Skip to content

🐛 [iOS] Deliver camera result after dismissal and encode JPEG off the main thread#619

Merged
vinceglb merged 1 commit into
vinceglb:mainfrom
PierreVieira:fix/ios-camera-dismissal-ordering-and-main-thread
Jul 21, 2026
Merged

🐛 [iOS] Deliver camera result after dismissal and encode JPEG off the main thread#619
vinceglb merged 1 commit into
vinceglb:mainfrom
PierreVieira:fix/ios-camera-dismissal-ordering-and-main-thread

Conversation

@PierreVieira

@PierreVieira PierreVieira commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Fixes the two iOS camera picker problems reported in #618.

1. Result delivered before the picker dismissal (CameraControllerDelegate)

imagePickerController(_:didFinishPickingMediaWithInfo:) used to invoke onImagePicked before starting dismissViewControllerAnimated, so the continuation resumed (and client code reacted — navigation, closing Compose dialogs, ...) while the modal was still on screen, racing the UIKit dismissal transition. The gallery path doesn't have this issue in practice because the async NSItemProvider loading naturally delays results past the dismissal.

Now both the success and cancel callbacks are invoked from the dismissal completion handler, so openCameraPicker only returns once the picker is fully gone.

2. JPEG encode + file write on the main thread (FileKit.ios.kt)

UIImageJPEGRepresentation(image, 1.0) on a full-resolution photo plus the multi-MB writeToURL ran inside withContext(Dispatchers.Main), freezing the UI right after the capture. The function is now split in two phases: the UIKit part (presentation + delegate) stays on Dispatchers.Main, and the encode/write moved to Dispatchers.IO. Public API unchanged.

:filekit-dialogs:compileKotlinIosSimulatorArm64 passes. The underlying diagnosis (camera result racing the dismissal while the launcher lived inside a Compose Dialog) was confirmed on a physical iPhone 15 (iOS 17, Compose Multiplatform 1.11.1), where an equivalent deliver-after-dismissal + encode-off-main implementation resolves the freezes; this patch itself is compile-tested.

@vinceglb

Copy link
Copy Markdown
Owner

thanks for your PR 👌

@vinceglb
vinceglb merged commit 5cd09d6 into vinceglb:main Jul 21, 2026
9 checks passed
@PierreVieira
PierreVieira deleted the fix/ios-camera-dismissal-ordering-and-main-thread branch July 22, 2026 00:13
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.

2 participants