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.

Touch events do not work when multiple screens are active on Android

See original GitHub issue

I added a way to have transparent scenes in react-navigation a while back to support dialogs (https://github.com/react-navigation/react-navigation-stack/blob/master/src/views/StackView/StackViewCard.js#L35). It keeps all screens active in the stack but this seems to break touch events on Android because of the logic here: https://github.com/kmagiera/react-native-screens/blob/master/android/src/main/java/com/swmansion/rnscreens/ScreenContainer.java#L189

The react-navigation code is basically this:

const modalNavigatorConfig = {
  initialRouteName: 'app',
  mode: 'modal',
  headerMode: 'none',
  transparentCard: true, // <- The option for transparent card
  defaultNavigationOptions: {
    gesturesEnabled: false,
  },
  transitionConfig: () => ({
    transitionSpec: {
      duration: 300,
      easing: Easing.inOut(Easing.ease),
      timing: Animated.timing,
    },
    screenInterpolator: sceneProps => {
      const { position, scene } = sceneProps;
      const { index } = scene;

      const opacity = position.interpolate({
        inputRange: [index - 1, index],
        outputRange: [0, 1],
      });

      return { opacity };
    },
  }),
};

const ModalStack = createAppContainer(
  createStackNavigator(
    {
      app: {
        screen: RootStack,
      },
      { screen: SomeOtherRoute },
    },
    modalNavigatorConfig,
  ),
);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:32
  • Comments:43 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
emeraldsantocommented, Aug 27, 2019

I did a little expirement and changed this line from Screen.java :

@Override
public PointerEvents getPointerEvents() {
    return mTransitioning ? PointerEvents.NONE : PointerEvents.AUTO;
}

to :

@Override
public PointerEvents getPointerEvents() {
    return PointerEvents.AUTO;
}

This seems to resolve the issue as all the views will be able to receive touch events even when “transitioning” and I haven’t seen any side effects when it comes to performance. I might make a PR with a config to override the default behaviour of this method…

7reactions
GfxKaicommented, Feb 7, 2019

Think I’m seeing a similar issue on iOS: when navigating back to a previous screen in a stack that has transparentCard set, the screen doesn’t respond to touch events. Had a poke around with the Element Inspector and it seems that the component tree is “StackViewLayout > ScreenContainer” after navigating back, compared to “StackViewLayout > SceneView > [ Screen ]” initially. Navigation gestures still work, screen focus events still trigger and navigating from the screen via code is fine. Will investigate further and try to get a snack up and running asap

Read more comments on GitHub >

github_iconTop Results From Across the Web

Manage touch events in a ViewGroup - Android Developers
Stay organized with collections Save and categorize content based on your preferences. Handling touch events in a ViewGroup takes special care, ...
Read more >
Touch events - Web APIs - MDN Web Docs - Mozilla
Touch events are similar to mouse events except they support simultaneous touches and at different locations on the touch surface. The ...
Read more >
Android Multi-touch event problems...No new ... - Stack Overflow
So yeah, the problem is that if the joystick is in the middle of a case MotionEvent.ACTION_MOVE it seems to block any other...
Read more >
Gestures and Touch Events | CodePath Android Cliffnotes
Note that every touch event can be propagated through the entire affected view hierarchy. Not only can the touched view respond to the...
Read more >
Touch & hold delay - Android Accessibility Help
"Touch & hold" is a common gesture on Android devices. It means that you touch an item on the screen and don't lift...
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