将StackNavigator嵌套在组件中

时间:2017-09-20 08:57:55

标签: react-native react-navigation stack-navigator

我在我的应用程序开发中使用react-navigation(第一次......)。我的目的是将主要且唯一的StackNavigator嵌套在index.js中编写的组件中,因此我只能编写一次抽屉和状态栏代码,导航仅在可用空间中工作。我已尝试过本指南,但我不明白如何应用该段......

Home组件具有页面的特定内容。 我的索引代码感兴趣:

export default class BluetoothController extends React.Component {
  static navigationOptions = {
    title: 'Home',
    header: null,
  };

   render() {
       [...]
       return (
      <DrawerLayoutAndroid
        drawerWidth={300}
        keyboardDismissMode='on-drag'
        drawerPosition={DrawerLayoutAndroid.positions.Left}
        renderNavigationView={() => drawerView}
        ref={'DRAWER_REF'} // riferimento per recuperare tramite this.refs['DRAWER_REF'] la sidebar
      >
        {/*Il contenuto della view va ALL'INTERNO DEL DRAWER TAG*/}
        <View style={mainStyles.container}>
          <StatusBar
            backgroundColor="#1976D2"
            barStyle="light-content"
          />
          <ToolbarAndroid
            title='Bluetooth Controller'
            titleColor='white'
            style={mainStyles.toolbar}
            navIcon={require('./images/menu.png')}
            onIconClicked={() => {
              // apro la sidebar grazie al riferimento che mi sono creato
              this.refs['DRAWER_REF'].openDrawer();
            }}
            actions={[{ title: 'Info', icon: require('./images/info.png'), show: 'always' }]}
            onActionSelected={(position) => {
              Alert.alert("Instructions", "Welcome to React Native! To get started, edit index.android.js, double tap R on your keyboard to reload, shake or press menu button for dev menu");
            }}
          />
        </View>
        <RouterOutlet/>
      </DrawerLayoutAndroid>

    );
  }
}
// impostazione del routing
const RouterOutlet = StackNavigator({
  Home: { screen: Home },
  OneBtnMode: { screen: OneBtnMode },
});
BluetoothController.router = RouterOutlet.router;
AppRegistry.registerComponent('BluetoothController', () => RouterOutlet);

现在它只显示主页内容...

0 个答案:

没有答案