peekaboo
peekaboo copied to clipboard
Android Image Picker Launcher: onResult Callback Not Invoked on Dismissal
Description:
When using rememberImagePickerLauncher, the onResult callback is never invoked if the user dismisses the image picker without selecting an image. This causes the consumer’s state to remain in a “picker active” state, expecting a result that never comes, which then requires an extra click to recover.
Current Behavior:
- If an image is selected, the callback correctly processes the image.
- If the user cancels/dismisses the picker (i.e., no image is selected), the callback is not triggered at all, and onCanceled() is never called.
Code Example:
val imagePicker = rememberImagePickerLauncher(
scope = scope
) { result ->
if (result.isNotEmpty()) {
// Do something with result
} else {
onCanceled()
}
}
Expected Behavior:
The onResult callback should always be invoked—regardless of whether the user selects an image or cancels the picker. When dismissed, it should trigger the callback with an empty result (or a null value) so that the consumer can correctly handle the cancellation via onCanceled().
Steps to Reproduce:
- Launch the image picker using rememberImagePickerLauncher.
- Dismiss the image picker without selecting an image.
- Notice that onResult is not called, and the UI remains in an inconsistent state.
Proposed Fix:
Modify the image picker launcher implementation to ensure that onResult is always called. If the image picker is dismissed without a selection, the callback should be triggered with an empty result, allowing consumers to update the UI accordingly.
Please let me know if you need any additional details.