我使用react-native-swiper来显示图像,我想将整个swiper封装在一个Pressable中,由于将会有多个这样的swiper,它们都嵌套在一个FlatList中,下面是它在代码中的样子:
<FlatList
data={locations}
renderItem={(props) => <Location {...props} />}
style={styles.flatList}
scrollEventThrottle={16}
refreshControl={refreshControl}
ListEmptyComponent={ListEmptyComponent}
contentInset={contentInset}
onScroll={onScroll}
contentContainerStyle={contentContainerStyle}
/>FlatList呈现Location组件,该组件返回以下内容:
<Pressable
style={{
position: "relative",
width: IMAGE_SIZE,
height: IMAGE_SIZE,
}}
onPress={() => console.log(id, " ,pressed")}
>
<Swiper
style={styles.swiper}
loop={false}
renderPagination={renderPagination}
>
{media.map((image) => (
<Image
key={image.id}
source={{ uri: image.url }}
style={{
width: IMAGE_SIZE,
height: IMAGE_SIZE,
}}
/>
))}
</Swiper>
</Pressable>当我试图在图像上滑动时,它只是不断地触发Pressables函数,而不想滑动到下一个图像。它在Android上的运行效果与预期一致。
当我用一个普通的视图组件替换可按下的组件时,一切正常。
发布于 2021-04-07 01:17:00
在此期间,我还添加了一个标题的组件,这有点复杂的事情,但我设法让它通过使用2个不同的可按组件。不幸的是,这移除了在图像转换时单击组件的功能,但它可以工作。
https://stackoverflow.com/questions/66972202
复制相似问题