首页 > 解决方案 > React Native 导入 React Navigation

问题描述

我遵循安装适用于 Android 的 React Navigation 的所有说明。

首先,“npm install --save react-navigation”、“npm install --save react-native-gesture-handler”。“react-native link react-native-gesture-handler”,最后更新了我的MainActivity.java

这是我的MainActivity.java

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 {

/**
 * Returns the name of the main component registered from JavaScript.
 * This is used to schedule rendering of the component.
 */
@Override
protected String getMainComponentName() {
    return "InstagramClone";
}

@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
  @Override
  protected ReactRootView createRootView() {
   return new RNGestureHandlerEnabledRootView(MainActivity.this)
  }
};
}
}

这是我得到的错误:

  • 出了什么问题:创建目录 'D:\React Native Projects\InstagramClone\node_modules\react- 时无法创建父目录 'D:\React Native Projects\InstagramClone\node_modules\react-native-gesture-handler\android\build'本机手势处理程序\android\build\intermediates\check-manifest\debug'

标签: react-nativereact-native-androidreact-navigation

解决方案


如果您使用expoinstall启动了您的项目react-native-gesture-handler。但是,如果您的计划由您开始,react-native cli您必须先安装react-native-gesture-handler,然后通过以下命令将其链接到所有包:

react-native link

推荐阅读