众所周知,React-Native原生的Webview的属性onShouldStartLoadWithRequest仅支持IOS平台,可是每每在开发中两端都须要进行URl的拦截,进行对应的业务须要。 react
使用方式以下: 1.添加依赖包git
yarn add react-native-webview-crossplatform react-native link react-native-webview-crossplatformgithub
2.在须要的业务页面导入web
import { WebView } from 'react-native-webview-crossplatform'
export default class webview extends Component<Props> {
constructor(props){
super(props);
}
render() {
return (
<View style={styles.container}>
<WebView
source={{ uri: 'https://infinite.red/react-native' }}
style={{ marginTop: 20 }}
onLoadProgress={e=>console.log(e.nativeEvent.progress)}
onShouldStartLoadWithRequest={(e)=> {
console.log('拦截', e)
return true
}}
renderError={()=> {
return <View>
<Text>我是错误页面</Text>
</View>
}}
/>
</View>
);
}
}
复制代码