-[RCTRootView cancelTouches]`已过时,将在React Native Map中被删除

Wat*_*wer 5 ios react-native

我正在使用react-native-map,它在ios和android上运行良好。

我的本机版本是0.61.2。但是在ios中,当我单击map时,显示警告“-[RCTRootView cancelTouches]`已过时,将很快被删除。”。

这是什么,以及如何删除此警告?

Muh*_*mir 17

看到这个提交现在在反应本地0.61+

尽管它说已弃用,但根据此拉取请求中的对话,它将被添加回react-native核心。

您可以将其关闭,直到反应团队删除警告为止:

console.ignoredYellowBox = ['Warning: `-[RCTRootView cancelTouches]`'];

或者您将本机降级到低于0.61的版本。

一些库,例如react-native-gesture-handler仍然调用cancelTouches方法。这就是为什么您看到此警告。

I was using react-native-gesture-handler which gave this warning on debug mode and caused crashes in release builds on both android and ios. Fixed the crashes by adding import 'react-native-gesture-handler' at the top level of index.js.

  • 我尝试在index.js和/或app.js中添加“ import“ react-native-gesture-handler”“,但是没有用。我还尝试使用YellowBox忽略组件级别,app.js级别和index.js级别的警告,警告仍在显示 (3认同)
  • 您能否指出[此拉取请求中的对话](https://github.com/kmagiera/react-native-gesture-handler/pull/657)的确切部分,人们可以假设它将被添加回反应本机核心? (2认同)

MrN*_*kel 6

Muhammed的答案基本上是正确的,但是为了阻止崩溃,您还需要将应用程序包装在React Native Gesture Handler HOC中,如下所示:

index.js

import 'react-native-gesture-handler'
import { gestureHandlerRootHOC } from 'react-native-gesture-handler';
Run Code Online (Sandbox Code Playgroud)

index.js

AppRegistry.registerComponent(appName, () => gestureHandlerRootHOC(App));
Run Code Online (Sandbox Code Playgroud)

注意您必须具有这些导入作为工作的第一个导入。

这对于React Native 61.2和react-native-gesture-handler 1.4.1都是正确的

注意:官方的React Native文档建议使用该YellowBox模块来忽略警告。例如:

import {YellowBox} from 'react-native';

YellowBox.ignoreWarnings(['`-[RCTRootView cancelTouches]`']);
Run Code Online (Sandbox Code Playgroud)