更新时间:2023-01-10 10:08:12
我找到了解决方案. React Navigation取决于react-native-gesture-handler
库.在React Navigation文档的Installation部分中,它仅表示使用命令react-native link
创建链接.这对于iOS就足够了.但是对于Android,您必须编辑MainActivity.java
文件,以便手势处理程序库可以按预期工作:
I have found the solution. React Navigation depends on the react-native-gesture-handler
library. In the Installation section of React Navigation docs, it only says to create link by using the command react-native link
. This is enough for iOS. But for Android, you have to edit the MainActivity.java
file, so that the gesture handler library can work as expected:
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);
+ }
+ };
+ }
}
请参阅文档: https://kmagiera .github.io/react-native-gesture-handler/docs/getting-started.html
实际上,React Navigation文档中没有任何地方可以修改任何文件,因为它特定于react-native-gesture-handler
而不是React Navigation
.我将答案保留在这里,以便对他人有所帮助.
Actually, it's nowhere stated in React Navigation documentation to modify any files, as it is specific to react-native-gesture-handler
and not React Navigation
. I am keeping the answer here so it may help others.
更新:React Navigation的最新文档解决了该问题
UPDATE: The latest docs of React Navigation addresses this issue