cabinetLockMode:'locked-closed'不能直接与createStackNavigator一起使用

时间:2018-09-17 05:46:00

标签: android ios react-native react-navigation

当我与drawerLockMode直接指定createStackNavigator时,它不起作用。

const drawerStack = createStackNavigator({
  HomeScreen: { screen: HomeScreen },
}, {
  headerMode: 'screen',
  navigationOptions: {
    drawerLockMode:'locked-closed'
  }
})

但是当我使用drawerStack变量定义navigationOptions时,它就起作用了。

drawerStack.navigationOptions = ({ navigation }) => {
    drawerLockMode = 'locked-closed';
    return {
       drawerLockMode,
    };
};

createStackNavigator中直接使用它时,我会犯任何错误吗?

更新

正如@bennygenel所建议的,我们需要在抽屉导航器中而不是stackNavigator中使用抽屉锁模式。这是我所做的。

const drawerNavigator = createDrawerNavigator({
    drawerStack: drawerStack
}, {
    contentComponent: DrawerComponent,
    navigationOpions:{
       drawerLockMode:'locked-closed'
    }
})

但是它也不以这种方式工作。它唯一有效的方法是使用constcreateStackNavigator

创建的createDrawerNavigator变量

2 个答案:

答案 0 :(得分:0)

尝试以下代码,它对我有用:

   const UserHome_StackNavigator = StackNavigator({
      userHm: {
        screen: UserHome,
        navigationOptions: ({ navigation }) => ({
          title: 'User screen title',
          headerStyle: {
            backgroundColor: 'white',
          },
          headerTintColor: 'black'
        }),
     },
    });

    UserHome_StackNavigator.navigationOptions = ({ navigation }) => {
      let drawerLockMode = 'locked-closed';
      //logic here to change conditionaly, if needed
      return {
        drawerLockMode,
     };
   };

答案 1 :(得分:0)

万一有人需要这个:

const drawerNavigator = createDrawerNavigator({
    drawerStack: drawerStack
}, {
    contentComponent: DrawerComponent,
    navigationOpions: ({navigation}) => {

      let routeName = navigation.state.routes[navigation.state.routes.length-1].routeName;

      if(['Animation', 'Splash', 'Intro', 'Login', 'Signup'].indexOf(routeName)>=0){
        return {
          drawerLockMode: 'locked-closed'
        }
      }

      return {}
    }
})