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

Commit 9ed38aa9 authored by George Lin's avatar George Lin
Browse files

Fix shape and grid content height

If the app is paused and started again, we can possibly call bind and
trigger the listener of on layout again, with the layout component give
the height of 0.

We avoid updating the height of 0 to fix the issue.

Test: Manually tested the issue no longer exists
Fixes: 376107964
Flag: com.android.systemui.shared.new_customization_picker_ui
Change-Id: I9c70598a0b2a7dbc481dfdd33abb99af19fa8f65
parent 0ae53d6d
Loading
Loading
Loading
Loading
+19 −15
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ object ShapeGridFloatingSheetBinder {
        shapeContent.viewTreeObserver.addOnGlobalLayoutListener(
            object : OnGlobalLayoutListener {
                override fun onGlobalLayout() {
                    if (shapeContent.height != 0) {
                        _shapeGridFloatingSheetHeights.value =
                            _shapeGridFloatingSheetHeights.value?.copy(
                                shapeContentHeight = shapeContent.height
@@ -114,6 +115,7 @@ object ShapeGridFloatingSheetBinder {
                                ?: ShapeGridFloatingSheetHeightsViewModel(
                                    shapeContentHeight = shapeContent.height
                                )
                    }
                    shapeContent.viewTreeObserver.removeOnGlobalLayoutListener(this)
                }
            }
@@ -122,10 +124,7 @@ object ShapeGridFloatingSheetBinder {
        gridContent.viewTreeObserver.addOnGlobalLayoutListener(
            object : OnGlobalLayoutListener {
                override fun onGlobalLayout() {
                    // Make sure the recycler view height is the same as its parent. It's possible
                    // that the recycler view is shorter than expected.
                    gridOptionList.layoutParams =
                        gridOptionList.layoutParams.apply { height = gridContent.height }
                    if (gridContent.height != 0) {
                        _shapeGridFloatingSheetHeights.value =
                            _shapeGridFloatingSheetHeights.value?.copy(
                                gridContentHeight = gridContent.height
@@ -133,6 +132,7 @@ object ShapeGridFloatingSheetBinder {
                                ?: ShapeGridFloatingSheetHeightsViewModel(
                                    gridContentHeight = shapeContent.height
                                )
                    }
                    shapeContent.viewTreeObserver.removeOnGlobalLayoutListener(this)
                }
            }
@@ -152,6 +152,10 @@ object ShapeGridFloatingSheetBinder {
                            val (shapeContentHeight, gridContentHeight) = heights
                            shapeContentHeight ?: return@collect
                            gridContentHeight ?: return@collect
                            // Make sure the recycler view height is the same as its parent. It's
                            // possible that the recycler view is shorter than expected.
                            gridOptionList.layoutParams =
                                gridOptionList.layoutParams.apply { height = gridContentHeight }
                            val targetHeight =
                                when (selectedTab) {
                                    SHAPE -> shapeContentHeight