admin管理员组文章数量:1389903
I'm using a bottomTabNavigator with lazy
set to false
. For the screen I render a react-native-webview. The render function is being called because I can see the console.log but the actual webview does not start loading till the tab bees active. The tab I start on starts loading immediately.
Tab
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 bees active (clicking on it) }
source={{uri:'linkgoes.here'}} />)
}
Navigator
const TabNavigator = createBottomTabNavigator(
{
TabOne: {
screen: Tab
},
TabTwo: {
screen: Tab
}
},
{
initialRouteName: 'TabOne',
lazy: false,
}
)
This happened after upgrading react-navigation
from 1.x to 3.x and upgrading react-native
and react-native-webview
. I want the webview to start loading immediately, not just when visible.
I'm using a bottomTabNavigator with lazy
set to false
. For the screen I render a react-native-webview. The render function is being called because I can see the console.log but the actual webview does not start loading till the tab bees active. The tab I start on starts loading immediately.
Tab
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 bees active (clicking on it) }
source={{uri:'linkgoes.here'}} />)
}
Navigator
const TabNavigator = createBottomTabNavigator(
{
TabOne: {
screen: Tab
},
TabTwo: {
screen: Tab
}
},
{
initialRouteName: 'TabOne',
lazy: false,
}
)
This happened after upgrading react-navigation
from 1.x to 3.x and upgrading react-native
and react-native-webview
. I want the webview to start loading immediately, not just when visible.
1 Answer
Reset to default 9Having the same issue, I looked a bit more into this:
The problem does not appear on Android, so it es from the iOS implementation
Looking at the native code of react-native-webview
, it appears that the webview is being loaded in the didMoveToWindow
method, with a check on the window
property being non nil, which results in a webview loaded only when displayed.
I don't think this could be resolved using react-native, so I proposed a PR in the react-native-webview
package solving this particular issue: https://github./react-native-munity/react-native-webview/pull/813
To use it before it's merged, use in your package.json
:
"react-native-webview": "https://github./philippeauriach/react-native-webview#8b7015037d9c1329e4e65e1978e98c4897a928e6",
Don't forget to run cd ios && pod install
, it is sometimes needed.
本文标签:
版权声明:本文标题:javascript - react-native-webview ONLY starts loading when on active tab in react-navigation tabNavigator - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744634879a2616766.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论