我这里有一个问题。当我尝试在我的React Native应用中添加onPress时,标签根本不会按下,而当我在图标标签中添加onPress时,它确实可以工作,但这不是我想要的。
下面是我现在拥有的代码:
import { StyleSheet, Text, View, SafeAreaView ,TouchableOpacity} from 'react-native'
import React from 'react'
import tw from 'twrnc'
import { Icon } from 'react-native-elements'
import { useNavigation } from '@react-navigation/native'
const RideOptionsCard = () => {
const navigation = useNavigation();
return (
<SafeAreaView>
<View>
<TouchableOpacity onPress={()=>{console.log("hello")}} style={tw`bg-black absolute top-6 left-5 rounded-full`} >
<Icon name="chevron-left" type="fontawesome"/>
</TouchableOpacity>
{/* <TouchableOpacity
onPress={()=>{console.log("hello")}}
style={tw`absolute top-6 left-5 rounded-full`}
>
<Icon name="chevron-left" type="fontawesome"/>
</TouchableOpacity> */}
<Text style={tw`text-center py-5 text-xl font-medium`}>Select A Ride</Text>
</View>
</SafeAreaView>
)
}
export default RideOptionsCard
const styles = StyleSheet.create({})
字符串
我试着把onPress放在图标标签中,只要它没有被视图或可触摸不透明标签包裹,它就可以工作
enter image description here
1条答案
按热度按时间owfi6suc1#
我发现的问题是与
Text
组件,因为它是重叠的图标,这是防止它检测到任何互动。我让它工作的方式是给
Text
组件增加一些宽度,并从图标中删除absolute
定位。字符串
这是它的工作snack。