react-native-webview-crossplatform支持iOS及Android拦截onShouldStartLoadWithRequest方法

众所周知,React-Native原生的Webview的属性onShouldStartLoadWithRequest仅支持IOS平台,但是往往在开发中两端都需要进行URl的拦截,进行对应的业务需要。
react-native-webview-crossplatform支持iOS及Android拦截onShouldStartLoadWithRequest方法_第1张图片
通过不断学习,在https://github.com/react-native-community/react-native-webview的基础上,整理出来一个方案,并且发布到了npm上,小伙伴们有需要的可以参考一下。https://github.com/wayne214/react-native-webview-crossplatform,欢迎star,fork.

使用方式如下:
1.添加依赖包

yarn add react-native-webview-crossplatform
react-native link react-native-webview-crossplatform

2.在需要的业务页面导入

import { WebView } from 'react-native-webview-crossplatform'
export default class webview extends Component {
    constructor(props){
        super(props);
    }


  render() {
    return (
      
          console.log(e.nativeEvent.progress)}
              onShouldStartLoadWithRequest={(e)=> {
                  console.log('拦截', e)
                  return true
              }}
              renderError={()=> {
                  return 
                      我是错误页面
                  
              }}
          />
      
    );
  }
}

你可能感兴趣的:(ReactNative,ReactNative)