React-native-gesture-handler: PanGestureHandler only for vertical movement

Created on 18 Dec 2018  路  4Comments  路  Source: software-mansion/react-native-gesture-handler

This is more of a question really.

I have tried every combination that I could think of but the gesture event is still triggering for horizontal movement when I only want it to become active on vertical movement only.

Any pointers?

source code available here https://github.com/mattermost/mattermost-mobile/blob/master/app/components/slide_up_panel/slide_up_panel.js

Question

Most helpful comment

If you need only one direction, the ScrollView component might be enough for you (you can get a version from gesture-handler which is wrap to support BaseGestureHandler.
Otherwise, if you only listen to translationY, then it will only work for vertical movement if that makes sense.
You can also play with the activeOffsetY property. For instance activeOffsetY={[-10, 10]} will only activate the gesture handler when vertically swiped up or down to 10 pixels.

I hope this helps.

All 4 comments

If you need only one direction, the ScrollView component might be enough for you (you can get a version from gesture-handler which is wrap to support BaseGestureHandler.
Otherwise, if you only listen to translationY, then it will only work for vertical movement if that makes sense.
You can also play with the activeOffsetY property. For instance activeOffsetY={[-10, 10]} will only activate the gesture handler when vertically swiped up or down to 10 pixels.

I hope this helps.

@wcandillon how to move element only down ? And less the original position or equal.

@userbq201 I've done this to handle the swipe down gesture only. In the onHandlerStateChange for the PanGestureHandler, I've checked if the nativeEvent.velocityY > 0 which means it is swiping down.

Seems to be resolved.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TerrerSandman picture TerrerSandman  路  3Comments

chrisdrackett picture chrisdrackett  路  4Comments

brunolemos picture brunolemos  路  3Comments

alexthebake picture alexthebake  路  3Comments

brentvatne picture brentvatne  路  4Comments