【问题标题】:Webview not showing any content(html) react nativeWebview没有显示任何内容(html)反应原生
【发布时间】:2017-05-22 20:21:18
【问题描述】:

内容确实在模拟器中完美显示并使用真实设备进行调试,但在使用真实设备进行测试时没有显示任何内容(使用已发布的 .apk)。它只显示白色的空白容器。还是我错过了什么?

<WebView
     ref={(wView) => {this.wView = wView}}
     javaScriptEnabled={true}
     // onBridgeMessage={this.onBridgeMessage}
     onMessage={this.onMessage}
     injectedJavaScript="window.postMessage = String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage');"               
     automaticallyAdjustContentInsets={false}
     domStorageEnabled={true}
     startInLoadingState={true}
     source={mainHtml} <-- load with, var mainHtml = require('./MainHtml.html');
     style={{width: 320,height:100,flex: 1}}/>

环境

  • react-native-cli: 2.0.1

  • 反应原生:0.43.4

  • 反应:16.0.0-alpha.6

  • 设备(华硕 Zenfone)

  • Android 版本 6.0.1

【问题讨论】:

    标签: android webview react-native


    【解决方案1】:

    从我读到的here 来看,这是在 Release 中部署时 Android 的一个已知问题。解决方法是使用uri 指向文件:

    { uri: 'file:///pathto/file.html' }
    

    【讨论】:

    • 那么,是指从项目文件夹的根目录开始?
    • 谢谢,现在可以使用了.. 我所做的是,在android\app\src\main\assets 创建资产文件夹并将所有 HTML 文件放在那里,然后使用 source={{ uri: 'file:///android_asset/&lt;file-name&gt;.html' }} 引用它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-01
    • 2020-03-24
    • 2014-07-21
    • 2016-02-19
    相关资源
    最近更新 更多