react-native-gesture-handler: Pressable stops working

Description

This is a really weird behavior, I’ve been facing it from time to time eventually - only on Android on both real devices and simulators.

I have a big and complex project, and sometimes it just stops receiving clicks on Pressable component.

Today I put some debugging on Pressable.tsx and I’ve found that isTouchPropagationAllowed.current is always false. The main function is:

const pressOutHandler = useCallback(
      (event: PressableEvent) => {
        console.log('pressOutHandler', isTouchPropagationAllowed.current)

        if (!isTouchPropagationAllowed.current) {
          hasPassedBoundsChecks.current = false;
          isPressCallbackEnabled.current = true;
          deferredEventPayload.current = null;

          if (longPressTimeoutRef.current) {
            clearTimeout(longPressTimeoutRef.current);
            longPressTimeoutRef.current = null;
          }

          if (pressDelayTimeoutRef.current) {
            clearTimeout(pressDelayTimeoutRef.current);
            pressDelayTimeoutRef.current = null;
          }

          return;
        }

        if (
          !hasPassedBoundsChecks.current ||
          event.nativeEvent.touches.length >
            event.nativeEvent.changedTouches.length
        ) {
          return;
        }

        if (unstable_pressDelay && pressDelayTimeoutRef.current !== null) {
          // When delay is preemptively finished by lifting touches,
          // we want to immediately activate it's effects - pressInHandler,
          // even though we are located at the pressOutHandler
          clearTimeout(pressDelayTimeoutRef.current);
          pressInHandler(event);
        }

        if (deferredEventPayload.current) {
          onPressIn?.(deferredEventPayload.current);
          deferredEventPayload.current = null;
        }

        onPressOut?.(event);

        if (isPressCallbackEnabled.current) {
          onPress?.(event);
        }

        if (longPressTimeoutRef.current) {
          clearTimeout(longPressTimeoutRef.current);
          longPressTimeoutRef.current = null;
        }

        console.log(4);

        isTouchPropagationAllowed.current = false;
        hasPassedBoundsChecks.current = false;
        isPressCallbackEnabled.current = true;
        setPressedState(false);
      },
      [onPress, onPressIn, onPressOut, pressInHandler, unstable_pressDelay]
    );

As being false its execution stops on the first condition, not firing onPress.

I couldn’t reproduce it in a repro, but it is happening often on my project.

My _layout.tsx:

return (
    <GestureHandlerRootView style={{flex: 1}}>
      <LoaderFullscreen>
        <trpc.Provider client={trpcClient} queryClient={queryClient}>
          <CustomConfirmationBottomSheetModalProvider>
            <CustomBottomSheetModalProvider>
              <ThemeProvider value={DefaultReactNavigationTheme}>
                <CustomQueryClientProvider>
                  <KeyboardProvider statusBarTranslucent>
                    <SafeAreaProvider initialMetrics={initialWindowMetrics}>
                      <AuthProvider>
                        <App />
                      </AuthProvider>
                    </SafeAreaProvider>
                  </KeyboardProvider>
                </CustomQueryClientProvider>
              </ThemeProvider>
            </CustomBottomSheetModalProvider>
          </CustomConfirmationBottomSheetModalProvider>
        </trpc.Provider>
      </LoaderFullscreen>
      {toastContent}
    </GestureHandlerRootView>
  );

As a temporary (I hope) solution, I’ll have to use <GestureDetector gesture={singleTap}> on each clickable spot and handle it manually. That way it always works.

Steps to reproduce

  1. Just open my app and try clicking on some buttons. It doesn’t happen all the time, but quite often.

Snack or a link to a repository

I couldn’t reproduce it.

Gesture Handler version

2.25.0

React Native version

0.77.1

Platforms

Android

JavaScript runtime

Hermes

Workflow

Expo managed workflow

Architecture

Paper (Old Architecture)

Build type

Release mode

Device

Real device

Device model

Moto g60

Acknowledgements

Yes

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 13
  • Comments: 48 (9 by maintainers)

Commits related to this issue

Most upvoted comments

It can be a misunderstanding of mine, specially because I have no idea how RN works in practice (I know the theory, but not the implementation challenges), but doesn’t it sound worry (sad) that the core library react-native itself can’t make a simple functional button (a button!) that fits all needs and scenarios? They have to rely on some third-party library, that also face the same issue.

I’m not complaining nor judging you guys, serious, don’t take that way. I’ve been using RN and RNGH for years. My comment here is more like “we are building products on top of it. Isn’t it dangerous? How can we push a technology that faces simple problems?”. Again, “simple problems” from the point of view of those who are consuming the API. Maybe it can be really hard to make it work without issues.

Does anyone know any articles or youtube video that go deep and show the challenges and issues of RN and why these kind of thing happen so often?

The Release 2.27.0 is now live with a fix for this issue.

I believe this is a minimal reproduction: https://github.com/baylesa-dev/PressableIssue

I would also be willing to monetarily sponsor a fix to this issue.

The lack of attention for a completely breaking issue like this one on such a core library used by almost every React Native app is frustrating to see.

We don’t have the time to contribute to a fix but we are willing to start a bounty of $500 for a pull request or patch to fix the issues on Android under React Native 0.77, old architecture.

Reverting the changes in this PR https://github.com/software-mansion/react-native-gesture-handler/pull/3295 using patch-package fixed the issue for me.

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?

Repro repo: https://github.com/baylesa-dev/PressableIssue

Fwiw I realized on my side the issue was caused by this bug in Reanimated : https://github.com/software-mansion/react-native-reanimated/issues/7109 causing exiting animations not to unmount components. I still have issues with onPressIn sometimes not firing until releasing touch though, don’t know if this is related.

My good friend @vendramini we find ourselves again in the corners of the internet!

I am also facing the exact same issue.

I am using Expo 52, React Native 0.77.1 and react-native-gesture-handler 2.25.0 I have the same issue, but only on development builds. Release builds work without issues. If you must use react-native-gesture-handler buttons I suggest you try building a release variant and see if they work, otherwise I use regular react-native buttons when there is no need to use this library (for example, I found out that modals and bottom sheets work better with gesture handler buttons, and that is about it where they are beneficial). This inconsistency and mixing button libraries in one project very messy. I hope this gets fixed because Expo and React Native push the usage of this library, and many third party libraries rely on it, so we don’t really have the option to not use it.

Edit: Actually, the same issue happens on release builds too, only rarely. I just now realised that after extensive testing of every button (I use both Pressables and BorderlessButtons from gesture handler library). It is impossible to reproduce because they stop working for unknown reasons. I tried 2.25.0, 2.24.0 and 2.23.0 - the issue is present everywhere.

Hey, could you please let me know if this issue also occurs on RNGH 2.24.0? We’ve made some changes to pressOutHandler in RNGH 2.25.0 that could be the cause of this bug.

Please let me know if #3571 works on your setups.

Tested it on the repro sent by @baylesa-dev and it now seems to be working well. Also tested with our example app on every supported platform, and haven’t found any new issues.

(c.c. @vendramini, @techied)

Haven’t got any issue so far 🥇 Thank you @latekvo !

@tannerbaum I’m not sure how adding directly from branches works in pnpm, but you can add .patch to pull request URL and then apply this patch with patch-package

Thanks, patch-package doesn’t seem to work well with pnpm but you set me down the right path. Take everything with a grain of salt coming from a react-native newbie – and because for whatever reason I had to add the …/utils.ts file inside the components directory even though that isn’t part of the PR which is fishy – but I found that with the patch:

  • It fixed the issue I had with ExpoRouter Link which wasn’t present in 2.24 but in 2.25
  • It did not fix the React Native Primitive issue, which I will share a snippet of here:

// Button call
<DropdownMenu>
    <DropdownMenuTrigger asChild>
        {/* Our custom button component, which is GH's Pressable and children */}
           <Button title="Upload Your Own" rounded="slight" type="outline" /> 
      </DropdownMenuTrigger>
// DropdownMenu.tsx
import * as DropdownMenuPrimitive from "@rn-primitives/dropdown-menu";
// ...

// A "ReactForwardRefExoticComponent" that omits ref from Native's PressableProps and adds an asChild prop
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;

It’s possible that these two libraries just aren’t meant to interact, which is fine because I found I can just pass a prop to my Button component where I conditionally render either Pressable from RN or RNGH. I just wanted to share in case it somehow helped the team during this refactor.

@tannerbaum I’m not sure how adding directly from branches works in pnpm, but you can add .patch to pull request URL and then apply this patch with patch-package

I sometimes think it’s a react modal or modal “thing” that wasn’t closed properly but you navigate away from where that modal was, perhaps programmatically. It results in some sort of freeze on new screens and there’s simply no way to recover from it othan than to restart the app. From what I see in my app it seems to still feel like it’s operating, as no drops on fps or performance has occured but yet it’s still “frozen” and unresponsive. I do agree with the sentiment of it occuring in scroll views of any sort.

I’m also experiencing this with expo 52, react native 0.77, and all the versions of gesture handler. Pressable inside of a Flatlist stop working randomly on android. I think it is maybe related to when I use scrollTo to move through the Flatlist?

Ah, I think the bug I’m facing is related to #3350

@latekvo That’s certainly possible, it seems to surface when paired with scrolling. I’ll go ahead and subscribe to that issue then. I greatly appreciate you looking into this and your contribution to this fantastic library!