From 3974765ea96d083eef23af8445f0d4c04d502ac6 Mon Sep 17 00:00:00 2001 From: x-JOC Date: Wed, 21 Oct 2026 12:12:00 +0300 Subject: [PATCH] fix(drawer): update the search bar padding when the device profile changes (#7405) AllAppsSearchInput sets its horizontal padding from the device profile only when it is inflated and when the IDP changes. A DeviceProfile change without an IDP change (rotation, or folding and unfolding once the device type is stable) left the padding of the old profile. When it did run, setupPadding() also reset the full padding even while a search was active, where the bar uses half of it, and the focus and text listeners kept animating to the paddings captured at inflation. - Listen to DeviceProfile changes and update the padding then too. - Keep the half padding while the search box is focused or holds a query, and cancel a running padding animation first. - Animate to the current paddings rather than the inflation ones. The search text and results are untouched. The result views already follow the new profile: ActivityAllAppsContainerView#onDeviceProfileChanged swaps the adapters and clears the view pool of every list, the search list included, so all result views are inflated again with it. (cherry picked from commit 090ce597ed7f6e35ee7fecb8235ea52d7be155c7) Co-authored-by: Claude Opus 5.5 --- .../lawnchair/allapps/AllAppsSearchInput.kt | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt b/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt index 0325d69627..8dc6a83204 100644 --- a/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt +++ b/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt @@ -56,6 +56,8 @@ import app.lawnchair.search.algorithms.LawnchairSearchAlgorithm import app.lawnchair.theme.color.tokens.ColorTokens import app.lawnchair.ui.theme.LawnchairTheme import app.lawnchair.util.ProvideLifecycleState +import com.android.launcher3.DeviceProfile +import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener import com.android.launcher3.Insettable import com.android.launcher3.InvariantDeviceProfile.OnIDPChangeListener import com.android.launcher3.LauncherState @@ -77,6 +79,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs), Insettable, OnIDPChangeListener, + OnDeviceProfileChangeListener, SearchUiManager, SearchCallback, AllAppsStore.OnUpdateListener, @@ -118,6 +121,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : private var initialPaddingLeft: Int = 0 private var initialPaddingRight: Int = 0 + private var paddingAnimator: ValueAnimator? = null private var hideSearchBar = false override fun onFinishInflate() { @@ -260,9 +264,6 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : } }) - val currentPaddingLeft = initialPaddingLeft - val currentPaddingRight = initialPaddingRight - // Activate zero search on tap @SuppressLint("ClickableViewAccessibility") input.setOnTouchListener { _, event -> @@ -287,7 +288,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : setBackgroundVisibility(false, 0f) animateHintVisibility(true) - animatePadding(currentPaddingLeft / 2, currentPaddingRight / 2) + animatePadding(initialPaddingLeft / 2, initialPaddingRight / 2) } else { setBackgroundVisibility(true, 1f) animateHintVisibility(false) @@ -297,7 +298,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : } if (input.text.isNullOrEmpty()) { - animatePadding(currentPaddingLeft, currentPaddingRight) + animatePadding(initialPaddingLeft, initialPaddingRight) } focusedResultTitle = "" input.setHint("") @@ -326,7 +327,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : val isEmpty = it.isNullOrEmpty() if (isEmpty && !input.hasFocus()) { - animatePadding(currentPaddingLeft, currentPaddingRight) + animatePadding(initialPaddingLeft, initialPaddingRight) } queryEmpty = isEmpty }, @@ -345,7 +346,11 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : val padding = dp.getAllAppsIconStartMargin(context) initialPaddingLeft = padding initialPaddingRight = padding - setPadding(padding, paddingTop, padding, paddingBottom) + // Keep the narrower padding of an active search (see the focus and text listeners) + paddingAnimator?.cancel() + val isSearchActive = ::input.isInitialized && (input.hasFocus() || !input.text.isNullOrEmpty()) + val currentPadding = if (isSearchActive) padding / 2 else padding + setPadding(currentPadding, paddingTop, currentPadding, paddingBottom) } } @@ -372,7 +377,8 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : val currentPaddingLeft = paddingLeft val currentPaddingRight = paddingRight - ValueAnimator.ofFloat(0f, 1f).apply { + paddingAnimator?.cancel() + paddingAnimator = ValueAnimator.ofFloat(0f, 1f).apply { duration = 300 interpolator = FastOutSlowInInterpolator() addUpdateListener { animation -> @@ -421,6 +427,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : override fun onAttachedToWindow() { super.onAttachedToWindow() launcher.deviceProfile.inv.addOnChangeListener(this) + launcher.addOnDeviceProfileChangeListener(this) if (::appsView.isInitialized) { appsView.appsStore?.addUpdateListener(this) } @@ -430,6 +437,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : override fun onDetachedFromWindow() { super.onDetachedFromWindow() launcher.deviceProfile.inv.removeOnChangeListener(this) + launcher.removeOnDeviceProfileChangeListener(this) if (::appsView.isInitialized) { appsView.appsStore?.removeUpdateListener(this) } @@ -548,6 +556,13 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : bgAlphaState = Utilities.mapRange(fraction, 0f, bgAlpha) } + override fun onDeviceProfileChanged(dp: DeviceProfile) { + // LC-Note: The paddings follow the device profile, which also changes without an IDP + // change, e.g. on rotation or when a foldable is folded or unfolded. + setupPadding() + requestLayout() + } + override fun onIdpChanged(modelPropertiesChanged: Boolean) { setupPadding() invalidate()