【发布时间】:2022-01-23 10:20:40
【问题描述】:
TouchableOpacity onPress 在 Flatlist 中不起作用,但是当我将 onPress 替换为 onPressIn/onPressOut 时,它工作正常,但在这种情况下,反应太快并且在滚动时出现问题。我不知道发生了什么,也没有发现任何相关问题。以下是我的代码:
renderItem = ({ item, index }: { item: any, index: number }) => {
const { type } = this.props;
const valueType = {
phone: item,
stage: item.title,
location: item.name
}
return (
<TouchableOpacity
onPressIn={() => this.onSelect(item, index)}
style={styles.modalListContainer}
>
<Icon name={icon[type]} height={20} width={20}/>
<Spacer width={10} />
<View style={styles.modelTextContainer}>
<Text style={styles.modelText}>{valueType[type]}</Text>
</View>
</TouchableOpacity>
)
}
<FlatList
data={item}
renderItem={this.renderItem}
keyExtractor={this.keyExtractor}
ItemSeparatorComponent={() => <><Spacer height={10} /><View style={styles.modelTextDevider} /><Spacer height={10} /></>}
showsVerticalScrollIndicator={false}
contentContainerStyle={styles.container}
/>
它使用 react-native-modals 库在 Modal 中呈现。任何帮助,将不胜感激。 谢谢。
【问题讨论】:
标签: android react-native react-native-flatlist react-native-modal