Skip to content

Commit

Permalink
Fixed file picker callback
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikksahu committed Oct 14, 2023
1 parent 38b5624 commit 25c3aa5
Showing 1 changed file with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,20 @@ class VueFilePicker {

@Composable
fun getLauncher(onResult: (Uri) -> Unit = {}): ManagedActivityResultLauncher<Intent, ActivityResult> {
LaunchedEffect(key1 = vueFilePickerState, block = {
if (vueFilePickerState is VueFilePickerState.VueFilePickerImported && importJob == null) {
importJob = launch(context = coroutineContext, start = CoroutineStart.LAZY) {
if (isActive) {
onResult((vueFilePickerState as VueFilePickerState.VueFilePickerImported).uri)
}
}
importJob?.start()
importJob?.join()
}
})
return rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
vueFilePickerState = if (it.resultCode == Activity.RESULT_OK) {
if (it.resultCode == Activity.RESULT_OK) {
val uri = it.data?.data
if (uri != null) {
//Other sources
VueFilePickerState.VueFilePickerImported(uri)
vueFilePickerState = VueFilePickerState.VueFilePickerImported(uri)
onResult(uri)
} else {
//From Camera
VueFilePickerState.VueFilePickerImported(importFile!!.toUri())
vueFilePickerState = VueFilePickerState.VueFilePickerImported(importFile!!.toUri())
onResult(importFile!!.toUri())
}
} else {
VueFilePickerState.VueFilePickerIdeal
vueFilePickerState = VueFilePickerState.VueFilePickerIdeal
}
}
}
Expand Down

0 comments on commit 25c3aa5

Please sign in to comment.