🐛 [iOS] Deliver camera result after dismissal and encode JPEG off the main thread#619
Open
PierreVieira wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the two iOS camera picker problems reported in #618.
1. Result delivered before the picker dismissal (
CameraControllerDelegate)imagePickerController(_:didFinishPickingMediaWithInfo:)used to invokeonImagePickedbefore startingdismissViewControllerAnimated, 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 asyncNSItemProviderloading naturally delays results past the dismissal.Now both the success and cancel callbacks are invoked from the dismissal completion handler, so
openCameraPickeronly 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-MBwriteToURLran insidewithContext(Dispatchers.Main), freezing the UI right after the capture. The function is now split in two phases: the UIKit part (presentation + delegate) stays onDispatchers.Main, and the encode/write moved toDispatchers.IO. Public API unchanged.:filekit-dialogs:compileKotlinIosSimulatorArm64passes. 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.