如何修复react-native-gesture-handler错误不起作用

时间:2019-07-05 10:24:08

标签: react-native

我在react-native中创建一个新项目,然后进行安装(npm install --save react-navigation,npm install --save,react-native-gesture-handler), 最新版本(react-native:0.60.0)自动连结,所以我没有连结,但仍然显示错误,  !https://prnt.sc/oaxxuc 任务:react-native-gesture-handler:compileDebugJavaWithJavac 失败

卸载手势处理程序后,此类错误显示 !https://prnt.sc/oaxx8i

请帮助解决此错误

The react-native latest version:-
  

系统:       作业系统:Linux 4.15 Ubuntu 16.04.5 LTS(Xenial Xerus)       反应:16.8.6 => 16.8.6       react-native:0.60.0 => 0.60.0 npmGlobalPackages:       react-native-cli:2.0.1

谢谢

6 个答案:

答案 0 :(得分:2)

您应该粘贴导入“ react-native-gesture-handler”;在index.js的顶部,这是开箱即用的标准本机。

您的应用程序条目。这是您导入App.js文件的文件,文件中清楚地写了该文件。

文档https://reactnavigation.org/docs/en/getting-started.html

答案 1 :(得分:0)

请尝试安装命令npm install --save react-native-gesture-handler

react-native link react-native-gesture-handler

之后

效果很好。

答案 2 :(得分:0)

此问题已发布在github上,您可以应用以下解决方案。 它将适用于RN 0.60.0。

https://github.com/kmagiera/react-native-gesture-handler/issues/642#issuecomment-509113481 

答案 3 :(得分:0)

从1.1.0-> 1.0.16降级,并使用确切的版本(-E):

npm i react-native-gesture-handler@1.0.16 -D -E

答案 4 :(得分:0)

如果您使用的是React Native> = 0.60,则需要先禁用react-native-gesture-handler的自动链接。要禁用自动链接,请在项目的根目录中创建一个具有以下内容的react-native.config.js文件:

module.exports = {
  dependencies: {
    'react-native-gesture-handler': {
      platforms: {
        android: null,
        ios: null,
      },
    },
  },
};

答案 5 :(得分:0)

首先,使用yarn安装库:

  

添加纱线react-native-gesture-handler

,或者如果愿意,可以使用 npm

  

npm install-保存react-native-gesture-handler

链接   react-native链接react-native-gesture-handler

Android

  

执行以下步骤:

如果您使用本机导航库之一(例如wix / react-native-navigation),则应按照此单独的指南在Android上设置手势处理程序库。忽略此步骤的其余部分-它仅适用于使用标准Android项目布局的RN应用。

Update your MainActivity.java file (or wherever you create an instance of ReactActivityDelegate), so that it overrides the method responsible for creating ReactRootView instance and then use the root view wrapper provided by this library. Do not forget to import ReactActivityDelegate, ReactRootView, and RNGestureHandlerEnabledRootView:

打包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);
+      }
+    };
+  }
}

iOS

除了下一步需要执行的操作外,iOS上不需要其他配置。

现在您已经准备就绪。使用 react-native run-android react-native run-ios

运行您的应用