React Native 如何禁用滑动以打开抽屉导航器,但保持滑动以向后导航?

bwleehnv  于 2022-12-14  发布在  React
关注(0)|答案(2)|浏览(197)

我在这种情况下,我有一个屏幕在抽屉导航器中,我希望能够向右滑动导航回上一个屏幕。但由于它是在抽屉导航器中,我的右滑动打开抽屉,我无法导航回来,除非按下返回箭头。有没有办法禁用抽屉滑动该屏幕,但保持滑动导航。任何帮助,感谢。TYIA

ff29svar

ff29svar1#

您需要在screenOptions中使用swipeEnabled属性禁用滑动才能打开/关闭抽屉,例如:

<Drawer.Navigator
  screenOptions={{
    // ... defined something
    swipeEnabled: false,
  }}>
  // ... your drawer
</Drawer.Navigator>

你需要在1个堆栈中定义一个抽屉项目,就像我的例子一样:https://snack.expo.dev/@pqv2210/q-74710170

dtcbnfnu

dtcbnfnu2#

// Solution 1 
**React Navigation 6**

In screen options: Set edge width to 0.

<Drawer.Navigator
        screenOptions={{
            swipeEdgeWidth: 0,
        }}
    >
        {/* screens */}
</Drawer.Navigator>

**React Navigation 5**

In your createDrawerNavigator config:

const drawerNavigator = createDrawerNavigator({
  Home: {
    screen: Home
  }
}, 
{
  edgeWidth: 0
})

//Solution 2 : This may also work.

You can use the drawerLockMode in the screen navigation options using the option locked-open

locked-open: the drawer will stay opened and not respond to gestures. The drawer may still be opened and closed programmatically

Other options can be viewed here

static navigationOptions = {
     drawerLockMode: 'locked-open',
}

相关问题