GestureHandler import

#1

Hey there,

I’m experimenting with the GestureHandler module, available here, and have had success trying out the rotate-and-zoom example. However, without thinking about it, when I copy+pasted the example code from the repo, the handlers were imported ‘normally’ as such

import {
  PanGestureHandler,
  PinchGestureHandler,
  RotationGestureHandler,
  ScrollView,
  State,
} from 'react-native-gesture-handler';

However, why does this work? In the Expo docs, it says:

This API is available under the DangerZone namespace for the time being, as it is based on the quickly-improving react-native-gesture-handler. We recommend seeing the README on the project’s GitHub repository for documentation and usage examples. No native setup is required for using this API within Expo or ExpoKit.

Shouldn’t I be importing the DangerZone namespace from Expo, and import the GestureHandler from there?

#2

Hey @jhalborrg!

I found a real live example for you in our repos if you want to check it out: https://github.com/expo/native-component-list/blob/c0abecdf4d310beb19f801d4cf2426682d2df3da/screens/GestureHandlerPinchScreen.js

That should clarify your original question about DangerZone, you should be able to stick to our usage and feel confident for now.

It looks like in our docs: https://docs.expo.io/versions/latest/sdk/gesture-handler.html#content we aren’t being super clear about how to use this. It’s on us to be more clear! Sorry about that.

Hope the live example helps, let me know if you have any more questions!

#3

react-native-gesture-handler Native Modules are exposed in the Expo client, therefore when you import 'react-native-gesture-handler' you are bringing in the javascript code and when it looks for the Native Modules it actually finds them! :open_mouth:

Here are the Native Modules in the Expo client and here they are in RNGestureHandler.

This is why it works, but it would be better to use DangerZone.GestureHandler as this currently only works by happy accident! :grin::blue_heart::upside_down_face:

#4

Thanks for the clarification :smiley: And yes, I think the docs could be clearer, that’d be great!

Edit: No, wait. The example @jimmylee refers to imports the handlers in the same manner that I do. But @bacon says that I should use the DangerZone import option. The latter makes sense to me, but just want to be clear? How should I best import i.e. the PanGestureHandler?

#5

Under the hood it’s doing the exact same thing :wink: either way is fine - I personally prefer to go through the Expo namespace just in case things change later. :blue_heart:

2 Likes