Both of react-native
and react-native-gesture-handler
provide Touchables (TouchableOpacity
, TouchableHighlight
, etc).
What is the difference between the Touchables from both packages? Any detailed explanation would be appreciated.
The most popular and recommended library is react-native-gesture-handler . This library exposes platform-specific (i.e., Android and iOS) native touch and gestures to React Native.
These long presses can be handled by passing a function to the onLongPress props of any of the "Touchable" components.
I think the description on their docs is very useful:
Gesture Handler library provides an implementation of RN's touchable components that are based on native buttons and does not rely on JS responder system utilized by RN. Our touchable implementation follows the same API and aims to be a drop-in replacement for touchables available in React Native.
The motivation for using RNGH touchables as a replacement for these imported from React Native is to follow built-in native behavior more closely by utilizing platform native touch system instead of relying on the JS responder system. These touchables and their feedback behavior are deeply integrated with native gesture ecosystem and could be connected with other native components (e.g. ScrollView) and Gesture Handlers easily and in a more predictable way, which follows native apps' behavior.
https://docs.swmansion.com/react-native-gesture-handler/docs/component-touchables
So if you are on the native side (not web) it's better to use Touchables from RNGH. Maybe they will include the new pressable component from RN soon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With