gpt4 book ai didi

React-Native View 以显式设置的宽度/高度呈现,但 flexBasis 为 0

转载 作者:行者123 更新时间:2023-11-28 04:43:09 25 4
gpt4 key购买 nike

在 React-native 0.39 中,

我经常遇到这个错误,但我真的不明白为什么(事实上我没有设置 flexGrow...)。

控制台报错

View was rendered with explicitly set width/height but with a 0 flexBasis. (This might be fixed by changing flex: to flexGrow:) View: <RCTShadowView: 0x6080005a02a0; viewName: RCTView; reactTag: 2608; frame: {{0, 0}, {nan, nan}}>

有人可以向我解释为什么会触发此错误吗?

编辑:错误来 self 在主视图中添加的这段样板代码:

flex: 1,
// remove width and height to override fixed static size
width: null,
height: null,

但是如果有人可以阐明 react-native 样式或引导我找到好的资源,我将不胜感激 :)

最佳答案

引用react-native/React/Views/RCTShadowView.m , 有评论

    This works around a breaking change in css-layout where setting flexBasis needs to 
be set explicitly, instead of relying on flex to propagate.

We check for it by seeing if a width/height is provided along with a flexBasis
of 0 and the width/height is laid out as 0.

flex 没有定义 flexBasis 并且宽度和高度为零时会触发错误

引用react-native/Libraries/StyleSheet/LayoutPropTypes.js ,我们知道 flexGrow、flexShrink 和 flexBasis 接收的值为 number。

对于视觉指南,您可以引用此网页,A Visual Guide to CSS3 Flexbox Properties .

关于React-Native View 以显式设置的宽度/高度呈现,但 flexBasis 为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41098835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com