1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| import React, {Component} from 'react'; import {Platform, StyleSheet, Text, View, Image} from 'react-native'; import {StackNavigator, TabNavigator, TabBarBottom} from 'react-navigation'; // 全局注册并注入mobx,其他地方都可以使用store import {Provider} from 'mobx-react'; // 获取store实例 import store from './src/Mobx/Store';
import One from './src/One/One'; import Two from './src/Two/Two';
export default class TwoDetails extends Component<Props> { render () { return ( <Provider rootStore={store}>
<Navigator onNavigationStateChange={(prevState, currentState) => { // 只要切换tab,push,pop,这里一定走 console.log (prevState); console.log (currentState); }} /> </Provider> ); }
componentDidMount = () => { console.disableYellowBox = true; //去除黄色弹框警告 }; }
const Tab = TabNavigator ( { One: { screen: One, navigationOptions: ({navigation}) => ({ tabBarLabel: '男孩', tabBarIcon: ({focused, tintColor}) => ( <Image source={ focused ? require ('./src/Image/boy_active.png') : require ('./src/Image/boy.png') } style={{width: 25, height: 25}} /> ), }), }, Two: { screen: Two, navigationOptions: ({navigation}) => ({ tabBarLabel: '女孩', tabBarIcon: ({focused, tintColor}) => ( <Image source={ focused ? require ('./src/Image/girl_active.png') : require ('./src/Image/girl.png') } style={{width: 25, height: 25}} /> ), }), }, }, { tabBarComponent: TabBarBottom, tabBarPosition: 'bottom', swipeEnabled: true, animationEnabled: true, lazy: true, tabBarOptions: { activeTintColor: '#979797', inactiveTintColor: '#979797', style: {backgroundColor: '#ffffff'}, }, } );
const Navigator = StackNavigator ({ Tab: { screen: Tab, }, });
const styles = StyleSheet.create ({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, }, });
|