mid*_*dev 7 pinterest masonry react-native
有没有办法在React Native中使用flexbox来实现Masonry/Pinterest样式列?
在React Native中,远程图像在加载时不会调整大小(请参阅" 为什么不自动调整所有内容 ").这似乎限制了使用flexbox,因为默认情况下远程图像的大小为0x0,如果设置宽度或高度,它们不会像在Web上那样保持宽高比.
幸运的是,在这个github pull请求中有很多讨论,这导致了@paramaggarwal的一些出色的工作来生成如下所示的代码:
<View aspectRatio={1}>
<View style={{flexDirection: 'row', flex: 1}}>
<Image
style={{flex: 1}}
source={{uri: "http://edibleapple.com/wp-content/uploads/2009/11/steve-jobs-bill-gates-1991.jpg"}}
/>
<Image
style={{flex: 2}}
source={{uri: "http://edibleapple.com/wp-content/uploads/2009/11/steve-jobs-bill-gates-1991.jpg"}}
/>
</View>
<View style={{flexDirection: 'row', flex: 1}}>
<Image
style={{flex: 3}}
source={{uri: "http://edibleapple.com/wp-content/uploads/2009/11/steve-jobs-bill-gates-1991.jpg"}}
/>
<Image
style={{flex: 2}}
source={{uri: "http://edibleapple.com/wp-content/uploads/2009/11/steve-jobs-bill-gates-1991.jpg"}}
/>
</View>
</View>
Run Code Online (Sandbox Code Playgroud)
并启用这样的布局:

虽然这不完全是您需要的布局,但我非常确定此更改将允许flexbox以更像"网络"的方式用于图像.根据github的说法,PR已经准备好在昨天(7月3日)合并,所以希望它不会太长,直到我们在发布中看到它.
| 归档时间: |
|
| 查看次数: |
5302 次 |
| 最近记录: |