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

Commit 3b441008 authored by Lucas Silva's avatar Lucas Silva
Browse files

Fix flickering of the resize frame when resizing

After resizing, the frame flickers briefly due to the offsets not being
immediately set to 0 after resize. To remedy this, we just key the
viewmodel on the current size - and when the current size changes, we
create an entirely new viewmodel, which removes any existing offsets.

Fixes: 372230926
Test: manually by expanding/shrinking widgets and verifying it no longer
flickers
Flag: com.android.systemui.communal_widget_resizing

Change-Id: Iac45e9233d7be9dde4b8dabfd69df7f19c99d9cf
parent 4f94f0d5
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -649,6 +649,7 @@ private fun ObserveNewWidgetAddedEffect(
@Composable
private fun ResizableItemFrameWrapper(
    key: String,
    currentSpan: GridItemSpan,
    gridState: LazyGridState,
    gridContentPadding: PaddingValues,
    verticalArrangement: Arrangement.Vertical,
@@ -665,6 +666,7 @@ private fun ResizableItemFrameWrapper(
    } else {
        ResizableItemFrame(
            key = key,
            currentSpan = currentSpan,
            gridState = gridState,
            gridContentPadding = gridContentPadding,
            verticalArrangement = verticalArrangement,
@@ -797,6 +799,7 @@ private fun BoxScope.CommunalHubLazyGrid(
                val widgetSizeInfo = calculateWidgetSize(item, isResizable)
                ResizableItemFrameWrapper(
                    key = item.key,
                    currentSpan = GridItemSpan(item.size.span),
                    gridState = gridState,
                    gridContentPadding = contentPadding,
                    verticalArrangement = itemArrangement,
+7 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@@ -65,6 +66,7 @@ private fun UpdateGridLayoutInfo(
    minHeightPx: Int,
    maxHeightPx: Int,
    resizeMultiple: Int,
    currentSpan: GridItemSpan,
) {
    val density = LocalDensity.current
    LaunchedEffect(
@@ -77,6 +79,7 @@ private fun UpdateGridLayoutInfo(
        minHeightPx,
        maxHeightPx,
        resizeMultiple,
        currentSpan,
    ) {
        val verticalItemSpacingPx = with(density) { verticalArrangement.spacing.toPx() }
        val verticalContentPaddingPx =
@@ -100,7 +103,7 @@ private fun UpdateGridLayoutInfo(
                    currentRow = itemInfo?.row,
                    maxHeightPx = maxHeightPx,
                    minHeightPx = minHeightPx,
                    currentSpan = itemInfo?.span,
                    currentSpan = currentSpan.currentLineSpan,
                    resizeMultiple = resizeMultiple,
                    totalSpans = maxItemSpan,
                    viewportHeightPx = viewportHeightPx,
@@ -168,6 +171,7 @@ private fun BoxScope.DragHandle(
@Composable
fun ResizableItemFrame(
    key: String,
    currentSpan: GridItemSpan,
    gridState: LazyGridState,
    gridContentPadding: PaddingValues,
    verticalArrangement: Arrangement.Vertical,
@@ -187,7 +191,7 @@ fun ResizableItemFrame(
    val brush = SolidColor(outlineColor)
    val onResizeUpdated by rememberUpdatedState(onResize)
    val viewModel =
        rememberViewModel(traceName = "ResizeableItemFrame.viewModel") {
        rememberViewModel(key = currentSpan, traceName = "ResizeableItemFrame.viewModel") {
            ResizeableItemFrameViewModel()
        }

@@ -241,6 +245,7 @@ fun ResizableItemFrame(
                viewModel = viewModel,
                key = key,
                gridState = gridState,
                currentSpan = currentSpan,
                gridContentPadding = gridContentPadding,
                verticalArrangement = verticalArrangement,
                minHeightPx = minHeightPx,
+1 −1
Original line number Diff line number Diff line
@@ -420,7 +420,7 @@ class ResizeableItemFrameViewModelTest : SysuiTestCase() {
        val verticalContentPaddingPx: Float,
        val viewportHeightPx: Int,
        val currentRow: Int?,
        val currentSpan: Int?,
        val currentSpan: Int,
        val maxHeightPx: Int,
        val minHeightPx: Int,
        val resizeMultiple: Int,
+2 −2
Original line number Diff line number Diff line
@@ -109,13 +109,13 @@ class ResizeableItemFrameViewModel : ExclusiveActivatable() {
        currentRow: Int?,
        maxHeightPx: Int,
        minHeightPx: Int,
        currentSpan: Int?,
        currentSpan: Int,
        resizeMultiple: Int,
        totalSpans: Int,
        viewportHeightPx: Int,
        verticalContentPaddingPx: Float,
    ) {
        if (currentRow == null || currentSpan == null) {
        if (currentRow == null) {
            gridLayoutInfo.value = null
            return
        }