question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IllegalStateExceptioncom.swmansion.gesturehandler.GestureHandler in prepare

See original GitHub issue

Hello,

I’m facing some random crash in production on Android. Log give me that:

java.lang.IllegalStateException: Already prepared or hasn't been reset
    at com.swmansion.gesturehandler.GestureHandler.prepare(GestureHandler.java:178)
    at com.swmansion.gesturehandler.GestureHandlerOrchestrator.recordHandlerIfNotPresent(GestureHandlerOrchestrator.java:379)
    at com.swmansion.gesturehandler.GestureHandlerOrchestrator.recordViewHandlersForPointer(GestureHandlerOrchestrator.java:389)
    at com.swmansion.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:466)
    at com.swmansion.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:403)
    at com.swmansion.gesturehandler.GestureHandlerOrchestrator.onTouchEvent(GestureHandlerOrchestrator.java:97)
    at com.swmansion.gesturehandler.react.RNGestureHandlerRootHelper.dispatchTouchEvent(RNGestureHandlerRootHelper.java:121)
    at com.swmansion.gesturehandler.react.RNGestureHandlerRootView.dispatchTouchEvent(RNGestureHandlerRootView.java:36)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3222)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2845)
    at com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView.dispatchTouchEvent(RNGestureHandlerEnabledRootView.java:34)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3222)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2845)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3222)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2845)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3222)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2845)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3222)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2845)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3222)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2845)
    at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:697)
    at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1879)
    at android.app.Activity.dispatchTouchEvent(Activity.java:3487)
    at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
    at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:655)
    at android.view.View.dispatchPointerEvent(View.java:13732)
    at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:6119)
    at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5897)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5346)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5399)
    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5365)
    at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5524)
    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5373)
    at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5581)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5346)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5399)
    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5365)
    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5373)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5346)
    at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:8408)
    at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:8341)
    at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:8294)
    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:8523)
    at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:198)
    at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
    at android.os.MessageQueue.next(MessageQueue.java:326)
    at android.os.Looper.loop(Looper.java:181)
    at android.app.ActivityThread.main(ActivityThread.java:7037)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965) 

and when I reload my Android Emulator Device, I have: Screenshot_1574182653

my index.js:

import { AppRegistry, StatusBar, YellowBox } from 'react-native';
import { name as appName } from './app.json';
import App from './src/App';

StatusBar.setHidden(true);
YellowBox.ignoreWarnings(['-[RCTRootView cancelTouches]` is deprecated and will be deleted soon.']);
AppRegistry.registerComponent(appName, () => App);

my App.js:

import React from 'react';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler';
...
export default gestureHandlerRootHOC(App);

My environment:

  npmPackages:
    react: 16.9.0
    react-native:  0.61.4
    react-native-gesture-handler:  ^1.5.0

If someone can help me to avoid this crash and the error message when I reload that can be really nice.

Regards, Youcef EL KAMEL

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
yelkamelcommented, Nov 28, 2019

@furedal After some test and look, I find a solution:

I wrote that in my index.js

import 'react-native-gesture-handler';
...
if (Platform.OS === 'android') {
  const { UIManager } = NativeModules;
  if (UIManager) {
    // Add gesture specific events to genericDirectEventTypes object
    // exported from UIManager native module.
    // Once new event types are registered with react it is possible
    // to dispatch these events to all kind of native views.
    UIManager.genericDirectEventTypes = {
      ...UIManager.genericDirectEventTypes,
      onGestureHandlerEvent: { registrationName: 'onGestureHandlerEvent' },
      onGestureHandlerStateChange: {
        registrationName: 'onGestureHandlerStateChange',
      },
    };
  }
}

and remove I remove the gestureHandlerRootHOC()

that issue help me: https://github.com/kmagiera/react-native-gesture-handler/issues/320

I check I have no regression on iOS, it seem like gestureHandlerRootHOC() is not mandatory

0reactions
jakub-gonetcommented, Aug 23, 2021

This issue was not active for some time so I’m closing it. If you need further help please reply.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IllegalStateExceptioncom.swmansion.gesturehandler ...
I'm facing some random crash in production on Android. Here is the logcat give me that: 2019-11-20 15:00:09.752 3248-3248/? ...
Read more >
IllegalStateExceptioncom.swmansion.gesturehandler ... - GitHub
Hello, I'm facing some random crash in production on Android. Log give me that: java.lang.IllegalStateException: Already prepared or hasn't ...
Read more >
Migrating off RNGHEnabledRootView | React Native Gesture ...
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView; public class MainActivity extends ReactActivity { - @Override
Read more >
GestureHandler - Expo Documentation
This library provides an API that exposes mobile platform specific native capabilities of touch & gesture handling and recognition.
Read more >
react-native-gesture-handler | Yarn - Package Manager
Declarative API exposing platform native touch and gesture system to React Native. React Native Gesture Handler provides native-driven gesture management ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found