Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Touchables from react-native and react-native-gesture-handler

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.

like image 334
baymax Avatar asked Nov 08 '20 19:11

baymax


People also ask

What does React-Native-gesture-handler do?

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.

How do you handle the long press in React Native?

These long presses can be handled by passing a function to the onLongPress props of any of the "Touchable" components.


1 Answers

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.

like image 175
Arbnor Avatar answered Sep 21 '22 23:09

Arbnor