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

标签 react-native

在 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/

相关文章:

ios - react 原生中的自定义字体

image - 在 React-Native 中将图像合并到视频

android - 找不到处理 Intent com.instagram.share.ADD_TO_STORY 的 Activity

ios - 在发出 OAuth token 交换请求时,如何深层链接并导航到 "LogInLoading"屏幕?

javascript - 类型错误 : undefined is not an object (evaluating 'data.filter' ) - React Native

javascript - function.querySnapshot 不是函数

android - 如何测试具有 native 依赖的 npm 库

reactjs - 当多个组件使用复杂对象的一部分作为其源时,redux 如何工作

javascript - 无法从 Indeed 找到模块 `./index`

javascript - Undefined 不是评估 this.state 的对象。*