用明确设置宽度/高度,但使用0 flexbasis呈现反应原始视图



在reation-native 0.39,

我经常会遇到这个错误,但我并不真正理解原因(Appart我没有设置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}}>

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

edit :错误来自我在主视图上添加的这一点的样板代码:

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

但是,如果有人可以阐明反应的样式或带我获得良好的资源,我将感激:)

请参阅react-native/react/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接收数字的值。

对于视觉指南,您可以参考此网页,CSS3 Flexbox属性的视觉指南。

指定flexDirection: 'row'解决问题¯_(ツ)_/¯

作为错误状态 - 将'flex'更改为'flexgrow'并解决了问题。

很难的部分是如何找到" flex''需要从整个项目中更改'flex'的方法。我所做的是(使用原子编辑器,所以"在项目中找到" ...)更改每个'flex:'with flexgrow:'只需再次搜索整个项目的" flexgrow",然后用" flex"更改每个文件,直到找到损坏的" flex"。

我更喜欢使用Flex而不是Flexgrow,这就是为什么我还原flex的原因。这就是原因:布局道具

希望这能解决问题。

in node_modules/react-native/react/react/views/rctshadowview.m添加"//"在第170行中的"//rctassert"(!ygnodeisdirty(node), @ @ @ @从肮脏的瑜伽节点获取布局指标。");"

最新更新