ReactNativeUtil icon indicating copy to clipboard operation
ReactNativeUtil copied to clipboard

webview 添加header

Open wuyunqiang opened this issue 7 years ago • 0 comments

 react: ^16.3.0-alpha.1 => 16.3.1
  react-native: ^0.55.4 => 0.55.4
  constructor(props){
    super(props);
      this.header = { //header中不能有"_"
          'xxxxx':'testing', //right
          'xxx-xxx':'native', //right
          'xxx_xxx':'native', //fail
      };
      this.webviewParams = {};
  }
    <WebView
              nativeConfig={
                  {
                      props: {
                          backgroundColor: '#ffffff',
                          flex: 1,
                          justifyContent:'center',
                          alignItems: 'center',
                      }
                  }
              }
              userAgent='MyApp'
              ref = {(webview)=>{this.web = webview}}
              style={{width:'100%',height:'100%',justifyContent:'center', alignItems: 'center'}}
              source={{uri:this.state.destinationUrl,headers:this.header}}
              onLoadStart={this.onLoadStart}
              // domStorageEnabled={true}
              // mixedContentMode={'always'}//指定混合内容模式。即WebView是否应该允许安全链接(https)页面中加载非安全链接(http)的内容,never,always,compatibility
              // onLoadEnd = {this.LoadEnd}//加载成功或者失败都会回调
              onError = {this.isConnNet}
              // scalesPageToFit = {true}
              // javaScriptEnabled = {true}//指定WebView中是否启用JavaScript
              onNavigationStateChange={(e) => {
                  this.onNavigationStateChange(e)//可以获取标题 url 等信息
              }} 
              startInLoadingState={true} //强制WebView在第一次加载时先显示loading视图
              // bounces={true}//指定滑动到边缘后是否有回弹效果。
              // scrollEnabled={true}//是否启用滚动
              renderLoading={this.renderLoad}//返回一个加载指示器
              renderError={(e) => {
                  return <View/>;
              }}
          />

header中是以key:value的形式存在的并且,key中不能有"_"。

wuyunqiang avatar May 23 '18 10:05 wuyunqiang