Yvo*_*lon 2 javascript react-native react-navigation react-native-webview
我使用的是bottomTabNavigator与lazy设置为false。对于屏幕,我渲染了react-native-webview。之所以调用render函数,是因为我可以看到console.log,但是直到选项卡被激活,实际的Webview才开始加载。我开始的选项卡立即开始加载。
标签
const Tab = () => {
console.log('render') // this is being called right away
return (<WebView
onLoadStart={() => console.log('on load start') // this is being called only when tab becomes active (clicking on it) }
source={{uri:'linkgoes.here'}} />)
}
Run Code Online (Sandbox Code Playgroud)
航海家
const TabNavigator = createBottomTabNavigator(
{
TabOne: {
screen: Tab
},
TabTwo: {
screen: Tab
}
},
{
initialRouteName: 'TabOne',
lazy: false,
}
)
Run Code Online (Sandbox Code Playgroud)
react-navigation从1.x 升级到3.x并升级react-native和react-native-webview。我希望webview立即开始加载,而不只是在可见时开始加载。
遇到相同的问题,我对此进行了更多研究:
该问题未在Android上出现,因此来自iOS实现
查看的原始代码react-native-webview,看来该didMoveToWindow方法中正在加载Web视图,并且对window属性的检查为non nil,这导致仅在显示时加载Web视图。
我认为这不能使用react-native来解决,因此我在react-native-webview软件包中提出了PR来解决此特定问题:https : //github.com/react-native-community/react-native-webview/pull/813
要在合并之前使用它,请在您的中使用package.json:
"react-native-webview": "https://github.com/philippeauriach/react-native-webview#8b7015037d9c1329e4e65e1978e98c4897a928e6",
Run Code Online (Sandbox Code Playgroud)
不要忘记运行cd ios && pod install,有时是需要的。