I am trying to implement react native webview component in my application, but the web view is not loading any url its just showing the white page.
var React = require('react-native'); var{ View, Text, StyleSheet, WebView } = React; module.exports = React.createClass({ render: function(){ return( <View style={styles.container}> <WebView source={{uri: 'https://m.facebook.com'}} style= {styles.webView}/> </View> ); } }); var styles = StyleSheet.create({ container: { flex:1, backgroundColor: '#ff00ff' },webView :{ height: 320, width : 200 } });
Below is the screenshot of the output .
The solution to How To Reload Webview In React Native will be demonstrated using examples in this article. You can set a key to the webview key={this. state. key} and then you can reload it by updating the state this.
WebViews offer developers opportunities to render any web components in a React Native application. A web component can be anything from a whole webpage/application or just a simple HTML file. The package react-native-webview makes it super simple to embed WebViews into your React Native apps!
I had this issue. WebView would render when it was the only component returned, but not when nested in another View component.
For reasons I'm not entirely sure of the issue was resolved by setting a width property on the WebView component.
class App extends React.Component { render() { return ( <View style={styles.container}> <WebView source={{uri: 'https://www.youtube.com/embed/MhkGQAoc7bc'}} style={styles.video} /> <WebView source={{uri: 'https://www.youtube.com/embed/PGUMRVowdv8'}} style={styles.video} /> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'space-between', }, video: { marginTop: 20, maxHeight: 200, width: 320, flex: 1 } });
I'm facing same issue. What I observed is that WebView
doesn't work if it's nested. If component returns just WebView, then everything is fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With