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

Commit af2d4bb0 authored by Olivier St-Onge's avatar Olivier St-Onge
Browse files

Clear the drag&drop state on drag end events

In some rare occasions, the drag could end before the drag&drop listeners were notified. This would cause the tile to be wrongfully marked as being dragged until another drag gesture was started.

The fix is to listen for the end event and clear the state is a drag is active at that moment.

Flag: com.android.systemui.qs_ui_refactor_compose_fragment
Fixes: 425555356
Test: manually - Testing really short drag gestures
Change-Id: I31883811e3e18350c91ef63d7071ab1fe60dd766
parent f70831e7
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -122,7 +122,9 @@ fun Modifier.dragAndDropTileList(
        remember(dragAndDropState) {
            object : DragAndDropTarget {
                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) {
@@ -148,6 +150,10 @@ fun Modifier.dragAndDropTileList(
                }

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

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

                    dragState.onStarted(sizedTile, dragType)
                    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()
                },
            )
        }
    )