react-native - 如何禁用滑动打开但不关闭反应原生?
问题描述
我想禁用滑动以打开抽屉导航但不关闭?
我找到了 android 的解决方案,但没有找到 react-native 的解决方案。目前我正在使用这个:
drawerLockMode: 'locked-open'
哪个有效,但我无法通过滑动关闭它。
我用这样的汉堡菜单图标打开抽屉:
onPress={() => props.navigation.toggleDrawer()}
这里有人已经这样做了吗?有没有办法drawerLockMode
全局设置?onDrawerOpened
和onDrawerClosed
道具存在吗?谢谢!
解决方案
你需要一个react-native-gesture-handler
模块来swipe
.
你可以跑
yarn add react-native-gesture-handler
OR
npm install --save react-native-gesture-handler
和react-native link react-native-gesture-handler
更新您的MainActivity.java
文件(或您创建 的实例的任何位置ReactActivityDelegate
),以便它覆盖负责创建ReactRootView
实例的方法,然后使用此库提供的根视图包装器。不要忘记导入ReactActivityDelegate
、ReactRootView
和RNGestureHandlerEnabledRootView
:
package com.swmansion.gesturehandler.react.example;
import com.facebook.react.ReactActivity;
+ import com.facebook.react.ReactActivityDelegate;
+ import com.facebook.react.ReactRootView;
+ import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
public class MainActivity extends ReactActivity {
@Override
protected String getMainComponentName() {
return "Example";
}
+ @Override
+ protected ReactActivityDelegate createReactActivityDelegate() {
+ return new ReactActivityDelegate(this, getMainComponentName()) {
+ @Override
+ protected ReactRootView createRootView() {
+ return new RNGestureHandlerEnabledRootView(MainActivity.this);
+ }
+ };
+ }
}
有关详细信息,请参阅
推荐阅读
- bash - Bash 脚本 - 计算时间表的函数
- python - return pickle.load(f) 导致 _pickle.UnpicklingError: could not find MARK while
- python-3.x - Seaborn,如何根据 x 轴值渐变颜色分布图
- list - 如何将列表附加到 OCaml 中的列表
- javascript - vue 的 Monaco 编辑器生成大量 .js 文件
- node.js - 安装 Node JS 后安装 npm 时出错
- apache-kafka - 如何将具有特定字段的kafka消息聚合到单个消息并将其发送到新主题
- tensorflow - 'var_list' 缺少必需的位置参数
- django - ValueError:在 Django Window 函数中解包的值太多(预期为 2)
- javascript - 如何从Javascript中的音频元素获取音频样本?