react-native-vector-icons/Ionicons 自定义tabbar ---2

import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TouchableOpacity,
PixelRatio,
Image,
} from 'react-native';

import Icon from 'react-native-vector-icons/Ionicons';
export default class HKTabBar extends Component {
static propTypes = {
goToPage: React.PropTypes.func, //跳转到Tab的方法
activeTab: React.PropTypes.number,//选中的下标
tabs: React.PropTypes.array,//tabs的集合!像OC items的数组

     //接下来!我们扩展自定义的属性
     tabNames:React.PropTypes.array,//文字的名字
     tabIconNames:React.PropTypes.array,//Item图片的名称
     tabIconNamesClick:React.PropTypes.array,//这里是被点击的图片
 };
render(){
  return(
      <View style={styles.tabsStyle}>
          {this.props.tabs.map((tab,i)=>this.renderItem(tab,i))}
      </View>

  );
}
renderItem(tab,i){
  const color =this.props.activeTab == i?"#B22222":"black";
  var name = color == "#B22222"?this.props.tabIconNamesClick[i]:this.props.tabIconNames[i];
  return(
    <TouchableOpacity style={styles.tabItem}
      onPress={()=>this.props.goToPage(i)}
       key={i}>
        <View style={styles.tabItemView}>
            {/* <Icon
                  name={this.props.tabIconNames[i]}
                   size={30}
                   color={color}
              >

            </Icon> */}

            <Image source={{uri:name}}
              style={[{width:20,height:20},{margin:5}]}
              >

              </Image>
            <Text style={{color:color}}>
                {this.props.tabNames[i]}
            </Text>
        </View>
    </TouchableOpacity>
  )
}

}

const styles=StyleSheet.create({
tabsStyle:{

    height:50,
    flexDirection:'row',
    borderTopWidth:1,
    borderColor:'gray',

},
tabItem:{
  flex:1
},
tabItemView:{
  alignItems:'center',

}

});

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容