Skip to content

Commit 2f3110f

Browse files
drchendsn5ft
authored andcommitted
[TopAppBar] Fix app:expanded=false not working
When an AppBarLayout is loaded, it will load the attribute and set up a non-forcing pending action. However when it's measured, the current scroll state will be saved and restored, which will override the non-forcing pending action. This behavior is incorrect - if there's a pending action, we shouldn't restore the scrolling state because it's meant to be changed. Resolves #2629 PiperOrigin-RevId: 440960254 (cherry picked from commit 05be1b9)
1 parent 9dd0952 commit 2f3110f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/java/com/google/android/material/appbar/AppBarLayout.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,12 @@ private boolean hasCollapsibleChild() {
537537

538538
private void invalidateScrollRanges() {
539539
// Saves the current scrolling state when we need to recalculate scroll ranges
540-
SavedState savedState = behavior == null || totalScrollRange == INVALID_SCROLL_RANGE
540+
// If the total scroll range is not known yet, the ABL is never scrolled.
541+
// If there's a pending action, we should skip this step and respect the pending action.
542+
SavedState savedState =
543+
behavior == null
544+
|| totalScrollRange == INVALID_SCROLL_RANGE
545+
|| pendingAction != PENDING_ACTION_NONE
541546
? null : behavior.saveScrollState(AbsSavedState.EMPTY_STATE, this);
542547
// Invalidate the scroll ranges
543548
totalScrollRange = INVALID_SCROLL_RANGE;

0 commit comments

Comments
 (0)