2016-08-11 57 views
2

我有一个WebView,它使用本地文件require来显示网页内容。如何在ReactNative Android的发布包中包含静态html?

<WebView 
    source={ require('./inline_web_view/inline_web_view.html') } 
    injectedJavaScript={ scripts } 
    scrollEnabled={ this.props.scrollEnabled || false } 
    scalesPageToFit={ false } 
    style={{ 
     width: this.state.width, 
     height: this.state.height, 
    }} 
    onNavigationStateChange={ (navState)=> this.onNavigationStateChange(navState) } 
    /> 

这工作完全在开发模式iOS和Android,但它好像不被包含在Android版本捆绑的HTML文件。

我该如何将它添加到包中?

回答

0

这是React Native中的已知问题。

快速解决方法是以不同的方式在iOS和Android中加载内容。 iOS将按照您所描述的方式工作,但对于Android版本,您需要将静态文件复制到您的本机应用资产文件夹(即android/app/src/main/assets)中,并使用{ uri: 'file:///android_assets/-your-path-' }源加载内容。

查看this post了解完整的详细信息和完整的示例。