• react native 自定义的公用导航栏Navigator


    export default class  Navigation extends Component {
         render () {
             // leftTitle和leftImage 优先判断leftTitle (即 文本按钮和图片按钮优先显示文本按钮)
                const {title,leftTitle,leftImage,leftAction,rightTitle,rightImage,rightAction} = this.props;
                return (
                    <View style={styles.barView}>
                      <View style={styles.showView}>
                          {
                              (()=>{
                                  if (leftTitle) {
                                      return <TouchableOpacity style={styles.leftNav} onPress={ ()=> {leftAction()}}>
                                            <View  style={{alignItems:'center'}}>
                                                <Text style={styles.barButton}>{leftTitle}</Text>
                                            </View>
                                         </TouchableOpacity>
                                 } else if (leftImage) {
                                      return <TouchableOpacity style={styles.leftNav} onPress={ ()=> {leftAction()}}>
                                                 <View style={{alignItems:'center'}}>
                                                     <Image source={leftImage}/>
                                                 </View>
                                              </TouchableOpacity>
                                  };
                              })()
                           }
    
    
                          {
                              (()=>{
                                  if (title) {
                                      return <Text style={styles.title}>{title || ''} </Text>
                                  }
                              })()
                          }
    
                          {
                              (()=>{
                                  if (rightTitle) {
                                      return <TouchableOpacity style={styles.rightNav} onPress={ ()=> {rightAction()}}>
                                          <View  style={{alignItems:'center'}}>
                                              <Text style={styles.barButton}>{rightTitle}</Text>
                                          </View>
                                      </TouchableOpacity>
                                  } else if (rightImage) {
                                      return <TouchableOpacity style={styles.rightNav} onPress={ ()=> {rightAction()}}>
                                          <View style={{alignItems:'center'}}>
                                              <Image style={styles.rightImg} source={rightImage}/>
                                          </View>
                                      </TouchableOpacity>
                                  }
                              })()
                          }
                      </View>
                    </View>
                )
         }
    }
    
    
    
    const styles =StyleSheet.create({
        barView:{
            height: Platform.OS === 'android' ? 44 : 64,
              Dimensions.get('window').width,
            backgroundColor:'#323136'
        },
    
        showView:{
            flex:1,
            marginLeft:px2dp(18),
            marginRight:px2dp(18),
            alignItems:'center',
            justifyContent: 'center',
            flexDirection: 'row',
            marginTop: Platform.OS === 'android' ? 0 :px2dp(20)
    
        },
    
        leftNav:{
            px2dp(20),
            height:px2dp(20)
        },
        rightNav:{
            position: 'absolute',
             top:px2dp(12),
             right:0,
             px2dp(18),
             height:px2dp(18),
            justifyContent:'center'
        },
    
        rightImg:{
            px2dp(18),
            height:px2dp(18),
            resizeMode:'stretch'
        },
    
        title:{
            fontSize:px2dp(16),
            color:'#fff',
        }
    });
  • 相关阅读:
    主键索引就是聚集索引吗?
    聚集索引以及非聚集索引
    IO阻塞模型、IO非阻塞模型、多路复用IO模型
    Log4j的使用说明
    前置机是什么
    转:图文理解区块链
    DQL、DML、DDL、DCL全名是啥?
    OLAP和OLTP的区别
    JAVA之运算符优先级
    JAVA之异常处理(一)
  • 原文地址:https://www.cnblogs.com/zk666/p/6840913.html
Copyright © 2020-2023  润新知