Repository navigation
withRef/simultaneousHandlers usage in RNGH v3 #4418
|
hi! i wonder whats the correct usage/migration of Gesture.withRef/simultaneousHandlers (which accepts a ref of gesture) in RNGH v3? the new docs have 0 mentions of this. This is relevant in eg. #3595 Many thanks in advance! |
Replies: 3 comments 5 replies
|
Hi @lovegaoshi! Could you show example which you find confusing to migrate? In general, if you don't use relations hooks, you should be able to pass gestures objects to the relevant config fields, e.g.: const innerTap = useTapGesture({});
const outerTap = useTapGesture({
requireToFail: innerTap,
}); |
|
thanks for the response, im specifically looking at withRef as I need to pass it to another legacy prop RNGHScrollView.overrideProps.simutaneousHandlers the goal is to enable both the scrollivew's native handler + an additional handler. specifically my case is I want to use scrollview's pull down to refresh at the beginning + a custom gesture's pull up to refresh at the bottom. my previous testing using simultaneous with nativeGesture and panGesture doesnt work, only via overrideProps.simutaneousHandlers. |
|
Hi @lovegaoshi, just to add a concrete example to @m-bert's answer, since the v3 docs don't spell out this exact migration.
For "native scroll + pull-up gesture at the bottom" that gives something like: import { GestureDetector, ScrollView, usePanGesture } from 'react-native-gesture-handler';
const pan = usePanGesture({
// only react to upward drags; check your own "at bottom" condition here
onUpdate: (e) => { /* e.translationY < 0 && atBottom.current -> show pull-up indicator */ },
onDeactivate: () => { /* trigger refresh if the threshold was passed */ },
});
<GestureDetector gesture={pan}>
<ScrollView
simultaneousWith={pan} // replaces overrideProps.simultaneousHandlers + withRef
onScroll={...} // track whether you're at the end of the content
scrollEventThrottle={16}
/>
</GestureDetector>Notes:
|
Hi @lovegaoshi, just to add a concrete example to @m-bert's answer, since the v3 docs don't spell out this exact migration.
withRef(and ref-basedsimultaneousHandlers) belongs to the legacy API, so it can't be mixed with hook-based gestures, as you were told. In v3 you don't pass a ref anymore: you pass the gesture object returned by the hook. Reading the 3.3.0 sources, the relation props aresimultaneousWith,requireToFailandblock(ExternalRelations), and they are accepted both by the gesture hooks and by the RNGH wrapped components (ScrollView,FlatList, ...).For "native scroll + pull-up gesture at the bottom" that gives something like: