css - React Native flexShrink 默认是 1,但好像是 0
问题描述
根据Docs,RN 中 flexShrink 的默认值为 1。但是,鉴于下面的代码,我必须将其显式设置为 1 才能使其工作,默认情况下似乎为 0。预期的行为是所有内部容器的宽度都应该缩小,以便默认情况下它们都适合屏幕。但它不会那样做,除非我取消注释这些行。谢谢你的时间
<View
style={{
flexDirection: "row",
}}
>
<View
style={{
backgroundColor: "green",
width: 100,
height: 200,
// flexShrink: 1,
}}
/>
<View
style={{
backgroundColor: "red",
width: 100,
height: 200,
// flexShrink: 1,
}}
/>
<View
style={{
backgroundColor: "blue",
width: 100,
height: 200,
// flexShrink: 1,
}}
/>
<View
style={{
backgroundColor: "maroon",
width: 130,
height: 100,
// flexShrink: 1,
}}
/>
</View>
解决方案
看起来文档现在已经更正了。
现在它说:
flexShrink 接受任何 >= 0 的浮点值,其中 0 是默认值(在网络上,默认值为 1)
我在这里找到了doc 的更改日志:
https://github.com/facebook/react-native-website/commit/2007c56fd09262cdb6803a2193a65fe555ef8344
最新文档在这里:
https://reactnative.dev/docs/flexbox
发表于 2021 年 12 月 31 日
推荐阅读
- css - 具有父子行的 Angular Material mat-table 的替代颜色
- c# - 获取日期时间和可为空的日期时间之间的日期差异
- c - 在 C 中实现两个样本 t 检验
- cassandra - cassandra如何为复合主键选择令牌
- collision-detection - Collision Hit 事件仅在敌人在 Unreal 中移动时触发?
- mysql - MySQL 没有使用 ORDER BY 的索引
- java - Java Gson ClassCastException
- java - 会话关闭后如何禁用或阻止使用 Hibernate 代理?
- javascript - 使用不记名授权将 PouchDB 同步到 Cloudant 时出错
- javascript - 无法获得按钮以根据下一页中的信息更改颜色