Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native webview doesn't appear

For some reason, my react-native webview doesn't show up at all. Nothing shows up after my text field. Here's my code

import React, { Component } from 'react';


import {
View,
Text,
WebView,

} from 'react-native';


export default class Home extends Component {

    render() {
        return (
        <View style={{flexDirection:'column'}}>
          <Text>Show webview</Text>
          <WebView source={{html:"<html><body style='color:red'>Hello<br/>This is a test</body></html>"}} style={{width:200,height:200,backgroundColor:'blue',marginTop:20}} />
        </View>
        );
  }
}

What am I doing wrong?

like image 520
John Avatar asked Oct 29 '17 21:10

John


People also ask

Does react native support Webview?

React Native WebView is a modern, well-supported, and cross-platform WebView for React Native.

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.


1 Answers

Add flex: 1 to your <View /> component.

<View style={{flex: 1, flexDirection:'column'}}>
  <Text>Show webview</Text>
  <WebView source={{html:"<html><body style='color:red'>Hello<br/>This is a test</body></html>"}} style={{width:200,height:200,backgroundColor:'blue',marginTop:20}} />
</View>

Here's a demo

like image 95
Dan Avatar answered Oct 21 '22 17:10

Dan