react-native webview不会出现

Joh*_*ohn 4 webview react-native

出于某种原因,我的反应本机webview根本没有出现.我的文本字段后没有显示任何内容.这是我的代码

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>
        );
  }
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Dan*_*Dan 9

添加flex: 1到您的<View />组件.

<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>
Run Code Online (Sandbox Code Playgroud)

这是一个演示