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

Commit 47b1c542 authored by Bryce Lee's avatar Bryce Lee
Browse files

Do not show remove button unless item is selected or reordering.

Currently, the remove button shows in edit mode if an item is selected
or we are reordering. However, the definition of reordering was defined
on simply drag start. This changelist updates the behavior to make sure
we're actually dragging an item before we are considered in the
reordering state.

Test: manually verified remove button shows under correct conditions
Flag: EXEMPT bugfix
Fixes: 346337328
Change-Id: I2f5524acea494799d0f92e5c08a49f24d5428607
parent 0b8d6213
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -108,7 +108,12 @@ internal constructor(
    private val draggingItemLayoutInfo: LazyGridItemInfo?
        get() = state.layoutInfo.visibleItemsInfo.firstOrNull { it.index == draggingItemIndex }

    internal fun onDragStart(offset: Offset, contentOffset: Offset) {
    /**
     * Called when dragging is initiated.
     *
     * @return {@code True} if dragging a grid item, {@code False} otherwise.
     */
    internal fun onDragStart(offset: Offset, contentOffset: Offset): Boolean {
        state.layoutInfo.visibleItemsInfo
            .filter { item -> contentListState.isItemEditable(item.index) }
            // grid item offset is based off grid content container so we need to deduct
@@ -118,7 +123,10 @@ internal constructor(
                dragStartPointerOffset = offset - this.offset.toOffset()
                draggingItemIndex = index
                draggingItemInitialOffset = this.offset.toOffset()
                return true
            }

        return false
    }

    internal fun onDragInterrupted() {
@@ -216,8 +224,9 @@ fun Modifier.dragContainer(
                    dragDropState.onDrag(offset = offset)
                },
                onDragStart = { offset ->
                    dragDropState.onDragStart(offset, contentOffset)
                    if (dragDropState.onDragStart(offset, contentOffset)) {
                        viewModel.onReorderWidgetStart()
                    }
                },
                onDragEnd = {
                    dragDropState.onDragInterrupted()