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.

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.

本文标签: