【发布时间】:2020-10-06 00:08:12
【问题描述】:
在我的组件中,我为每个项目渲染了一个按钮。它正在工作。但是,当我将所有这些都包裹在一个可触摸的 TouchableOpacity 中时,该按钮不再起作用。现在一切都是可触摸的不透明度。我怎样才能仍然使用该按钮?
return (
<TouchableOpacity onPress= {()=> console.log('Hello')}>
<View style={styles.item} key={item.id}>
<Thumbnail
style={styles.thumbnail}
source={{
uri:
'https://cdn4.iconfinder.com/data/icons/avatars-xmas-giveaway/128/afro_woman_female_person-512.png',
}}></Thumbnail>
<View style={styles.nameNumber}>
<Text style={styles.userName}>{userName}</Text>
</View>
<View style={styles.deleteButtonContainer}>
<Button
rounded
style={styles.deleteButton}
onPress={() => onDeleteContact(item.id)}
>
<Icon name="trash-o" size={moderateScale(20)} color="black" />
</Button>
</View>
</View>
</TouchableOpacity>
);
},
【问题讨论】:
-
什么是
TouchableOpacity?它是否捕获所有用户输入(如鼠标单击事件)? -
是的@user0101。它来自 react-native-gesture-handler
-
嗯,所以它与按钮重叠,对吧?
-
是的,如果我点击按钮,我只需点击不透明度@user0101
-
你是从“react-native-gesture-handler”还是“react-native”导入TouchableOpacity?
标签: javascript reactjs typescript react-native native-base