Everything inside Pressable should be pressable and trigger goBack. This code correctly allows me to press the contents inside the Pressable to go back:
<View style={styles.header}>
<Pressable
style={({ pressed }) => [
styles.backButtonContainer,
{
color: pressed ? 'rgba(0, 224, 255, 0.3)' : 'transparent',
},
]}
onPress={() => navigation.goBack()}
android_ripple={{ color: 'rgba(0, 224, 255, 0.3)', borderless: false }}
hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
>
<Icon name="chevron-back-outline" color="#00e0ff" size={24} />
</Pressable>
<View style={{ flex: 1, alignItems: 'center' }}>
<Text style={styles.title}>Add Gym</Text>
</View>
</View>
In this version pressing the arrow icon doesn't trigger anything yet pressing the padding does:
<View style={styles.header}>
<Pressable
style={({ pressed }) => [
styles.backButtonContainer,
{
color: pressed ? 'rgba(0, 224, 255, 0.3)' : 'transparent',
},
]}
onPress={() => navigation.goBack()}
android_ripple={{ color: 'rgba(0, 224, 255, 0.3)', borderless: false }}
hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
>
<Icon name="chevron-back-outline" color="#00e0ff" size={24} />
</Pressable>
<Text style={styles.title}>Add Gym</Text>
</View>
CSS:
header: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingHorizontal: 10,
paddingVertical: 20,
},
backButtonContainer: {
flexDirection: 'row',
alignItems: 'center',
padding:8,
},
Since you have a
hitSlopset for thePressablecomponent, you are able to press on it outside its render view.There could be 2 things affecting the touch area on the icon itself:
Make sure that there are no absolute views rendered on top of the button.
Pressablecomponent.For this, try to add to the Icon
pointerEventsprop and set it as null.Like this:
Not sure which
Iconlibrary you are using, but it should inheritViewprops, in case it doesn't, wrap the whole Icon with aViewand set thepointerEventsto it instead.