React-Native在webview不可见时预加载uri
React-Native pre-load uri while webview not visible
我有一个webview在react如下。
<WebView
source={{ uri: this.state.url }}
style={ this.state.style }
javaScriptEnabled = { true }
startInLoadingState = {true}
onLoad = {this.showPage()}
onLoadEnd = {this.showPage()}
/>
当我设置this.state.url时,我希望webview立即加载url,然后在加载onLoad或onLoadEnd后调用showPage函数显示webview内容。我似乎不能得到这个工作- webview只加载url时,它是可见的dom。有办法做到这一点吗?
最简单的解决方案是使用WebView的renderLoading属性。如果你需要自定义加载器逻辑,你可以这样做:
class WebScreen extends Component {
...
render() {
const { isLoading } = this.state;
return (
<View style={styles.container}>
<ReactWebView
style={styles.webview}
source={{ uri: url }}
onLoadStart={::this.onLoadStart}
onLoadEnd={::this.onLoadEnd}
/>
{isLoading && (
<WebViewLoader style={styles.loader} />
)}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
loader: {
position: 'absolute',
top: 0,
right: 0,
bottom: 0,
left: 0,
zIndex: 4,
backgroundColor: 'white'
}
});
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- 如何在生成下载文件时显示加载动画
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- 无法在通过jQuery的ajax加载的页面中执行javascript
- Emberjs应用程序加载在除Index之外的所有路由上
- 在chrome.tabs.onCreated之后加载HTML页面
- 当加载带有hastags的动态内容-URI时,Jquery-悬停效果不起作用
- 谷歌地图 KML 加载 - 414 请求 URI 太大
- 使用AngularJS加载动态指令-错误:访问受限URI被拒绝
- 是否可以加载图像,在内存中缩放它并将其分配为背景图像的 uri
- 表单提交后,用JS或PHP重新加载当前页面/URI
- 如何用数据URI延迟图像加载
- 如何使用Cordova从URI加载Android上的图像
- 在不重新加载页面的情况下更改浏览器URI
- React-Native在webview不可见时预加载uri
- 如何从URI加载.jpg到画布
- 如何从引用本地文件的res: uri加载脚本
- Firefox加载URI不工作
- 作为数据URI加载的SVG没有渲染
标签 - 使用javascript更改uri而不重新加载页面