最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - react-native-webview ONLY starts loading when on active tab in react-navigation tabNavigator - Stack Overflow

programmeradmin6浏览0评论

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.

Share Improve this question asked Jul 7, 2019 at 14:58 Yvo CilonYvo Cilon 3804 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Having 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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论