错误:NativeViewGestureHandler 必须用作 GestureHandlerRootView 的后代

ins*_*der 17 reactjs react-native expo

我已经安装了GestureHandler ( npx expo install react-native-gesture-handler) 并使用 polyfills 将其导入到我的App.tsx文件的第 3 行中

import 'react-native-gesture-handler';

是按照世博文档执行的,由于某种原因,即使在运行(清除缓存)之后它似乎仍然无法工作,npx expo start --clear它会给我这个错误:

Error: NativeViewGestureHandler must be used as a descendant of GestureHandlerRootView.
Otherwise the gestures will not be recognized.
See https://docs.swmansion.com/react-native-gesture-handler/docs/installation for more details.
Run Code Online (Sandbox Code Playgroud)

ins*_*der 54

好吧,结果我很愚蠢,我TouchableOpacityreact-native-gesture-handler而不是react-native导入 ,抱歉,但也许可能会帮助某人,所以只是在这里发布解决方案:)快乐编码


Jef*_*zik 14

看起来这是背后团队最近做出的改变react-native-gesture-handler。最近打开了一个 GitHub 问题,并已通过此评论解决:https://github.com/gorhom/react-native-bottom-sheet/issues/1373#issuecomment-1550661599

“我通过在项目根目录添加 GestureHandlerRootView 包装器(例如 App.tsx)来修复此问题。您可以在此处找到说明https://docs.swmansion.com/react-native-gesture-handler/docs/installation/# js"

所以你的代码看起来像这样:

<GestureHandlerRootView>
// your code
</GestureHandlerRootView>
Run Code Online (Sandbox Code Playgroud)

  • 我需要定义为 `&lt;GestureHandlerRootView style={{ flex: 1 }}&gt;`,否则我的屏幕会变成空白。 (3认同)

归档时间:

查看次数:

15382 次

最近记录:

2 年,1 月 前