代码之家  ›  专栏  ›  技术社区  ›  heltdev

React本机iOS WebView未正确加载

  •  0
  • heltdev  · 技术社区  · 6 年前

    我试图在WebView中运行本地HTML文件,但它不加载全部内容。
    我用相同的HTML文件在本机应用程序上测试了它,它显示得很好。

    我不知道有什么问题。

    本机代码

    @IBOutlet weak var mapView: WKWebView!
        override func viewDidLoad() {
            super.viewDidLoad()
            mapView.uiDelegate = self;
            mapView.navigationDelegate = self;
            let url = Bundle.main.url(forResource: "index", withExtension: "html")!
            mapView.loadFileURL(url, allowingReadAccessTo: url)
            let request = URLRequest(url: url)
            mapView.load(request)
        }
    

    响应本机代码

    <WebView
              originWhitelist={['*']}
              onLoad={this.onLoad}
              source={Platform.OS === 'android' ? { uri: 'file:///android_asset/index.html' } : require('../ios/web/index.html')}
              dataDetectorTypes={'none'}
              ref='webview'
              onMessage={e => this.onMessage(JSON.parse(e.nativeEvent.data))}
              onShouldStartLoadWithRequest={this.onShouldStartLoadWithRequest}
              onNavigationStateChange={this.onShouldStartLoadWithRequest}
              injectedJavaScript={patchPostMessageJsCode}
              useWebKit={true}
              />
    

    反应本地屏幕截图

    enter image description here

    本地屏幕截图

    enter image description here

    请帮帮我。

    0 回复  |  直到 6 年前
        1
  •  0
  •   displayname    6 年前

    尝试调整WebView的大小,

    import{Dimensions, SafeAreaView, WebView} from 'react-native';
    
    <SafeAreaView style={{flex:1}}>
    
         <WebView
              originWhitelist={['*']}
              onLoad={this.onLoad}
              source={Platform.OS === 'android' ? { uri: 'file:///android_asset/index.html' } : require('../ios/web/index.html')}
              dataDetectorTypes={'none'}
              ref='webview'
              onMessage={e => this.onMessage(JSON.parse(e.nativeEvent.data))}
              onShouldStartLoadWithRequest={this.onShouldStartLoadWithRequest}
              onNavigationStateChange={this.onShouldStartLoadWithRequest}
              injectedJavaScript={patchPostMessageJsCode}
              useWebKit={true}
              style={{ height: Dimensions.get('window').width.height, width:Dimensions.get('window') , resizeMode: 'cover', flex: 1 }}
              />
    
    </SafeAreaView>
    
    推荐文章