6

If I want to prevent the onPress event on the View component propagating to the parent Touchable for the following Sample component, what's the best option other than wrapping the child view in a Touchable please?

export default function Sample (): Element<*> {
  return(
    <TouchableOpacity>
      <View>
        <Text>Sample</Text>
      </View>
    </TouchableOpacity>
  );
}
aprofromindia
  • 1,111
  • 1
  • 13
  • 27
  • Duplicate of https://stackoverflow.com/questions/31866671/how-to-stop-touch-event-propagation-in-react-native ? – odemolliens Mar 28 '18 at 12:43

1 Answers1

0

In my case I simply put the View inside another TouchableOpacity (with activeOpacity to 1 to block any graphic effect):

export default function Sample (): Element<*> {
  return(
    <TouchableOpacity>
      <TouchableOpacity activeOpacity={1}>
        <View>
          <Text>Sample</Text>
        </View>
      </TouchableOpacity>
    </TouchableOpacity>
  );
}