Skip to content

Commit

Permalink
migrate file upload sample
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-tennert committed Oct 18, 2024
1 parent 4d72e26 commit 4acdd8f
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
package io.github.jan.supabase.common.ui.utils

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.draganddrop.dragAndDropTarget
import androidx.compose.runtime.MutableState
import androidx.compose.ui.DragData
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.onExternalDrag
import androidx.compose.ui.draganddrop.DragAndDropEvent
import androidx.compose.ui.draganddrop.DragAndDropTarget
import androidx.compose.ui.draganddrop.DragData
import androidx.compose.ui.draganddrop.dragData

@OptIn(ExperimentalComposeUiApi::class)
@OptIn(ExperimentalComposeUiApi::class, ExperimentalFoundationApi::class)
actual fun Modifier.applyDragging(isDragging: MutableState<Boolean>, onSuccess: (List<String>) -> Unit): Modifier {
return composed {
onExternalDrag(
onDragStart = {
isDragging.value = true
dragAndDropTarget(
shouldStartDragAndDrop = {
it.dragData() is DragData.FilesList
},
onDragExit = {
isDragging.value = false
},
onDrop = {
isDragging.value = false
if(it.dragData is DragData.FilesList) {
onSuccess((it.dragData as DragData.FilesList).readFiles())
target = object : DragAndDropTarget {
override fun onDrop(event: DragAndDropEvent): Boolean {
isDragging.value = false
val dragData = event.dragData() as DragData.FilesList
onSuccess(dragData.readFiles())
return true;
}
}
)
Expand Down

0 comments on commit 4acdd8f

Please sign in to comment.