【问题标题】:React-Native 'Cannot add a child that doesn't have a YogaNode to a parent without a measure function!'React-Native '不能将没有 YogaNode 的孩子添加到没有测量功能的父母!
【发布时间】:2018-07-11 22:13:03
【问题描述】:

App.js 呈现一个可重用的外部组件 Fade 及其子组件。 Fade 中的动画在其渲染函数中使用{this.state.visible ? children : null} 确认子节点时执行。经过调试,我认为错误是由三元运算符引起的,由于它在Fade的渲染函数中定义的方式。

我的问题是我不知道如何正确地将这个三元运算符包装在渲染中。我试过<Text><View> 没有成功。有谁知道如何解决这个问题?

提前谢谢你。

App.js 渲染

<Container>
  <Fade visible={display.bus}> {renderIf(display.bus, <BusTemplate />)} </ Fade>
</Container>

Fade.js 渲染

<Animated.View style={this.state.visible ? combinedStyle : containerStyle}>
  {this.state.visible ? children : null}
</Animated.View>

Bus.js 渲染

<Container>
  <Image source={require("./scenerios/Bus.png")} style={styles.MainContainer}>
  </Image>
</Container>

【问题讨论】:

    标签: javascript react-native components


    【解决方案1】:

    乔迭戈, 一旦我读到这个问题与if 检查undefined 变量有关。 this.state.visible 可能是您的情况。
    另一个机会是将您的组件包装在 View 标记中。
    这是与 if 检查相关的问题:
    https://github.com/facebook/react-native/issues/13653
    如果您已经解决了,请告诉我们如何解决

    【讨论】:

    • 感谢您的回复。我需要检查一下,然后告诉你结果。
    猜你喜欢
    • 2018-12-02
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-18
    • 1970-01-01
    相关资源
    最近更新 更多