Android crash: java.lang.IllegalArgumentException: pointerIndex out of range
Description
We have a crash on Android, the stacktrace is provided below.
This patch has already merged as changes to the new version but the issue is still reproducible.
react-native-gesture-handler+2.12.0.patch
Stacktrace
java.lang.IllegalArgumentException: pointerIndex out of range at android.view.MotionEvent.nativeGetAxisValue(MotionEvent.java) at android.view.MotionEvent.getY(MotionEvent.java:2445) at android.widget.ScrollView.onTouchEvent(ScrollView.java:895) at com.facebook.react.views.scroll.ReactScrollView.onTouchEvent(ReactScrollView.java:460) at com.swmansion.gesturehandler.core.NativeViewGestureHandler.onHandle(NativeViewGestureHandler.java:113) at com.swmansion.gesturehandler.core.GestureHandler.handle(GestureHandler.java:374) at com.swmansion.gesturehandler.core.GestureHandlerOrchestrator.deliverEventToGestureHandler(GestureHandlerOrchestrator.java:276) at com.swmansion.gesturehandler.core.GestureHandlerOrchestrator.deliverEventToGestureHandlers(GestureHandlerOrchestrator.java:231) at com.swmansion.gesturehandler.core.GestureHandlerOrchestrator.onTouchEvent(GestureHandlerOrchestrator.java:45) at com.swmansion.gesturehandler.react.RNGestureHandlerRootHelper.dispatchTouchEvent(RNGestureHandlerRootHelper.java:97) at com.swmansion.gesturehandler.react.RNGestureHandlerRootView.dispatchTouchEvent(RNGestureHandlerRootView.java:35) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3173) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2823) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3173) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2823) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3173) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2823) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3173) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2823) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3173) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2823) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3173) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2823) at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:502) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1890) at android.app.Activity.dispatchTouchEvent(Activity.java:4195) at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:70) at com.dynatrace.android.window.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:79) at com.contentsquare.android.sdk.cf.dispatchTouchEvent(cf.java:4) at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:460) at android.view.View.dispatchPointerEvent(View.java:14837) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:6617) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:6392) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5866) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5923) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5889) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:6054) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5897) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:6111) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5870) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5923) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5889) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5897) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5870) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:8931) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:8871) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:8828) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:9063) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:259) at android.os.MessageQueue.nativePollOnce(MessageQueue.java) at android.os.MessageQueue.next(MessageQueue.java:335) at android.os.Looper.loopOnce(Looper.java:161) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7888) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:568) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)
Steps to reproduce
Possible steps are described here: https://github.com/software-mansion/react-native-gesture-handler/issues/1679#issuecomment-1471576215
Snack or a link to a repository
Unknown
Gesture Handler version
2.13.4
React Native version
0.72.6
Platforms
Android
JavaScript runtime
None
Workflow
React Native (without Expo)
Architecture
None
Build type
Release mode
Device
Real device
Device model
No response
Acknowledgements
Yes
Hey! 👋
The issue doesn't seem to contain a minimal reproduction.
Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?
@github-actions The example provided here: https://github.com/software-mansion/react-native-gesture-handler/issues/1679#issuecomment-1471576215
Hi @bahinskamariia! Could you provide more information about device that you're using? This problem should already be fixed by #2551 and it is hard to reproduce it without more information.
Hi @m-bert, we faced this issue on production on such devices: Pixel 7 Pro, Pixel 6, Pixel 6a, Pixel 6 Pro and some others.
Hi @bahinskamariia! I've just checked that on Pixel 6 and it works fine - nothing crashes. Also I've checked that on the commit before the solution was merged and it did crash.
Given that, we can't do much unless we get reproduction that actually crashes.
Hello,
we took a look at this issue and it looks NativeViewGestureHandler component which wraps the FlatList is unnecessary, and is the reason for this crash.
Removing it should fix the issue.
Code:
Reproduction code
import React, { useMemo, useState } from 'react';
import {
Modal,
StyleSheet,
Text,
Pressable,
View,
Dimensions,
} from 'react-native';
import Animated from 'react-native-reanimated';
import {
FlatList,
GestureHandlerRootView,
NativeViewGestureHandler,
} from 'react-native-gesture-handler';
const Item = ({ title }: { title: string }) => {
return (
<View>
<Text style={styles.title}>{title}</Text>
</View>
);
};
const windowHeight = Dimensions.get('window').height;
export default function Example() {
const [modalVisible, setModalVisible] = useState(false);
const data: { id: number; title: string }[] = useMemo(() => {
const newData = [];
for (let i = 0; i < 100; i++) {
newData.push({ id: i, title: `hello - ${i}` });
}
return newData;
}, []);
return (
<View style={styles.centeredView}>
<Modal animationType="slide" transparent={true} visible={modalVisible}>
<GestureHandlerRootView style={styles.rootContainer}>
<Animated.View style={styles.animatedContainer}>
{/* <NativeViewGestureHandler> */}
<FlatList
data={data}
renderItem={({ item }) => <Item title={item.title} />}
keyExtractor={(item) => item.id.toString()}
/>
{/* </NativeViewGestureHandler> */}
</Animated.View>
</GestureHandlerRootView>
</Modal>
<Pressable
style={[styles.button, styles.buttonOpen]}
onPress={() => setModalVisible(true)}>
<Text style={styles.textStyle}>Show Modal</Text>
</Pressable>
</View>
);
}
const styles = StyleSheet.create({
centeredView: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
marginTop: 22,
},
rootContainer: {
width: '100%',
height: '100%',
},
animatedContainer: {
backgroundColor: 'white',
overflow: 'hidden',
flexShrink: 1,
width: '100%',
opacity: 1,
height: windowHeight / 2,
},
button: {
borderRadius: 20,
padding: 10,
elevation: 2,
},
buttonOpen: {
backgroundColor: '#F194FF',
},
textStyle: {
color: 'white',
fontWeight: 'bold',
textAlign: 'center',
},
title: {
color: 'white',
backgroundColor: 'black',
},
});