我昨天使用react-native-cli构建了一个新的React Native项目。 但是,当用我的Android手机运行该项目时,我在红色屏幕上收到了此错误。
不变违规:WebView已从React Native中移除。现在可以从“ react-native-webview”而不是“ react-native”安装和导入它。参见“ https://github.com/react-native-community/react-native-webview”。
我从未使用过WebView,这是我的“ package.json”。
{
"name": "",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-image-slider": "^2.0.3",
"react-native-svg": "^9.13.6",
"react-navigation": "^4.0.10",
"react-navigation-drawer": "^2.3.3",
"react-navigation-stack": "^1.10.3",
"react-redux": "^7.1.3",
"redux": "^4.0.4"
},
"devDependencies": {
"@babel/core": "^7.7.5",
"@babel/runtime": "^7.7.6",
"@react-native-community/eslint-config": "^0.0.5",
"babel-jest": "^24.9.0",
"eslint": "^6.7.2",
"install-peers": "^1.0.3",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.57.0",
"react-native-gesture-handler": "^1.5.2",
"react-native-reanimated": "^1.4.0",
"react-test-renderer": "16.9.0"
},
"jest": {
"preset": "react-native"
}
}
我整天试图解决此问题,但无法解决。 我只是认为“ react-native-gesture-handler”会导致此问题。 任何有过React-Native经验的人,请帮助我。 谢谢。
答案 0 :(得分:0)
尝试
答案 1 :(得分:0)
我认为警告中已经明确提到了它:
WebView已从React Native中被删除。现在可以从“ react-native-webview ”而不是“ react-native”
进行安装和导入。
我想您现在在代码中使用以下某些地方
import {
WebView,
} from 'react-native';
现在,您应该改为执行以下操作
import { WebView } from 'react-native-webview';
要开始使用react-native-webivew,您可以按照getting started document here
答案 2 :(得分:0)
在您的根文件夹中运行以下命令: npm我 react-native-webview
请先查看此npm软件包
https://www.npmjs.com/package/react-native-webview
使用以下命令在Android和IOS设备中再次运行项目: react-native run-android或react-native run-ios
导入包: 从“ react-native-webview”导入{WebView};
将webview用作:
<WebView source={{ uri: 'https://facebook.github.io/react-native/' }} />
答案 3 :(得分:0)
基本上你的猜测是正确的,它受到react-native-gesture-handler
的影响。
这是依赖webview的文件。
https://github.com/software-mansion/react-native-gesture-handler/blob/1.0.10/GestureHandler.js
react-native-gesture-handler
升级到最新版本,该版本已经将 webview 从 react-native 替换为 react-native-webviewyarn install
并重建您的项目