【问题标题】:React-native: Component not renderingReact-native:组件未呈现
【发布时间】:2017-11-11 20:12:19
【问题描述】:

我有一个地图组件,当我调用以下方法时会呈现:

render() {
    return (
      <MapComponents />
    )
  }

但是,我想从 &lt;View&gt; 中创建调用 &lt;MapComponents /&gt;,如下所示:

render() {
    return (
      <View>
      <MapComponents />
      </View>
    )
  }

此时,我得到一个空白屏幕。任何想法为什么会这样?

【问题讨论】:

    标签: reactjs react-native components react-native-maps


    【解决方案1】:

    您需要将flex: 1 添加到父级,以便它占用所有可用空间:

    render() {
      return (
        <View style={{ flex: 1 }}>
          <MapComponents />
        </View>
      )
    }
    

    【讨论】:

    • 非常感谢您的修复。你介意解释一下为什么需要这样做吗(我认为组件不需要依赖这个特殊的样式值才能被看到)?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-23
    • 2019-03-17
    • 2017-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多