Skip to content

Commit

Permalink
[TopAppBar] Fix app:expanded=false not working
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
drchen authored and dsn5ft committed Apr 19, 2022
1 parent 9dd0952 commit 2f3110f
Showing 1 changed file with 6 additions and 1 deletion.
Expand Up @@ -537,7 +537,12 @@ private boolean hasCollapsibleChild() {

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

0 comments on commit 2f3110f

Please sign in to comment.