您可以使用react-native-router-flux 或其他任何东西,并根据您的风格切换大小写,例如底部:
第一个import { Router, Scene ,Drawer} from 'react-native-router-flux';
在您的默认导出应用组件中:
export default class App extends React.Component{
render() {
return (
<Router>
<Scene key="root" hideNavBar>
<Scene key="splash" component={Splash} initial/>
<Scene key="main" tabs={true} swipeEnabled={false} tabBarPosition={'bottom'}
tabBarStyle={styles.tabBar} showLabel={false} default="home">
<Scene
key="home"
title="Home"
icon={TabIcon}
hideNavBar={true}
initial
component={Home}/>
<Scene
key="categories"
title="Categories"
icon={TabIcon}
hideNavBar={true}
component={Categories}/>
<Scene
key="search"
title="Search"
icon={TabIcon}
hideNavBar={true}
component={Search}/>
<Scene
key="profile"
title="Profile"
icon={TabIcon}
hideNavBar={true}
component={Profile}/>
</Scene>
</Scene>
</Router>
)
}
}
然后创建你的TabIcon 函数:
const TabIcon = ({ focused, title }) => {
switch (title) {
case "Home":
color = focused ? 'black' : 'grey';
return (
<View style={styles.tabView}>
<Icon name="ios-home" size={30} color={color} />
<Text style={styles.tabLabel}>Home</Text>
</View>
);
case "Categories":
color = focused ? 'black' : 'grey';
return (
<View style={styles.tabView}>
<Icon name="ios-list" size={30} color={color} />
<Text style={styles.tabLabel}>Categories</Text>
</View>
);
case "Search":
color = focused ? 'black' : 'grey';
return (
<View style={styles.tabView}>
<Icon name="ios-search" size={30} color={color} />
<Text style={styles.tabLabel}>Search</Text>
</View>
);
case "Profile":
color = focused ? 'black' : 'grey';
return (
<View style={styles.tabView}>
<Icon name="md-person" size={30} color={color} />
<Text style={styles.tabLabel}>Profile</Text>
</View>
);
}
};
最后你可以通过创建 styleSheet 来使用自己的样式:
const styles = StyleSheet.create({
container: {
flex: 1,
},
tabBar: {
backgroundColor: 'white',
},
navigationBarStyle: {
backgroundColor: 'red',
},
navigationBarTitleStyle: {
color: 'white',
},
icon: {
width: 18,
height: 22,
padding: 5
},
tabView: {
alignItems: 'center'
},
tabLabel: {
fontSize: 12,
textAlign: 'center'
},
});