Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3d8c671e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Clear the drag&drop state on drag end events" into main

parents 34884ece af2d4bb0
Loading
Loading
Loading
Loading
+16 −1
Original line number Original line Diff line number Diff line
@@ -122,7 +122,9 @@ fun Modifier.dragAndDropTileList(
        remember(dragAndDropState) {
        remember(dragAndDropState) {
            object : DragAndDropTarget {
            object : DragAndDropTarget {
                override fun onEnded(event: DragAndDropEvent) {
                override fun onEnded(event: DragAndDropEvent) {
                    dragAndDropState.onDrop()
                    // Drop the tile if the drag ended with a cell still marked as dragged. This can
                    // happen if no other drag listeners consumed the drop event.
                    onDropInternal()
                }
                }


                override fun onExited(event: DragAndDropEvent) {
                override fun onExited(event: DragAndDropEvent) {
@@ -148,6 +150,10 @@ fun Modifier.dragAndDropTileList(
                }
                }


                override fun onDrop(event: DragAndDropEvent): Boolean {
                override fun onDrop(event: DragAndDropEvent): Boolean {
                    return onDropInternal()
                }

                private fun onDropInternal(): Boolean {
                    return dragAndDropState.draggedCell?.let {
                    return dragAndDropState.draggedCell?.let {
                        onDrop(it.tile.tileSpec)
                        onDrop(it.tile.tileSpec)
                        dragAndDropState.onDrop()
                        dragAndDropState.onDrop()
@@ -190,6 +196,8 @@ fun Modifier.dragAndDropTileSource(
            detectDragGesturesAfterLongPress(
            detectDragGesturesAfterLongPress(
                onDrag = { _, _ -> },
                onDrag = { _, _ -> },
                onDragStart = {
                onDragStart = {
                    check(!dragState.dragInProgress)

                    dragState.onStarted(sizedTile, dragType)
                    dragState.onStarted(sizedTile, dragType)
                    onDragStart()
                    onDragStart()


@@ -206,6 +214,13 @@ fun Modifier.dragAndDropTileSource(
                        )
                        )
                    )
                    )
                },
                },
                onDragEnd = {
                    check(dragState.dragInProgress)

                    // onDragEnd is only called if the drag is ended before a drag and drop session
                    // is started. In this case, we clear the drag state.
                    dragState.onDrop()
                },
            )
            )
        }
        }
    )
    )