一、安装依赖
yarn add react-navigation react-navigation-stack
yarn add react-native-reanimated react-native-gesture-handler react-native-screens
1-1 请在android/app/build.gradle 中 dependencies 选项中添加下面这两行:
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
1-2 请在 android/app/src/main/java/com/MainActivity.java 中做如下修改:
将+号后面的添加到对应位置
package com.reactnavigation.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);
+ }
+ };
+ }
}
1-3 index.js
import 'react-native-gesture-handler'