gpt4 book ai didi

reactjs - React Native - 如何构建像 Facebook 一样的图像网格

转载 作者:行者123 更新时间:2023-12-03 14:04:31 25 4
gpt4 key购买 nike

我希望使用 React Native 创建一个应用程序,并且需要像 Facebook 事件照片一样排列和显示图像列表。

简而言之,我想创建react-native版本的 https://taras-d.github.io/images-grid/

有人知道提供类似功能的 RN 组件吗?

最佳答案

您可以通过设置每个图像的宽度高度来自行创建图像网格并将其呈现在一行中。

例如,您想要 1 行 3 个图像。您可以使用尺寸来获取窗口宽度并除以 3。

const windowWidth = Dimensions.get('window').width;
var IMAGES_PER_ROW = 3;

calculatedSize(){
var size = windowWidth / IMAGES_PER_ROW
return {width: size, height: size}
}

之后,我们将连续渲染图像。

renderRow(images) {
return images.map((uri,i) =>{
return(
<Image key={i} style={[styles.item, this.calculatedSize()]} source={{uri: uri}} />
);
})
}
renderImagesInGroupsOf(count) {
return _.chunk(IMAGE_URLS, IMAGES_PER_ROW).map((imagesForRow,i) => {
return (
<View style={styles.row} key={i}>
{this.renderRow(imagesForRow)}
</View>
)
})
}

您可以在styles.item中设置图像网格边距,例如margin: 1

完整示例 here

关于reactjs - React Native - 如何构建像 Facebook 一样的图像网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41540279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com