我也在学习 React Native 和 Flexbox。您的问题促使我尝试使用 flex-basis,因为我也遇到了麻烦。
我正在使用 RN 0.34 并在 iOS 模拟器中运行。
我发现 RN 部分支持“flexBasis”。 flexBasis 值只能是数字。不能引用数字。 '%' 或 'px' 等限定符会导致运行时错误。
flexBasis 让我可以控制一行中 Text 元素的相对宽度。 (看起来 RN 将 flexBasis 值解释为百分比。)您可以通过在 RN 模拟器中运行以下代码来看到这一点。
<View >
<Text>1a) Basic flexBasis</Text>
<View style={{flexDirection: 'row'}}>
<Text style={{ backgroundColor: "lightgray", flexBasis: 40 }}>foo</Text>
<Text style={{ backgroundColor: "lightgreen", flexBasis: 20 }}>bar</Text>
<Text style={{ backgroundColor: "lightblue", flexBasis: 40}}>baz</Text>
</View>
<Text>1b) Basic flexBasis, but with different values and effect than 1a.</Text>
<View style={{flexDirection: 'row'}}>
<Text style={{ backgroundColor: "lightgray", flexBasis: 10 }}>foo</Text>
<Text style={{ backgroundColor: "lightgreen", flexBasis: 80 }}>bar</Text>
<Text style={{ backgroundColor: "lightblue", flexBasis:10}}>baz</Text>
</View>
<Text>2) Adding flexGrow makes the items fill the row.</Text>
<View style={{flexDirection: 'row'}}>
<Text style={{ backgroundColor: "lightgray", flexGrow: 1, flexBasis: 10 }}>foo</Text>
<Text style={{ backgroundColor: "lightgreen", flexGrow: 2, flexBasis: 80 }}>bar</Text>
<Text style={{ backgroundColor: "lightblue", flexGrow: 1, flexBasis:10}}>baz</Text>
</View>
<Text>3) Flexbox attirbutes spaceBetween and spaceAround didn't work. But CSS margin can separate the items.</Text>
<View style={{flexDirection: 'row'}}>
<Text style={{ backgroundColor: "lightgray", marginRight: 10, flexGrow: 1, flexBasis: 10 }}>foo</Text>
<Text style={{ backgroundColor: "lightgreen", flexGrow: 2, flexBasis: 80 }}>bar</Text>
<Text style={{ backgroundColor: "lightblue", marginLeft: 10, flexGrow: 1, flexBasis:10}}>baz</Text>
</View>
</View>
在其他博客文章中,我看到了人们使用borderRadius 使元素圆角的示例。但是当我尝试他们的代码时,我并没有得到圆角。
可能原发帖人已经找到答案了。也许其他 RN 新手会发现此信息很有帮助。