react-native-webview 只有在 react-navigation tabNavigator 中的活动选项卡上时才开始加载
react-native-webview ONLY starts loading when on active tab in react-navigation tabNavigator
我正在使用 bottomTabNavigator with lazy
set to false
. For the screen I render a react-native-webview。正在调用渲染函数,因为我可以看到 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'}} />)
}
领航员
const TabNavigator = createBottomTabNavigator(
{
TabOne: {
screen: Tab
},
TabTwo: {
screen: Tab
}
},
{
initialRouteName: 'TabOne',
lazy: false,
}
)
这发生在将 react-navigation
从 1.x 升级到 3.x 以及升级 react-native
和 react-native-webview
之后。我希望 webview 立即开始加载,而不仅仅是在可见时。
有同样的问题,我仔细研究了一下:
问题没有出现在Android,所以它来自iOS实现
查看 react-native-webview
的本机代码,似乎正在 didMoveToWindow
方法中加载 webview,检查 window
属性非零,这导致仅在显示时才加载 webview。
我不认为这可以使用 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",
别忘了运行cd ios && pod install
,有时候是需要的。
我正在使用 bottomTabNavigator with lazy
set to false
. For the screen I render a react-native-webview。正在调用渲染函数,因为我可以看到 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'}} />)
}
领航员
const TabNavigator = createBottomTabNavigator(
{
TabOne: {
screen: Tab
},
TabTwo: {
screen: Tab
}
},
{
initialRouteName: 'TabOne',
lazy: false,
}
)
这发生在将 react-navigation
从 1.x 升级到 3.x 以及升级 react-native
和 react-native-webview
之后。我希望 webview 立即开始加载,而不仅仅是在可见时。
有同样的问题,我仔细研究了一下:
问题没有出现在Android,所以它来自iOS实现
查看 react-native-webview
的本机代码,似乎正在 didMoveToWindow
方法中加载 webview,检查 window
属性非零,这导致仅在显示时才加载 webview。
我不认为这可以使用 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",
别忘了运行cd ios && pod install
,有时候是需要的。