compose-multiplatform-file-picker
compose-multiplatform-file-picker copied to clipboard
Bug with .onExternalDrag modifier
I'm making a windows application that works with excel files. I added an option to add files: both drag and drop, and use file picker (by clicking on DnD box). I found out that FilePicker does not work properly with .onExternalDrag modifier: the application totally freezes after you try to drag any element out of File chooser dialog. That happens only if at least once any element with .onExternalDrag modifier is used. Upd: I mean it's happens even if you change screen. And even if on this screen are no elements with that modifier.
It looks like this:
At this point the application just does not respond and there are no ways to do something to it. If I comment an .onExternalDrag and try to launch application, everything works just fine:
I have this modifier only in one element. It's code:
@OptIn(ExperimentalComposeUiApi::class, ExperimentalFoundationApi::class)
@Composable
fun DragAndDropFileBox(navigator: Navigator, modifier: Modifier = Modifier) {
var isDragging by remember { mutableStateOf(false) }
val dragNDropColor = if (isDragging) Colors.active else Colors.default
var localPath by remember { mutableStateOf("") }
Box(
modifier = modifier
.border(border = BorderStroke(5.dp, Color.Magenta), shape = RectangleShape)
.onExternalDrag(
onDragStart = { isDragging = true },
onDragExit = { },
onDrop = { value ->
isDragging = false
val dragData = value.dragData
if (dragData is DragData.FilesList) {
val draggedList = DragDataList(dragData)
localPath = draggedList.receiveFilePath()
isDragging = false
navigator.replaceAll(MainScreen(localPath))
}
})
.onClick {
navigator.replace(FilePickerScreen())
}
) {
Column(modifier = Modifier.align(Alignment.Center)) {
DragAndDropDescription(
modifier = Modifier.align(Alignment.CenterHorizontally),
color = dragNDropColor
)
}
}
}
Java awt file picker does not have this problem, but I don't really won't use it (mostly because of it's appearance and not really native look).
P.S. I'm not a native speaker, so my apologies if I spoke out not totally clear.
I created a demonstration of this bug