Skip to content

fix: use in-app VisionCamera for chat attachments on Android and iOS#84770

Open
MelvinBot wants to merge 35 commits intomainfrom
claude-useVisionCameraForAttachments
Open

fix: use in-app VisionCamera for chat attachments on Android and iOS#84770
MelvinBot wants to merge 35 commits intomainfrom
claude-useVisionCameraForAttachments

Conversation

@MelvinBot
Copy link
Contributor

@MelvinBot MelvinBot commented Mar 10, 2026

Explanation of Change

Slack thread for context: https://expensify.slack.com/archives/C05LX9D6E07/p1772818699627849

On Android, tapping "Take photo" in the chat attachment picker launches the system camera via an external intent, which backgrounds the Expensify app. When the OS is under memory pressure, it can reclaim Expensify's process while the system camera is active — particularly during post-capture processing when memory usage spikes. This causes a crash when the user returns from the camera.

This PR replaces the external camera intent with an in-app camera modal powered by react-native-vision-camera (VisionCamera), which is already used in the receipt scan flow (IOURequestStepScan). By keeping Expensify in the foreground during photo capture, we eliminate the window in which the OS can reclaim the app's memory. The in-app camera is used on both Android and iOS for a consistent experience.

Changes:

  • New AttachmentCamera component (AttachmentCamera.tsx): A full-screen modal with VisionCamera viewfinder, shutter button, flash toggle, and back button. Handles camera permissions using the same CameraPermission module already used by receipt scan.
  • Modified AttachmentPicker/index.native.tsx: The "Take photo" menu item now opens the in-app camera modal instead of launching the external system camera on both Android and iOS. The captured photo flows through the same pickAttachment processing pipeline (resize, validation, upload) as before.

Fixed Issues

$ #84018

Tests

  1. Open the Expensify app on an Android device
  2. Navigate to any chat
  3. Tap the + button, then "Add attachment" → "Take photo"
  4. Verify an in-app camera opens (full screen with viewfinder, shutter button, flash toggle, and back arrow)
  5. Take a photo by tapping the shutter button
  6. Verify the photo is attached to the chat and can be sent successfully
  7. Repeat and close the camera using the back arrow without taking a photo
  8. Verify the attachment flow is properly cancelled (no photo attached)
  9. On an iOS device, repeat steps 2-8 and verify the same in-app camera behavior
  • Verify that no errors appear in the JS console

Offline tests

  1. Put the device in airplane mode
  2. Open any chat, tap + → "Add attachment" → "Take photo"
  3. Verify the in-app camera opens and a photo can be captured
  4. Verify the photo is queued for upload (optimistic update) and sends once connectivity returns

QA Steps

  1. On an Android device, open any chat
  2. Tap + → "Add attachment" → "Take photo"
  3. Verify the in-app camera appears with viewfinder, shutter button, flash toggle, and back button
  4. Take a photo and verify it attaches to the chat correctly
  5. Try toggling flash on/off and verify it works
  6. Close the camera without taking a photo and verify the flow cancels cleanly
  7. On an iOS device, repeat steps 2-6 and verify the same in-app camera behavior
  8. Verify no errors appear in the JS console throughout
  • 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
    • MacOS: Desktop
  • 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 verified there are no new alerts related to the canBeMissing param for useOnyx
  • 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 new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • 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.
  • I verified that similar component doesn't exist in the codebase
  • I verified that all props are defined accurately and each prop has a /** comment above it */
  • I verified that each file is named correctly
  • I verified that each component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
  • I verified that the only data being stored in component state is data necessary for rendering and nothing else
  • In component if we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
  • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
  • I verified that component internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
  • I verified that all JSX used for rendering exists in the render method
  • I verified that each component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

On Android, tapping "Take photo" in the attachment picker launches
the system camera intent, which backgrounds Expensify. The OS can
reclaim the app's memory during post-capture processing, causing a
crash when returning from the camera.

Replace the external camera intent with an in-app VisionCamera modal
on Android. This keeps Expensify in the foreground during photo
capture, eliminating the memory reclaim window. The change only
affects Android; iOS continues to use the existing external camera.

Fixed Issues: #84018

Co-authored-by: Shridhar Goel <ShridharGoel@users.noreply.github.com>
Co-authored-by: Shridhar Goel <ShridharGoel@users.noreply.github.com>
@MelvinBot
Copy link
Contributor Author

Fixed the failing Changed files ESLint check: added missing sentryLabel props to the three PressableWithFeedback components in AttachmentCamera.tsx (close button, flash toggle, and shutter button).

@MelvinBot
Copy link
Contributor Author

Fixed the failing check: the Changed files ESLint check was failing because three PressableWithFeedback components in AttachmentCamera.tsx were missing the required sentryLabel prop. This was addressed in commit 7d7adb1, and the ESLint check is now passing. The only remaining failing check is checklist (PR Author Checklist), which is unrelated to code.

The AttachmentCamera component imports react-native-vision-camera which
tries to initialize native modules that don't exist in the Jest test
environment. This causes all test suites to fail with
"system/camera-module-not-found" error. Add a mock similar to other
native module mocks in the jest setup file.

Co-authored-by: Shridhar Goel <ShridharGoel@users.noreply.github.com>
@MelvinBot
Copy link
Contributor Author

Fixed the failing checks: Added a Jest mock for react-native-vision-camera in jest/setup.ts.

Root cause: The new AttachmentCamera.tsx component imports react-native-vision-camera which attempts to initialize the native Camera module (NativeModules.CameraView) at import time. In the Jest test environment, this native module doesn't exist, causing a system/camera-module-not-found error. Because AttachmentCamera is imported through AttachmentPicker/index.native.tsxReceiptEmptyState.tsx → many other components, this cascaded and caused 42+ test suites to fail.

Fix: Added a mock for react-native-vision-camera in jest/setup.ts, following the same pattern used for other native modules like react-native-reanimated, react-native-keyboard-controller, etc.

@codecov
Copy link

codecov bot commented Mar 10, 2026

Codecov Report

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

Files with missing lines Coverage Δ
src/CONST/index.ts 95.20% <ø> (ø)
...rc/components/Icon/chunks/expensify-icons.chunk.ts 0.00% <ø> (ø)
...nts/Search/SearchPageHeader/useSearchPageInput.tsx 0.00% <0.00%> (ø)
src/components/AttachmentPicker/index.native.tsx 21.55% <28.57%> (+0.79%) ⬆️
...c/components/AttachmentPicker/AttachmentCamera.tsx 2.50% <2.50%> (ø)
... and 8 files with indirect coverage changes

@ShridharGoel
Copy link
Contributor

@MelvinBot Let's do it for both Android and iOS

Remove the Platform.OS === 'android' gate so the in-app camera is used
on iOS as well, instead of falling back to the external system camera.

Co-authored-by: Shridhar Goel <ShridharGoel@users.noreply.github.com>
@MelvinBot
Copy link
Contributor Author

Done — the in-app VisionCamera is now used on both Android and iOS. The Platform.OS === 'android' gate has been removed so both platforms use the same AttachmentCamera modal instead of falling back to the external system camera on iOS.

Changes in commit e32e587:

  • Removed the Platform import and platform check in index.native.tsx
  • The "Take photo" menu item now always uses launchInAppCamera on both platforms
  • Removed the unused launchCamera import
  • Updated comments to reflect the cross-platform behavior

@mountiny
Copy link
Contributor

How is it looking?

@ShridharGoel
Copy link
Contributor

It seemed good when I tested earlier, will have a thorough look at the code and test again.

@ShridharGoel
Copy link
Contributor

@MelvinBot Mark this as ready for review

@MelvinBot MelvinBot changed the title fix: use in-app VisionCamera for Android chat attachments fix: use in-app VisionCamera for chat attachments on Android and iOS Mar 12, 2026
@MelvinBot
Copy link
Contributor Author

PR has been marked as ready for review. I also updated the title to reflect that the in-app VisionCamera now covers both Android and iOS.

@ShridharGoel
Copy link
Contributor

@MelvinBot Mark this as ready for review

@MelvinBot MelvinBot marked this pull request as ready for review March 13, 2026 09:08
@MelvinBot MelvinBot requested a review from a team as a code owner March 13, 2026 09:08
@melvin-bot melvin-bot bot requested review from ShridharGoel and joekaufmanexpensify and removed request for a team March 13, 2026 09:08
@melvin-bot
Copy link

melvin-bot bot commented Mar 13, 2026

@ShridharGoel Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot removed the request for review from a team March 13, 2026 09:08
@MelvinBot
Copy link
Contributor Author

Marked this PR as ready for review. I also updated the PR description and test steps to reflect that the in-app VisionCamera is now used on both Android and iOS (previously the description mentioned iOS behavior was unchanged).

@ShridharGoel
Copy link
Contributor

@MelvinBot Is it possible to add a camera switcher option, so that the front camera can also be used?

Replace the empty spacer in the bottom control bar with a camera flip
button using the Rotate icon. Adds cameraPosition state to toggle
between 'back' and 'front' devices via useCameraDevice. Flash visibility
automatically adapts since front cameras typically lack a flash (already
handled by the hasFlash check).

Co-authored-by: Shridhar Goel <ShridharGoel@users.noreply.github.com>
@MelvinBot MelvinBot requested a review from a team as a code owner March 13, 2026 17:14
@MelvinBot
Copy link
Contributor Author

The failing build checks are unrelated to this PR's code changes and appear to be CI infrastructure issues.

Analysis:

  1. build (developmentDebug, false) (Android) — Failed in ~1 minute with:

    Could not read script 'node_modules/expo/scripts/autolinking.gradle' as it does not exist.

    This is a node_modules installation issue in the CI environment. Notably, the other Android build variant build (Debug, true) passed (18m18s), confirming the code itself builds fine.

  2. build (Expensify Dev, Debug, true) (iOS) — The "Rock Remote Build - iOS" step never completed properly — the job was marked failed after ~17 minutes but the step shows no conclusion. This appears to be a Rock build service infrastructure issue.

  3. checklist — Unrelated to code (PR author checklist validation).

Evidence this is not caused by PR changes:

  • The PR only modifies TS/TSX files, SVG assets, and translation files — no changes to package.json, android/ gradle files, or native build configuration.
  • One Android build variant passed while the other failed, indicating an environment flake, not a code issue.

Recommendation: Re-run the failed workflows. If the failures persist, they should be investigated as a CI infrastructure issue separate from this PR.

@MelvinBot
Copy link
Contributor Author

The failing build checks are unrelated to this PR's changes.

Failing checks:

  1. build (developmentDebug, false) — Android build fails with: Could not read script 'node_modules/expo/scripts/autolinking.gradle' as it does not exist
  2. build (New Expensify Dev, DebugDevelopment, false) — iOS build timed out during Airship pod compilation
  3. build (Expensify Dev, Debug, true) — iOS build timed out (Rock Remote Build step never completed)

Evidence this is unrelated:

  • This PR only modifies .tsx, .ts, .svg, and language files — no native build configuration (no Podfile, build.gradle, or settings.gradle changes)
  • The exact same Android build failure (autolinking.gradle not found) is also happening on main (run 23336764534)
  • The iOS builds appear to be timing out during pod compilation (Airship), which is a CI infrastructure issue

These are pre-existing CI/infrastructure failures, not caused by changes in this PR.

@srikarparsi
Copy link
Contributor

@ShridharGoel can you please merge main again to see if that fixes this

@ShridharGoel
Copy link
Contributor

@MelvinBot Merge main

@ShridharGoel
Copy link
Contributor

@MelvinBot Merge main into this branch

…aForAttachments

Co-authored-by: Shridhar Goel <ShridharGoel@users.noreply.github.com>
@MelvinBot
Copy link
Contributor Author

Merged latest main into this branch. The merge resolved cleanly.

@ShridharGoel
Copy link
Contributor

@srikarparsi Can you help in removing the extra text at the end of the author checklist? It keeps getting added back.

@srikarparsi
Copy link
Contributor

Yes removed, is this ready for review apart from this?

@srikarparsi
Copy link
Contributor

I can take care of the checklist failing

@ShridharGoel
Copy link
Contributor

Yes it's ready

@MelvinBot
Copy link
Contributor Author

All checks on this PR are currently passing — no failing checks found. If you're seeing failures that haven't shown up yet, please re-run the checks and tag me again if needed.

@MelvinBot
Copy link
Contributor Author

All checks on this PR are currently passing — no failing checks detected. If you're seeing a specific failure, it may have been resolved by a recent push or could be a transient/flaky issue. Please re-run the checks if needed and let me know if the problem recurs.

@srikarparsi
Copy link
Contributor

@ShridharGoel can you please test and add screenshots

const device = useCameraDevice(cameraPosition, {
physicalDevices: ['wide-angle-camera', 'ultra-wide-angle-camera'],
});
const format = useCameraFormat(device, [{photoAspectRatio: 4 / 3}, {photoResolution: 'max'}]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a constant for this ratio?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot Let's use a constant for this ratio

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — extracted 4 / 3 to CONST.RECEIPT.PHOTO_ASPECT_RATIO and updated the usage.

* Returns a Promise that resolves with the captured photo as an Asset-compatible object,
* or resolves with void if the user closes the camera without capturing.
*/
const launchInAppCamera = useCallback((): Promise<Asset[] | void> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need useCallback for these and the below? I think react will handle them automatically?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, @MelvinBot what do you think? Update accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — all three (launchInAppCamera, handleCameraCapture, handleCameraClose) had empty dependency arrays, so useCallback wasn't adding value here. Removed the wrappers from all three.

@ShridharGoel
Copy link
Contributor

ShridharGoel commented Mar 24, 2026

can you please test and add screenshots

@srikarparsi They are present in the description and the reviewer checklist respectively.

MelvinBot and others added 5 commits March 24, 2026 21:24
Co-authored-by: Shridhar Goel <ShridharGoel@users.noreply.github.com>
…pture, handleCameraClose

Co-authored-by: Shridhar Goel <ShridharGoel@users.noreply.github.com>
…aForAttachments

Co-authored-by: Shridhar Goel <ShridharGoel@users.noreply.github.com>
Co-authored-by: Shridhar Goel <ShridharGoel@users.noreply.github.com>
…ents' into claude-useVisionCameraForAttachments

Co-authored-by: Shridhar Goel <ShridharGoel@users.noreply.github.com>
@MelvinBot
Copy link
Contributor Author

Fixed the failing typecheck: merged main and removed the stale personalDetails argument from the navigateToAndOpenReport call in useSearchPageInput.tsx. The function signature on main no longer accepts personalDetails as a parameter, but the newly added useSearchPageInput.tsx file was still passing it (7 args instead of the expected 5-6).

@ShridharGoel
Copy link
Contributor

@MelvinBot revert the unrelated changes

@MelvinBot
Copy link
Contributor Author

The TypeScript check failure was caused by a stale personalDetails argument in the navigateToAndOpenReport call in useSearchPageInput.tsx after merging main (which had already removed that parameter from the function signature). This was already fixed in commit 198b176 and the typecheck is now passing. All checks are green.

@MelvinBot
Copy link
Contributor Author

The useSearchPageInput.tsx change is no longer in the PR diff — the latest merge of main absorbed it. The PR now only contains files related to the VisionCamera feature:

  • assets/images/camera-flip.svg
  • jest/setup.ts
  • src/CONST/index.ts
  • src/components/AttachmentPicker/AttachmentCamera.tsx
  • src/components/AttachmentPicker/index.native.tsx
  • src/components/Icon/chunks/expensify-icons.chunk.ts
  • Language translation files (de, en, es, fr, it, ja, nl, pl, pt-BR, zh-hans)

No unrelated changes remain.

Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(item?.reportID));
} else if ('login' in item) {
navigateToAndOpenReport(item.login ? [item.login] : [], personalDetails, currentUserAccountID, introSelected, isSelfTourViewed, betas, false);
navigateToAndOpenReport(item.login ? [item.login] : [], currentUserAccountID, introSelected, isSelfTourViewed, betas, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot revert this

…rAttachments' into claude-useVisionCameraForAttachments"

This reverts commit 0223e2e, reversing
changes made to d7e6e16.
@MelvinBot
Copy link
Contributor Author

Reverted the merge of main. The branch is now back to the PR-only changes (without main merged in).

Note: commit 198b176 ("Merge main and fix navigateToAndOpenReport call in useSearchPageInput") was also part of the main-merge line and has been reverted. If that fix is still needed, it will need to be re-applied separately.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants