vinceglb / FileKit

Pick and save Files, Medias and Folder for Kotlin Multiplatform / KMP and Compose Multiplatform / CMP
https://vinceglb.github.io/FileKit/
MIT License
513 stars 15 forks source link

When swiping bottom sheet in iOS the event not generated #127

Open derynia opened 1 day ago

derynia commented 1 day ago

I have a following composable function

@Composable
fun PickFile(
    type: String,
    afterPick: (PlatformFile?) -> Unit
) {
    val launcher = rememberFilePickerLauncher(
        type =
        when (type) {
            SELECT_FILE_CLICKED -> PickerType.Image
            SELECT_VIDEO -> PickerType.Video
            else -> PickerType.File(listOf("pdf"))
        },
        mode = PickerMode.Single,
        title = Strings.getString("pic_a_file")
    ) { file -> afterPick(file) }
    launcher.launch()
}

in my viemodel I check if the file is selected I'm starting to upload it. If the selection dialog is dismissed I clear the state of viewmodel to unblock the selectButton

private fun startFileUpload(platformFile: PlatformFile?) {
    Napier.i(tag = "FileSelect", message = "Starting upload")
    platformFile?.let {
        uploadFile(
            profileRepo = profileRepo,
            scope = scope,
            platformFile = it,
            type = PROCESSING_DOCUMENTS,
        )
    } ?: errorsShown()
}

It works fine in Android. But in iOS if I swipe down file selection dialog insead of pressing Cancel button nothing happens. Event is not generated so the code in viewModel is not called. Again if I dismiss by pressing Cancel in selection dialog everything works fine. In Android all ways of dialog dismiss work fine. The problem exists in both simulator and physical devices on iOS18 and earlier versions.

Simulator Screenshot - iPhone 14 Pro Max - 2024-10-03 at 18 09 34

derynia commented 8 hours ago

I also found out that when picking a document, not photo everything works fine. The problem seems to be in PHPickerViewControllerDelegateProtocol which doesn't have override fun documentPickerWasCancelled(controller: UIDocumentPickerViewController) { onPickerCancelled() } as UIDocumentPickerDelegateProtocol does. So it seems to be the problem is in native iOS component. Also I googled this problem and found some kind of solution here: https://forums.developer.apple.com/forums/thread/704315

But I don't understand at all how to implement it as I'm very weak in Swift.

vinceglb commented 8 hours ago

Hi @derynia! Thanks for reporting this issue! I'm going to take a look.