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
diff --git a/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt b/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt
index 8a59c60..5f292bd 100644
--- a/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt
+++ b/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt
@@ -107,13 +107,15 @@
shapeContent.viewTreeObserver.addOnGlobalLayoutListener(
object : OnGlobalLayoutListener {
override fun onGlobalLayout() {
- _shapeGridFloatingSheetHeights.value =
- _shapeGridFloatingSheetHeights.value?.copy(
- shapeContentHeight = shapeContent.height
- )
- ?: ShapeGridFloatingSheetHeightsViewModel(
+ if (shapeContent.height != 0) {
+ _shapeGridFloatingSheetHeights.value =
+ _shapeGridFloatingSheetHeights.value?.copy(
shapeContentHeight = shapeContent.height
)
+ ?: ShapeGridFloatingSheetHeightsViewModel(
+ shapeContentHeight = shapeContent.height
+ )
+ }
shapeContent.viewTreeObserver.removeOnGlobalLayoutListener(this)
}
}
@@ -122,17 +124,15 @@
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 }
- _shapeGridFloatingSheetHeights.value =
- _shapeGridFloatingSheetHeights.value?.copy(
- gridContentHeight = gridContent.height
- )
- ?: ShapeGridFloatingSheetHeightsViewModel(
- gridContentHeight = shapeContent.height
+ if (gridContent.height != 0) {
+ _shapeGridFloatingSheetHeights.value =
+ _shapeGridFloatingSheetHeights.value?.copy(
+ gridContentHeight = gridContent.height
)
+ ?: ShapeGridFloatingSheetHeightsViewModel(
+ gridContentHeight = shapeContent.height
+ )
+ }
shapeContent.viewTreeObserver.removeOnGlobalLayoutListener(this)
}
}
@@ -152,6 +152,10 @@
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