Skip to content

Fix: Present iOS pickers from the topmost view controller - #15

Merged
simonhamp merged 2 commits into
NativePHP:mainfrom
sonalidudhia:fix/issue-11-ios-present-top-vc
Oct 22, 2026
Merged

simonhamp merged 2 commits into
NativePHP:mainfrom
sonalidudhia:fix/issue-11-ios-present-top-vc

Conversation

@sonalidudhia

@sonalidudhia sonalidudhia commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11

On iOS, Camera::getPhoto(), Camera::recordVideo() and Camera::pickImages() presented on the key window's rootViewController. While any modal is on screen (e.g. a <native:bottom-sheet>, which renders as a SwiftUI .sheet) that controller is already presenting, so UIKit silently drops the present() call: no picker, no event, no log.

Changes

  • Adds a shared CameraPresenter that walks presentedViewController up to the topmost controller before presenting. This also covers nested sheets.
  • If the topmost modal is mid-dismissal (e.g. a sheet closed in the same tap as opening the camera), it waits for that transition to finish via its transitionCoordinator, since UIKit also drops presentations made during one. That makes the @dismiss workaround from the issue unnecessary.
  • All three call sites (photo, video, gallery) use it. Failure behaviour is unchanged: no window means a log line, and video still fires VideoCancelled.
  • Android is unaffected (it goes through registerForActivityResult launchers), so there are no Android changes.

Testing

Tested on a physical iPhone 15 with an EDGE screen (nativephp/mobile 4.x + nativephp/mobile-ui 0.4) that opens the pickers from inside a <native:bottom-sheet>:

  • Take photo, Record video and Choose from gallery inside the sheet: each picker now opens over the sheet and the result/cancel event is dispatched (previously nothing happened).
  • Photo from a sheet nested inside another sheet: works.
  • Baseline (no sheet open): unchanged.

Note for anyone reproducing this: give the sheet a stable native:key. Without one, the sheet's positional node id shifts when state rendered before it in the tree changes (e.g. a log line added on tap), and SwiftUI tears the sheet down, taking the camera presented on top of it with it. That's EDGE node identity, not something this plugin can guard against.

sonalidudhia and others added 2 commits September 30, 2026 11:17
Camera::getPhoto(), recordVideo() and pickImages() presented on the key
window's rootViewController. While any modal is on screen (e.g. a
<native:bottom-sheet>, rendered as a SwiftUI .sheet) that controller is
already presenting, so UIKit silently drops the present() call: no picker,
no event, no log.

Add a shared CameraPresenter that walks the presentation chain to the
topmost controller before presenting, which also covers nested sheets.
If the topmost modal is mid-dismissal (sheet closed in the same tap), it
waits for that transition to complete before presenting, since UIKit also
drops presentations made during one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0199rrDNxmZMTFV31gcj8bJj
NativePHP#17 landed on main with a smaller version of this fix, so the three
picker call sites conflicted. This keeps CameraPresenter and drops
NativePHP#17's topViewController helper, because CameraPresenter also waits
for a sheet that is still closing before it presents. Everything else
from main, including NativePHP#13, comes through unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonhamp

Copy link
Copy Markdown
Member

Thanks for this, and sorry it sat for so long. I merged #17 accidentally before this PR. #17 fixes the same thing but doesn't handle a sheet that's still closing, and yours does.

@simonhamp
simonhamp merged commit 75c0f35 into NativePHP:main Oct 22, 2026
2 checks passed
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.

iOS: camera and gallery pickers silently fail when launched from a bottom sheet (rootVC.present on a busy controller)

2 participants