Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Webview not loading any url (React native web view not working)

Tags:

react-native

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

like image 454
Anurag Vijayvergia Avatar asked Feb 17 '16 08:02

Anurag Vijayvergia


People also ask

How do you refresh a WebView in react-native?

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.

Can we use WebView in react-native?

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!


2 Answers

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   } }); 
like image 187
Matthew Vincent Avatar answered Sep 21 '22 12:09

Matthew Vincent


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.

like image 44
Rafal Wiliński Avatar answered Sep 19 '22 12:09

Rafal Wiliński