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

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

Merge "Fix resize frame drawing underneath content" into main

parents f8484f60 b1ff3fff
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -32,7 +32,9 @@ import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
@@ -49,6 +51,8 @@ import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastIsFinite
import androidx.compose.ui.zIndex
import com.android.compose.modifiers.thenIf
import com.android.systemui.communal.ui.viewmodel.DragHandle
import com.android.systemui.communal.ui.viewmodel.ResizeInfo
import com.android.systemui.communal.ui.viewmodel.ResizeableItemFrameViewModel
@@ -150,10 +154,9 @@ private fun BoxScope.DragHandle(
/**
 * Draws a frame around the content with drag handles on the top and bottom of the content.
 *
 * @param index The index of this item in the [LazyGridState].
 * @param key The unique key of this element, must be the same key used in the [LazyGridState].
 * @param currentSpan The current span size of this item in the grid.
 * @param gridState The [LazyGridState] for the grid containing this item.
 * @param minItemSpan The minimum span that an item may occupy. Items are resized in multiples of
 *   this span.
 * @param gridContentPadding The content padding used for the grid, needed for determining offsets.
 * @param verticalArrangement The vertical arrangement of the grid items.
 * @param modifier Optional modifier to apply to the frame.
@@ -162,6 +165,10 @@ private fun BoxScope.DragHandle(
 * @param outlineColor Optional color to make the outline around the content.
 * @param cornerRadius Optional radius to give to the outline around the content.
 * @param strokeWidth Optional stroke width to draw the outline with.
 * @param minHeightPx Optional minimum height in pixels that this widget can be resized to.
 * @param maxHeightPx Optional maximum height in pixels that this widget can be resized to.
 * @param resizeMultiple Optional number of spans that we allow resizing by. For example, if set to
 *   3, then we only allow resizing in multiples of 3 spans.
 * @param alpha Optional function to provide an alpha value for the outline. Can be used to fade the
 *   outline in and out. This is wrapped in a function for performance, as the value is only
 *   accessed during the draw phase.
@@ -196,10 +203,19 @@ fun ResizableItemFrame(
        }

    val dragHandleHeight = verticalArrangement.spacing - outlinePadding * 2
    val isDragging by
        remember(viewModel) {
            derivedStateOf {
                val topOffset = viewModel.topDragState.offset.takeIf { it.fastIsFinite() } ?: 0f
                val bottomOffset =
                    viewModel.bottomDragState.offset.takeIf { it.fastIsFinite() } ?: 0f
                topOffset > 0 || bottomOffset > 0
            }
        }

    // Draw content surrounded by drag handles at top and bottom. Allow drag handles
    // to overlap content.
    Box(modifier) {
    Box(modifier.thenIf(isDragging) { Modifier.zIndex(1f) }) {
        content()

        if (enabled) {