Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pressable elements not working in native-stack on Android devices with new architecture #2219

Closed
DrZoidberg09 opened this issue Jun 28, 2024 · 67 comments · Fixed by #2466
Closed
Assignees
Labels
NewArch Issues related only to new architecture Platform: Android This issue is specific to Android Repro provided A reproduction with a snack or repo is provided

Comments

@DrZoidberg09
Copy link

DrZoidberg09 commented Jun 28, 2024

Description

When using Android devices (iOS and Android emulator is fine) you cannot use onPress in the header bar. onPressIn and onPress out does work. This was tested mostly with Samsung devices.
This only happens with native-stack / Expo Router.

Please have a look here:
expo/expo#30032
react-navigation/react-navigation#12039
facebook/react-native#44643

Steps to reproduce

  1. Use react navigation native-stack with new arch enabled on RN 0.74
  2. Go to a stack screen and try to press elements with onPress
  3. onPress elements wont work. onPressIn and onPressOut does

Snack or a link to a repository

https://github.com/DrZoidberg09/RN-Android-Touch-Issue/

For comparison a repo with bare RN, one with Expo and react navigation stack and one with Expo router / native-stack

Screens version

3.32.0

React Native version

0.74

Platforms

Android

JavaScript runtime

Hermes

Workflow

None

Architecture

Fabric (New Architecture)

Build type

None

Device

None

Device model

Samsung S23, Samsung S8+

Acknowledgements

Yes

@github-actions github-actions bot added Platform: Android This issue is specific to Android Repro provided A reproduction with a snack or repo is provided labels Jun 28, 2024
@kkafar
Copy link
Member

kkafar commented Jul 2, 2024

🫨

@kkafar kkafar self-assigned this Jul 2, 2024
@kkafar
Copy link
Member

kkafar commented Jul 2, 2024

Is that the thing only on real devices?

@DrZoidberg09
Copy link
Author

Yes. So far, only tested with Samsung devices, incl. S24, S8+ and a Samsung tablet (dont remember the name)

@DrZoidberg09
Copy link
Author

Plus everything pressable goes completely crazy in the screen (not only the header bar), if it is an actually build apk instead of an expo development build. However, not sure if this related.

@AnzeBlaBla
Copy link

AnzeBlaBla commented Jul 3, 2024

Also happening in our app, we've only seen it happen on-device, specifically the S23.

It seems to do with the RN JS responder system, because using react-native-gesture-handler replacements for buttons and other things makes them work.

ScrollViews and FlatLists also work when the bug happens.

It also feels like it sometimes happens when the app is backgrounded for a while and then returns to focus, but this is not confirmed.

@martinezguillaume
Copy link

I have the same issue here but with iOS (not tested on Android)
It is only present in production build
It seems that when Pressable is pressed, it is disappearing for 1 frame and reappear right after causing important flicker.
It is not happening all the time, for me, it is happening when I push a new screen and the previous screens has elements.

Screen <- Pressable working

EmptyScreen
PushScreen <- Pressable is working

ScreenWithStuff
PushScreen <- Pressable is crazy

I hope it's understandable

Here is the behavior that I have
https://github.com/software-mansion/react-native-screens/assets/17292331/ff38698f-5a59-480e-bfeb-951e1f03b46f

Note : It is only happening in production build with new arch enabled

@tboba
Copy link
Member

tboba commented Jul 8, 2024

Hi @DrZoidberg09! Thanks for creating this issue. I can observe there are some several issues, related to this one:

#2150
facebook/react-native#44610

However, I didn't check if #2150 is related to the behavior of onPressIn/Out. Have you tried creating a navigation from stack navigator with detachInactiveScreens set to false inside the Navigator and checking if pressables also don't work there?

@DrZoidberg09
Copy link
Author

DrZoidberg09 commented Jul 8, 2024

@tboba I tried it with detachInactiveScreens true or false. It does not make any difference. Both do not work.

@tboba
Copy link
Member

tboba commented Jul 9, 2024

@DrZoidberg09 thanks for checking. This means that probably this issue is out of scope of react-native-screens (since the weird behavior still happens after disabling screens). I'll try to reproduce it on my side and re-check the scenario given above, but as I said, I would report this issue on react-navigation repository or official react-native one.

@DrZoidberg09
Copy link
Author

I actually did open the issue at react-native first. They redirected me to react navigation, and they directed me here.

Feels a little bit like going from one doctor to another :)

For my understanding: Why this is not coming from screens? It can defitely be tracked down to the native-stack from react native navigation. Hence, they mentioned it is related to screens.

@tboba
Copy link
Member

tboba commented Jul 9, 2024

@DrZoidberg09 I understand your point of view 😄 That's why I asked if this issue also happens on the classic Stack Navigator with detachInactiveScreens turned off (which means that you're resigning from using react-native-screens). If this issue happens on views without screens, then this problem must be related to react-navigation/react-native, but that's of course worth checking.

@DrZoidberg09
Copy link
Author

Oh, I noticed I misread your posting from above. I tried detachInactiveScreens true or false on native-stack navigator. Normal stack does work completely fine.
And the issue is only in the stack. The base view of the Tab for example is totally fine. Only if you navigate to a native-stack screen, the issues happen.

@DavidAmyot
Copy link

+1

Have the same issue since upgraded to latest Expo SDK 51 using expo-router. onPress buttons in the header do not work, but onPressIn does work.

Works fine on the simulator, but on our Samsung Galaxy Tab Active4 Pro 5g tablets, the issue is present (even with a development build instead of sdk).

One thing I saw too is that if I try to long press the button, the button's focused color does not stay active like it should, it flashes a fraction of a second.

hyochan added a commit to crossplatformkorea/cpk that referenced this issue Aug 6, 2024
@hyochan
Copy link

hyochan commented Aug 6, 2024

This is a real drawback of enabling newArch in Expo.

hyochan added a commit to crossplatformkorea/cpk that referenced this issue Aug 6, 2024
@tboba tboba added the NewArch Issues related only to new architecture label Aug 7, 2024
@alduzy
Copy link
Member

alduzy commented Aug 7, 2024

Just like in #1975 (comment) Using RectButton from react-native-gesture-handler is a workaround in this case.

@hyochan
Copy link

hyochan commented Aug 9, 2024

Just like in #1975 (comment) Using RectButton from react-native-gesture-handler is a workaround in this case.

Oh this works! Thank you

hyochan added a commit to crossplatformkorea/ExpoBriefing that referenced this issue Aug 10, 2024
@jpdery
Copy link

jpdery commented Oct 9, 2024

In my case I'm not even able to focus on TextInputs

@WKampel
Copy link

WKampel commented Oct 12, 2024

onPress also not working for me. But onPressIn does work. I'm on the latest beta version and Android. But it seems to only be a problem for me in certain situations (like in a scrollview that's inside a drawer content).

@WKampel
Copy link

WKampel commented Oct 12, 2024

RectButton does work. But I'm not sure it can sub touchable opacity.

@mym0404
Copy link
Contributor

mym0404 commented Oct 13, 2024

I wonder #2292 fixes this. But it is shipped on 4.x only and not in stable release (3.x).

The component in react-native-gesture-handler can't replace native Pressable component completely. But in my case, if I change [native stack to JS stack](JavaScript stack with @react-navigation/stack), touch issue was gone. (0.75, new arch)

@kriit24
Copy link

kriit24 commented Jan 14, 2025

problem is not only that onPress does not work, but onPressIn also does not work all time. when u in development mode and usb cable is connected then 10+ times clicked onPressIn also stops working. i dont know, does this happens in live also, but at this moment I don't dare build anything to live.

@antoinerey
Copy link

Could it be possible that despite the fix for screen content, and the latest one for header content, this issue still impacts form sheets?

I tried different presentation modes (e.g. regular screens, modals, and form sheets), and it seems that pressable elements in form sheets are still kinda hard to press. Both regular screen and modal presentation modes are working perfectly, but not sheets.

@kkafar
Copy link
Member

kkafar commented Jan 17, 2025

@antoinerey what platform do you speak of? Android or iOS?

@antoinerey
Copy link

@antoinerey what platform do you speak of? Android or iOS?

Android 🤗

@antoinerey
Copy link

Sorry for the late reproduction, but I've not been able to actually reproduce on a minimal application. There might be something conflicting in our production application, but I've not had time to deeply investigate, so I'm not sure what might be the root cause.

Feel free to discard my report as it seems invalid. 🙇

@pknrs
Copy link

pknrs commented Feb 2, 2025

This is still an issue as of now

@kkafar
Copy link
Member

kkafar commented Feb 2, 2025

@pknrs Can you provide a reproducer using 4.6.0 version of screens?

@Kartik4152
Copy link

Facing the same issue.

Observations till now:

  • Clicking on it using a cursor works (using scrpy to stream app to mac)
  • onPressOut gets called 200-250ms after onPressIn automatically even if I don't lift off my finger.
  • onPress gets called if I spam the Pressable 20-30 times sometimes, sometimes never gets called at all

@kkafar
Copy link
Member

kkafar commented Feb 4, 2025

In cases you're still experiencing issues, please provide a reproduction code, together with package versions you're using and preferably video of the bug occurring, if feasible. As of now I consider the bug fixed with release of 4.6.0.

@gersomvg
Copy link

gersomvg commented Feb 5, 2025

I've been spending hours on this already :( No idea what is causing this. I've tried to bisect it in every direction, but nothing helps.

edit: as in my case there is no scrollview in the modal, I could add cancelable={false} to the Pressable, which fixed the issue.

@freeboub
Copy link

freeboub commented Feb 5, 2025

I can confirm the issue is still present. It is hard to provide on a sample as (on our project newArch enable, react native 0.77 screens 4.6.0) it is reproduced only in release mode with a real device ...

High5Apps added a commit to High5Apps/organize-rn that referenced this issue Feb 8, 2025
- Perform changes recommended by the Upgrade Helper
  - Didn't update gradle-wrapper.jar since it is a binary file
  - Didn't manually remove all of the RnDiffAppTests/OrganizeTests references. I only kept the ones that were created by removing OrganizeTests.m and OrganizeTests Info.plist
  - Converted AppDelegate.mm to AppDelegate.swift
    - https://github.com/guardianproject/orbot-apple/blob/57dae6f/Orbot/AppDelegate.swift#L29
    - https://github.com/haqq-network/haqq-wallet/blob/c6687e3/ios/AppDelegate.swift#L67-L73
  - https://react-native-community.github.io/upgrade-helper/?from=0.75.3&to=0.77.0&package=app.getorganize.organize&name=Organize
- Update local dev machine node from v23.3.0 to v23.6.1 and npm from 10.9.0 to 10.9.2 to fix a warning that happened when running `npm run` commands
  - npm/cli#7857 (comment)
- Use align-deps to update and align dependencies
- Fix "2 vulnerabilities (1 moderate, 1 high)" with `npm audit fix`
- Update react-native-vision-camera from 4.5.3 to 4.6.3 to fix a build error
  - mrousavy/react-native-vision-camera#3263
- Fixed another react-native-vision-camera Android build error
  - Opened PR: mrousavy/react-native-vision-camera#3394
  - Added devDependency on [email protected] to bring this fix in locally until the PR is merged
    - https://github.com/ds300/patch-package
- Upgraded react-native-modal-datetime-picker from 17.1.0 to 18.0.0 to fix a default props warning
  - mmazzarolo/react-native-modal-datetime-picker#755
  - https://github.com/mmazzarolo/react-native-modal-datetime-picker/releases/tag/v18.0.0
- Fix Android shadows looked bad by migrating from elevation to boxShadow, which was newly added in 77
  - https://reactnative.dev/docs/view-style-props#boxshadow
  - https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow
- Update react-native-pager-view from 6.4.1 to 6.7.0 to fix an android crash when navigating to FlaggedContent, then hitting the back button
  - callstack/react-native-pager-view#944
  - https://github.com/callstack/react-native-pager-view/releases/tag/v6.6.1
- Fix CountdownClockBorder flicker on touch down by migrating from react native's built-in Animated to react-native-reanimated
  - This was caused by react native 77 using the new architecture by default
  - Add dependency on [email protected]
    - https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started/
    - Previously removed in 7b0b38a
- Fix iOS RefreshControl not shown on mount
  - This was caused by react native 77 using the new architecture by default
  - Created PR on react-native: facebook/react-native#49240
  - Used patch-package to bring this in locally until the PR is merged
- Fix failing jest tests by removing jestSetupMockReactNavigation.ts
  - According to the docs, the mock is only needed when using DrawerNavigator or (non-native) StackNavigator
    - https://reactnavigation.org/docs/testing/#mocking-native-modules
- Fix ListEmptyComponent briefly shown even though first page was non-empty
  - This was caused by react native 77 using the new architecture by default
  - This affected useModels, usePrependedModels, and useLeadItems because they used useEffect when they should have used useMemo, causing a render delay between when ready was true and when models were non-empty
    - As a result of the change from useEffect to useMemo in Models, I had to remove the isEqual check. This caused useModel consumers to have more renders than previously, since previously the isEqual check debounced many re-renders, e.g. when fetching data from the backend updated the cache, but didn't affect any of the ids watched by the specific instance of useModels
      - I updated useModelCache, which aleviated some of these unnecessary re-renders, but the scenario mentioned above still causes re-renders
      - The only place these new renders caused real issues was with OrgGraph. The useModelCache change fixed a re-render on pull-to-refresh of the OrgGraph. However, I specifically needed to debounce officers in VisGraphData or else selecting a node would trigger an OrgGraph re-render
- Update react-native-screens from 4.5.0 to 4.6.0 to fix an issue where HeaderButton onPress was ignored on Android devices
  - react-navigation/react-navigation#12274
  - software-mansion/react-native-screens#2219 (comment)
- Add an override to rnx-kit config, since it expected react-native-screens to be 4.5.0 instead of 4.6.0 for react native 77
  - https://microsoft.github.io/rnx-kit/docs/tools/align-deps#presets
  - https://microsoft.github.io/rnx-kit/docs/architecture/dependency-management#extensions
  - https://github.com/microsoft/rnx-kit/tree/main/packages/align-deps#configure
@perttuvirkki
Copy link

perttuvirkki commented Feb 13, 2025

Any update on this? Pretty much stuck with my app updates as this is breaking the buttons. I'm also having issues with Pressables inside ScrollView components.

Edit: Apparently my issues are related to gorhom bottomsheet, without it everything works.

Edit2: Placed all other stuff inside a <View style={{position: 'absolute', top: 0, left: 0, right: 0, bottom: 0}}> { ... } and the bottomsheet outside of this this and pressables work again.

@cyburns
Copy link

cyburns commented Feb 13, 2025

Still an issue for me as well

@kkafar
Copy link
Member

kkafar commented Feb 13, 2025

I can only repeat my previous comment #2219 (comment)

@mwerder
Copy link

mwerder commented Feb 18, 2025

can confirm it is fixed. Updating react-native-screens to 4.7.0 fixed it for me. Thanks

@cyburns
Copy link

cyburns commented Feb 18, 2025

can confirm it is fixed. Updating react-native-screens to 4.7.0 fixed it for me. Thanks

I just upgraded from 4.4.0 to 4.7.0 and am having the same issue. In fact it seems to be an issue on IOS now as well.

@kkafar
Copy link
Member

kkafar commented Feb 19, 2025

I can only repeat my previous comment #2219 (comment)

@cyburns
Copy link

cyburns commented Feb 19, 2025

Pressabbles not working within header

Sure, @kkafar , here is a minimum reproduction of where the issue is coming from. I'd also like to note that after upgrading from react-native-screen 4.4.0 to 4.7.0 the buttons changing widths is an issue. If the button gets wider it gets cut off.

Swapping onPress with onPressIn seemed to sometimes fix the issue in 4.4.0. After upgrading to 4.7.0 the issue seems to be on IOS (simulator) now as well where it was only on physical Android devices before.

Dependencies

    "react": "18.3.1",
    "react-native": "0.76.5",
    "react-native-gesture-handler": "~2.20.2",
    "react-native-pager-view": "6.5.1",
    "react-native-reanimated": "~3.16.1",
    "react-native-screens": "^4.7.0",
    "react-native-tab-view": "^3.5.2",

Minimum example

import { useNavigation } from 'expo-router';

const ParentComponent = () => {
  const [isEdit, setIsEdit] = useState(false);

  const nav = useNavigation();

  useLayoutEffect(() => {
    nav.setOptions({
      title: 'Device Details',
      headerLeft: () => (
        <CancelOrBackHeaderLeft isEdit={isEdit} handleEdit={handleEdit} />
      ),
      headerRight: () => (
        <EditHeaderRight
          isEdit={isEdit}
          hasEditPrivileges={hasEditPrivileges}
          isEditLoading={isEditLoading}
          handleEdit={handleEdit}
          handleSaveEdits={handleSaveEdits}
          disabled={
            !newDeviceName || !validateTags() || isEditLoading || loading
          }
        />
      ),
    });
  }, [
    nav,
    isEdit,
    isEditLoading,
    hasEditPrivileges,
    handleEdit,
    handleSaveEdits,
    newDeviceName,
    validateTags,
    loading,
  ]);

  return <></>;
};

const CancelOrBackHeaderLeft = ({
  isEdit,
  handleEdit,
}: DeviceDetailsHeaderProps) => {
  return (
    <View style={[a.flex_shrink]}>
      {!isEdit ? (
        <ScreenBack />
      ) : (
        <TouchableOpacity onPress={handleEdit} style={{ minWidth: 100 }}>
          <Text style={styles.headerCancel}>{t('general.cancel')}</Text>
        </TouchableOpacity>
      )}
    </View>
  );
};

const EditHeaderRight = ({
  isEdit,
  hasEditPrivileges,
  isEditLoading,
  handleEdit,
  handleSaveEdits,
  disabled,
}: DeviceDetailsHeaderProps) => {
  return (
    <View style={[a.flex_shrink]}>
      {hasEditPrivileges && (
        <Fragment>
          {!isEdit ? (
            <TouchableOpacity onPress={handleEdit}>
              <Ionicons
                name="create-outline"
                size={24}
                color={isEdit ? Colors.lightGray : Colors.black}
              />
            </TouchableOpacity>
          ) : (
            <TouchableOpacity
              style={{
                backgroundColor: disabled ? Colors.darkGray : Colors.black,
                borderRadius: 99,
                paddingVertical: 4,
                paddingHorizontal: 14,
                minWidth: 100,
              }}
              onPress={handleSaveEdits}
              disabled={disabled}
            >
              {isEditLoading ? (
                <LoadingDots color={Colors.white} />
              ) : (
                <Text style={[a.btnText, { color: Colors.white }]}>
                  {t('general.save')}
                </Text>
              )}
            </TouchableOpacity>
          )}
        </Fragment>
      )}
    </View>
  );
};

@kkafar
Copy link
Member

kkafar commented Feb 19, 2025

Thanks for the repro! I'll get back to you once I investigate it

@yeliu84
Copy link

yeliu84 commented Feb 27, 2025

Thanks for the repro! I'll get back to you once I investigate it

I'm facing the same issue as @cyburns, any updates?

@damiensedgwick
Copy link

damiensedgwick commented Feb 28, 2025

All of the internal testers on android have reported header buttons not working at all despite being fine on emulators.

Upgrading to 4.7.0 for screens did not help me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NewArch Issues related only to new architecture Platform: Android This issue is specific to Android Repro provided A reproduction with a snack or repo is provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.