Skip to content

Block tab navigation while photo capture is in progress #83949

Closed

Description

@marcaaron

Problem

When the scan receipt camera is open and a user taps the shutter button, then immediately taps the Manual tab, the app navigates away from the scan view while the photo capture is still in progress. This can lead to unexpected behavior since the capture flow is interrupted mid-flight.

Solution

Disable tab navigation (Scan/Manual/Distance) while a photo capture is in progress. Once the capture completes (or fails), re-enable tab switching.

  • Determine how to signal from the scan component to the OnyxTabNavigator/TabSelector that tab switching should be blocked
  • One approach: store a capture-in-progress flag in Onyx that the TabSelector reads to ignore taps
  • Another approach: add a disabled prop to OnyxTabNavigator or TabSelector
  • Unblock navigation once capture resolves or errors

Activity

  1. melvin-bot commented on Mar 2, 2026

    @melvin-bot

    Triggered auto assignment to @stephanieelliott (NewFeature), see https://stackoverflowteams.com/c/expensify/questions/14418#:~:text=BugZero%20process%20steps%20for%20feature%20requests for more details. Please add this Feature request to a GH project, as outlined in the SO. Remember to draft any necessary HelpDot updates by following the instructions here.

  2. melvin-bot commented on Mar 2, 2026

    @melvin-bot

    Triggered auto assignment to Design team member for new feature review - @dubielzyk-expensify (NewFeature)

  3. MelvinBot commented on Mar 2, 2026

    @MelvinBot
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When the scan receipt camera is open and a user taps the shutter button, then immediately taps the Manual tab, the app navigates away from the scan view while the photo capture is still in progress. This causes unexpected behavior because initMoneyRequest() resets the transaction draft while the async camera capture is still in flight, and when the capture completes, it tries to set receipt data on a reset transaction and may trigger navigation to the confirmation step even though the user has already switched tabs.

    What is the root cause of that problem?

    Tab switching in IOURequestStartPage is completely unguarded — there is no check for whether a photo capture is in progress before allowing the tab to change.

    The race condition works as follows:

    1. User taps the shutter button → capturePhoto() in index.native.tsx:302 sets didCapturePhoto = true (line 343) and calls camera.current.takePhoto() which returns a Promise (line 362-367)
    2. Before the Promise resolves, user taps the Manual tab
    3. TabSelector.handleTabPress() in TabSelector.tsx:37-58 dispatches TabActions.jumpTo() with no guard
    4. OnyxTabNavigator's state listener fires → onTabSelected() → resetIOUTypeIfChanged() → initMoneyRequest() in IOURequestStartPage.tsx:178-226
    5. initMoneyRequest() calls removeDraftTransactions() and resets the transaction draft via Onyx.set() in IOU/index.ts:1242,1333
    6. Eventually, takePhoto() resolves and tries to set receipt data on the now-reset transaction, and submitReceipts() triggers navigation to the confirmation step

    The didCapturePhoto state at index.native.tsx:91 is entirely local to IOURequestStepScan — it is never communicated to the parent IOURequestStartPage that controls tab switching. It is only used to prevent double-tapping the shutter and to disable the multi-scan submit button in ReceiptPreviews.

    The web version (index.tsx) has no didCapturePhoto state at all, though the synchronous getScreenshot() call makes the window for this race smaller on web.

    What changes do you think we should make in order to solve the problem?

    Use the existing screenListeners + canPreventDefault pattern that React Navigation and TabSelector already support:

    1. Lift the capture-in-progress state from IOURequestStepScan up to IOURequestStartPage. Pass a setIsCapturingPhoto callback down to IOURequestStepScan (similar to the existing setIsMultiScanEnabled pattern). Set it to true when capture begins and false when capture completes or fails.

    2. Add a screenListeners prop to the OnyxTabNavigator in IOURequestStartPage with a tabPress event listener that calls e.preventDefault() when isCapturingPhoto is true. TabSelector.handleTabPress() already emits tabPress events with canPreventDefault: true (line 48-52) and only dispatches TabActions.jumpTo() if !event.defaultPrevented (line 54-55), so this will block the tab switch cleanly.

    3. Add equivalent state tracking for web in index.tsx — wrap the async cropImageToAspectRatio call with a capture-in-progress flag.

    This approach requires no changes to OnyxTabNavigator, TabSelector, or the navigation infrastructure — it only uses existing, supported patterns.

    What alternative solutions did you explore? (Optional)

    • Storing a flag in Onyx: The issue description suggests storing a capture-in-progress flag in Onyx. This would work but is heavier than needed — the state is transient and only relevant to a single screen, so React state is more appropriate than persisted Onyx state.
    • Adding a disabled prop to TabSelectorItem: This would visually grey out the tabs, but TabSelector already has the canPreventDefault pattern built in, which is cleaner and doesn't require UI changes to the tab bar component.
    • Aborting the capture callback instead of blocking tabs: Rather than blocking the tab switch, we could check if the scan tab is still focused when the capture completes and bail out. This is more fragile and doesn't prevent the transaction reset from happening.

    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.

  4. dubielzyk-expensify commented on Mar 3, 2026

    @dubielzyk-expensify
    Contributor

    Let me know if you need a mock or anything here, but I think simply disabling the tabs works 👍

  5. melvin-bot commented on Mar 6, 2026

    @melvin-bot

    @stephanieelliott, @dubielzyk-expensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  6. dubielzyk-expensify commented on Mar 9, 2026

    @dubielzyk-expensify
    Contributor

    Not overdue

  7. 16 remaining items

  8. dubielzyk-expensify commented on Apr 1, 2026

    @dubielzyk-expensify
    Contributor

    Any updates here @marcaaron ?

  9. melvin-bot commented on Apr 7, 2026

    @melvin-bot

    @stephanieelliott, @dubielzyk-expensify Huh... This is 4 days overdue. Who can take care of this?

  10. dubielzyk-expensify commented on Apr 9, 2026

    @dubielzyk-expensify
    Contributor

    Any updates here?

  11. dubielzyk-expensify commented on Apr 14, 2026

    @dubielzyk-expensify
    Contributor

    Any updates? Been a few weeks without any updates now. Also looks like the PR for this merged anyways!?

  12. dubielzyk-expensify commented on Apr 17, 2026

    @dubielzyk-expensify
    Contributor
  13. stephanieelliott commented on Apr 17, 2026

    @stephanieelliott
    Contributor

    Ha sorry @dubielzyk-expensify, I wasn't keeping eyes on this because I assumed Melvin was just rolling with it. Looks like the PR was merged so I think this one is done

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

Metadata

Metadata

Labels

DailyKSv2Melvin TriageAutomatic AI Analysis of an issueNewFeatureSomething to build that is a new item.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions