Closed mrousavy closed 3 years ago
I've added debug statements everywhere and noticed that the <PanGestureHandler>
's onHandlerStateChange
and onGestureEvent
callbacks never get called. The gesture never gets recognized. Anyone know why?
I'm pretty sure it has something to do with pointerEvents
, not sure why that would get overriden though. I've played around with the property and got it recognizing my gesture once, but it hasn't worked since then. Is this a bug?
Maybe because my thumb has position: 'absolute'
?
same thing happened to me for React Native 0.63.2 it was fine on React Native 0.62
same thing happened to me for React Native 0.63.2 it was fine on React Native 0.62
I missed the installation step whereby I need to update MainAcivity.java.
It works ok now.
I didn't miss the installation step in MainActivity.java
, but it still doesn't work. It sometimes works on my HomeScreen, and it never works in my Modal.
Because RNGH doesn't work in modals at the moment.
If you do an Animated.duration(myValue, {toValue: 0, duration: 0})
as soon as you mount the component does it start working?
@evanc I'm sorry, what?
oops, sorry, I meant Animated.timing
. You'll also need to set the property useNativeDriver
or it will warn.
basically just do a throwaway animation on the value. I have seen a similar issue where the value wouldn't work until it had been Animated at least once.
@evanc Oh I see.
I've added:
useEffect(() => {
Reanimated.timing(thumbX, { toValue: 0, duration: 0, easing: Easing.linear });
}, [thumbX]);
And it still didn't work.
EDIT: What do you mean with useNativeDriver
? Do you mean react-native's Animated library instead of Reanimated?
I have a similar issue, can't make a TouchableOpacity work if wrapped in a PanGestureHandler. No issue on iOS. Does someone have a clue on this ?
Same issue here even after following the installation instructions. PanGestureHandler works fine on iOS but doesn't even fire any events on Android.
@MrGVSV, please provide some repro showing this problem.
this works for me on Android, it's an age slider
const { width } = Dimensions.get('window');
export default function AgeEditPage(props) {
const [rangeMeter, setRangeMeter] = useState(100);
const [maxAge, setMaxAge] = useState(18);
useEffect(() => {
updateRange(100);
}, []);
const updateRange = (meterRange) => {
const meterPercentage = (meterRange - 90) / (width - 150);
const meterAge = Math.floor(18 + meterPercentage * 62);
setMaxAge(meterAge);
setRangeMeter(meterRange);
};
const updateDelta = (event) => {
const { absoluteX } = event.nativeEvent;
const meterRange = clamp(absoluteX, 90, width - 60);
updateRange(meterRange);
};
return (
<ScrollView style={styles.container} contentContainerStyle={styles.content}>
<View style={styles.info}>
<Text style={styles.title}>I'm {maxAge} years old</Text>
<PanGestureHandler onGestureEvent={updateDelta} activeOffsetX={[-10, 10]}>
<View style={[styles.range, { width: rangeMeter }]}>
<Text style={styles.rangetext}>Age</Text>
</View>
</PanGestureHandler>
</View>
</ScrollView>
);
}
@mrousavy, is this issue still relevant?
(I mean if it isn't connected to the modal issue I linked. We're transferring issues to discussions and I want to close anything that may be outdated by now)
@jakub-gonet not for me, since I'm not using <Modal>
components anymore. In a react-native-navigation Modal screen everything works as expected. And we can definitely close this one since it's a duplicate of #139 (my bad) 👍
Thanks for the fast follow-up!
Adding activeOffsetX={[0, 0]}
to PanGestureHandler
fixed it for me. :)
<Modal transparent>
<GestureHandlerRootView style={{flex:1}}>
<PanGestureHandler>
<Animated.View>
{/* Your components */}
</Animated.View>
</PanGestureHandler>
</GestureHandlerRootView>
</Modal>
it worked for me when i did it like this
I had the problem of moving the Animated.View on a Modal on Android (on iOS, no problem), after I tried @shoki61's answer, it worked, so just wrap the
@shoki61 work for me, thanks for your contribution!
<Modal transparent> <GestureHandlerRootView style={{flex:1}}> <PanGestureHandler> <Animated.View> {/* Your components */} </Animated.View> </PanGestureHandler> </GestureHandlerRootView> </Modal>
it worked for me when i did it like this
Timesaver! GestureHandlerRootView helps
<Modal transparent> <GestureHandlerRootView style={{flex:1}}> <PanGestureHandler> <Animated.View> {/* Your components */} </Animated.View> </PanGestureHandler> </GestureHandlerRootView> </Modal>
it worked for me when i did it like this
Just to complement @shoki61 solution if anyone needs more clarification, this is mentioned on documentation: https://docs.swmansion.com/react-native-gesture-handler/docs/installation#usage-with-modals-on-android
They recommend using gestureHandlerRootHOC, which is the equivalent of wrapping with <GestureHandlerRootView style={{ flex: 1 }}>. You can check here: https://github.com/software-mansion/react-native-gesture-handler/blob/main/src/gestureHandlerRootHOC.tsx
Description
Hi! I've read the docs about 20 times now, and I still can't seem to get my
<PanGestureHandler>
working on Android.The View is in a Modal, but that Modal is wrapped with the gesture handler root HOC. I've also updated my MainActivity. Other PanGestureHandlers work, so it must be something with my code specifically, but I can't pinpoint it.
Code
Package versions