你怎么禁用"向下滑动关闭" React Native中的Modal组件?

时间:2018-03-14 17:55:12

标签: react-native react-navigation

我正在使用核心React Native Modal component。在模态内容中,我有一个Done按钮。

Done是我们希望用户关闭模式的唯一方法。但Modal组件允许从屏幕顶部向下滑动以关闭。

如何关闭"滑动关闭"?

4 个答案:

答案 0 :(得分:6)

自从React Navigation版本5.x起,他们已将StackNavigator和{的更改为gestureEnabled而不是gesturesEnabled (没有s) {3}}

样品用量:

<Stack.Navigator mode="modal" screenOptions={{ gestureEnabled: false }}>
    <Stack.Screen name="HomeNav" component={HomeNavigator} />
</Stack.Navigator>

答案 1 :(得分:4)

要在评论中回答@Nikolai,我正在使用React Navigation。

我没有意识到导航器中的手势设置也控制了反应原生模态的手势。

关闭手势解决了我的问题。

SELECT cnt.id as content_id, cnt.title as content_title, cnt.featured, cnt.alias as content_alias, cnt.catid, cnt.images, cnt.state, cnt.introtext, cat.id as cat_id, cat.title as cat_title, cat.alias as cat_alias,
MAX(case when f.field_id = 4 then f.value end) as prijs,
MAX(case when f.field_id = 5 then f.value end) as prijsoud
FROM snm_fields_values f
JOIN snm_content cnt
ON cnt.id = f.item_id
JOIN snm_categories cat
ON cnt.catid = cat.id
WHERE cnt.catid = '17'
AND cnt.state = 1
GROUP BY f.item_id

答案 2 :(得分:1)

除了@ GollyJer的答案之外,如果你想禁用单个模态的滑动手势,你也可以这样做:

const AppNavigator = StackNavigator({
    ModalScreen: {
      screen: ModalScreen,
      navigationOptions: {
        gesturesEnabled: false
      },
    }
}

答案 3 :(得分:1)

也有点挣扎。这是对我有用的东西:

如果您将根导航器设置为模式导航器,并且在其中将要禁用其手势的另一个堆叠式导航器,则将其放置在该堆叠式导航器的根导航器中,在v2.12 iOS中为我工作了
navigationOptions: { gesturesEnabled: false, },

完整的代码:

const RootStack = createStackNavigator(
  {
    LoginNavigator: {
      screen: LoginNavigator,
      navigationOptions: {
        gesturesEnabled: false,
      },
    },
    ModerationNavigator: {
      screen: ModerationNavigator,
    },
    WalletNavigator: {
      screen: WalletNavigator,
    },
    FloatingNavigator: {
      screen: FloatingNavigator,
    },
    UIKitNavigator: {
      screen: UIKitNavigator,
    },
    MainMapViewScreen: {
      screen: MainMapViewScreen,
    },
    FullscreenPhotoScreen: {
      screen: FullscreenPhotoScreen,
    },
  },
  {
    mode: 'modal',
    initialRouteName: 'MainMapViewScreen',
    headerMode: 'none',
    header: null,
  },
);