Skip to content

fix: android pressability issue with measureAsyncOnUI patch#86160

Draft
MelvinBot wants to merge 3 commits intomainfrom
claude-fixPressabilityNewArch-v3
Draft

fix: android pressability issue with measureAsyncOnUI patch#86160
MelvinBot wants to merge 3 commits intomainfrom
claude-fixPressabilityNewArch-v3

Conversation

@MelvinBot
Copy link
Contributor

Explanation of Change

Note: This PR is a recreation of #85745 on top of current main. The original branch had no common ancestor with main, making it impossible to merge. All changes are identical.

This PR adds a react-native patch based on the upstream PR facebook/react-native#51835 to fix an Android-specific issue where onPress events do not trigger for Pressable components when used inside a Tooltip on certain Samsung devices.

Root Cause: In the new architecture, Pressability.measure() reads layout information from the shadow tree. When a tooltip uses a Reanimated animation (e.g., scale: 0 during entry), the shadow tree retains the stale value while the UI thread has already updated. This causes Pressability to incorrectly compute the pressable region as having zero size, making the button untappable.

Fix: Introduces a new measureAsyncOnUI method that measures views using the native view hierarchy on the UI thread instead of the shadow tree. This ensures correct measurements even when Reanimated has modified the view's transform on the native side.

The patch modifies:

  • JS: Pressability.js to call measureAsyncOnUI instead of measure; adds measureAsyncOnUI to FabricUIManager, ReactFabricHostComponent, ReactNativeElement, and type definitions
  • C++ (shared): Adds measureAsyncOnUI binding in UIManagerBinding.cpp, with delegation through UIManagerDelegateSchedulerSchedulerDelegate
  • iOS: Implements async measurement in RCTMountingManager using RCTExecuteOnMainQueue with native view hierarchy measurement
  • Android: Implements async measurement through FabricUIManagerMountingManager using MountItem dispatch to UI thread, with native view hierarchy measurement via bounding box computation

Also removes the createPressHandler workaround (which used onPressIn instead of onPress on Android) since this patch properly fixes the root cause.

Fixed Issues

$ #59953

Tests

  1. Open the app on an Android device (ideally a Samsung Galaxy Z Fold 4 or similar affected device)
  2. Sign in to a new account or one that triggers product training tooltips
  3. When a tooltip appears (e.g., near the Concierge chat), tap the X button to dismiss it
  4. Verify the tooltip dismisses on tap (onPress fires correctly)
  5. If action button tooltips appear, verify "Try it out" and "No thanks" buttons work
  • Verify that no errors appear in the JS console

Offline tests

Same as tests - tooltip dismissal is a local UI interaction and should work identically offline.

QA Steps

  1. On an Android device (preferably Samsung Galaxy Z Fold 4 / Android 14), sign in to an account
  2. Trigger a product training tooltip (new account or cleared tooltip state)
  3. Verify the X button on the tooltip is tappable and dismisses the tooltip
  4. Verify other Pressable components inside tooltips work correctly
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native

This bug requires a specific Samsung device (e.g., Galaxy Z Fold 4) to reproduce. The patch is based on the upstream react-native fix.

Android: mWeb Chrome

N/A - This is a native-only issue (Fabric/new arch)

iOS: Native

N/A - This is an Android-specific issue

iOS: mWeb Safari

N/A - This is an Android-specific issue

MacOS: Chrome / Safari

N/A - This is an Android-specific issue

Add react-native patch based on upstream PR facebook/react-native#51835
to fix Android-specific issue where onPress events do not trigger for
Pressable components when used inside a Tooltip on certain Samsung devices.

Also removes the createPressHandler workaround since this patch properly
fixes the root cause.

Co-authored-by: Linh Vo <linhvovan29546@users.noreply.github.com>
@MelvinBot MelvinBot requested a review from a team March 24, 2026 02:43
@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/components/ProductTrainingContext/index.tsx 91.22% <0.00%> (ø)
... and 35 files with indirect coverage changes

@linhvovan29546
Copy link
Contributor

@MelvinBot We're seeing the error _NativeDOM.default.measureAsyncOnUI is not a function on iOS.

@MelvinBot
Copy link
Contributor Author

🔍 Analysis: _NativeDOM.default.measureAsyncOnUI is not a function on iOS

Root Cause: The patch is missing a critical file — FBReactNativeSpecJSI.h, the pre-generated C++ codegen header that registers TurboModule methods on iOS.

Why it works on Android but not iOS

On iOS, React Native deliberately skips codegen for FBReactNativeSpec when pre-generated files already exist in node_modules (shouldSkipGenerationForFBReactNativeSpec):

function shouldSkipGenerationForFBReactNativeSpec(schemaInfo, platform) {
  if (platform !== 'ios' || ...) return false;
  // If the pre-generated files exist in node_modules → SKIP codegen
  return (path.includes('node_modules') && fs.existsSync(...) && fs.readdirSync(...).length > 0);
}

This means the pre-generated FBReactNativeSpecJSI.h (shipped in the npm package) is used as-is on iOS, even though the JS spec (NativeDOM.js) was patched to include measureAsyncOnUI.

On Android, codegen always re-runs from the patched JS specs at Gradle build time, so measureAsyncOnUI gets properly registered.

Error chain

  1. Pressability.js checks typeof this._responderID.measureAsyncOnUI === 'function'TRUE (it's a JS class method on ReactNativeElement, added by the patch)
  2. ReactNativeElement.measureAsyncOnUI() calls NativeDOM.measureAsyncOnUI(node, callback)no guard on the native method
  3. The iOS TurboModule looks up measureAsyncOnUI in its methodMap_NOT FOUND (because FBReactNativeSpecJSI.h was not patched and still has only the original 21 methods)
  4. Returns undefined → calling undefined() throws: _NativeDOM.default.measureAsyncOnUI is not a function

Fix

The patch needs to also modify FBReactNativeSpecJSI.h to add:

  1. A measureAsyncOnUI entry in the NativeDOMCxxSpec constructor's methodMap_ (around line 5791-5813)
  2. A corresponding static __hostFunction_NativeDOMCxxSpec_measureAsyncOnUI invoker function that bridges JS to the C++ measureAsyncOnUI implementation using AsyncCallback

Alternatively, as a simpler defensive fix, add a guard in ReactNativeElement.measureAsyncOnUI to fall back to measure() when the native method doesn't exist:

measureAsyncOnUI(callback: MeasureOnSuccessCallback) {
  const node = getNativeElementReference(this);
  if (node != null) {
    if (typeof NativeDOM.measureAsyncOnUI === 'function') {
      NativeDOM.measureAsyncOnUI(node, callback);
    } else {
      NativeDOM.measure(node, callback);
    }
  }
}

However, the proper fix is patching FBReactNativeSpecJSI.h so the native method is actually registered.

Key files
  • FBReactNativeSpecJSI.h:5791-5813 — Pre-generated NativeDOMCxxSpec constructor with methodMap_ (missing measureAsyncOnUI)
  • scripts/codegen/generate-artifacts-executor/generateNativeCode.js:80-101shouldSkipGenerationForFBReactNativeSpec skip logic
  • ReactNativeElement.js (patched) — Calls NativeDOM.measureAsyncOnUI without checking existence
  • TurboModule.h:117-137 — Returns undefined for methods not in methodMap_

@linhvovan29546
Copy link
Contributor

@MelvinBot please apply the fix

… methodMap_

On iOS, codegen for FBReactNativeSpec is skipped when pre-generated files
exist in node_modules. The original patch modified NativeDOM.js and the C++
implementation but did not update the pre-generated FBReactNativeSpecJSI.h,
causing measureAsyncOnUI to be undefined at runtime on iOS.

This commit:
1. Patches FBReactNativeSpecJSI.h to add measureAsyncOnUI to the
   NativeDOMCxxSpec methodMap_ and adds the static invoker function
2. Adds a defensive typeof guard in ReactNativeElement.measureAsyncOnUI
   to fall back to regular measure() if the native method is unavailable

Co-authored-by: Linh Vo <linhvovan29546@users.noreply.github.com>
@MelvinBot
Copy link
Contributor Author

Fixed the iOS _NativeDOM.default.measureAsyncOnUI is not a function error in db16d63.

Changes:

  1. Patched FBReactNativeSpecJSI.h — Added measureAsyncOnUI to the NativeDOMCxxSpec constructor's methodMap_ and added the corresponding __measureAsyncOnUI static invoker function. This is the critical fix: on iOS, codegen is skipped for FBReactNativeSpec when pre-generated files exist in node_modules, so the original patch's changes to NativeDOM.js (the Flow spec) were never picked up. The pre-generated header needed to be patched directly.

  2. Added defensive guard in ReactNativeElement.measureAsyncOnUI — Now checks typeof NativeDOM.measureAsyncOnUI === 'function' before calling it, falling back to NativeDOM.measure() if unavailable. This provides a safety net in case the native method isn't registered for any reason.

Please rebuild the iOS app and verify the error is resolved.

@linhvovan29546
Copy link
Contributor

@MelvinBot The workflows failing

The second hunk of the FBReactNativeSpecJSI.h section had a line count
mismatch in its @@ header (declared 6 old/15 new but only contained
5 old/14 new lines), causing patch-package to fail with a parse error
during npm postinstall.

Co-authored-by: Linh Vo <linhvovan29546@users.noreply.github.com>
@MelvinBot
Copy link
Contributor Author

Fixed the failing checks: the react-native+0.83.1+034+fix-pressability-new-arch.patch file had a hunk header line count mismatch in the FBReactNativeSpecJSI.h section. The second hunk's @@ header declared 6 old/15 new lines but only contained 5 old/14 new lines, causing patch-package to fail with a parse error during npm postinstall. Corrected the header to @@ -5984,5 +5985,14 @@. This was the root cause of all CI failures (ESLint, Prettier, typecheck, tests, builds, etc.) since they all depend on npm install succeeding.

@MelvinBot
Copy link
Contributor Author

I checked the workflow status. The only failing check is PR Author Checklist / checklist, which is expected and not a real failure — it's an informational check.

All other checks (ESLint, typecheck, tests, builds, etc.) are still pending — they're currently running. There are no actual failures to fix yet.

If any checks fail after they complete, feel free to tag me again and I'll investigate.

@MelvinBot
Copy link
Contributor Author

The previous check failures (TypeScript, ESLint, unused styles) were all caused by the same issue: the patch file react-native+0.83.1+034+fix-pressability-new-arch.patch could not be parsed by patch-package during npm install.

This was already fixed in commit 03df1b7 ("Fix: correct hunk line count in react-native pressability patch"). The latest CI run shows all checks are now passing — ESLint, Changed files ESLint, unused styles, Prettier, validate-patches, and builds are all green. Tests and typecheck are still running but should pass since the underlying patch parsing issue is resolved.

The only failing check is checklist (PR Author Checklist), which is unrelated to the code.

@github-actions
Copy link
Contributor

🚧 @MonilBhavsar has triggered a test Expensify/App build. You can view the workflow run here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants