首先 webview已经从 react-native 移到单独模块 react-native-webview;
使用:
- 安装 yarn add react-native-webview;
- 运行 react-native link react-native-webview(native0.6以后会自动link 不知道可不可以 )
如果报错:
> Invariant Violation: requireNativeComponent: "RNCWKWebView" was not found in the UIManager. >
- cd ios
- 运行 pod install
- 重新运行 react-native run-ios
在App.js代码里写入
import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { WebView } from 'react-native-webview';
// ...
export default class MyWebComponent extends Component {
render() {
return <WebView source={{ uri: 'https://www.baidu.com' }} />;
}
}