Skip to content

Commit

Permalink
Update hidden state logic to address a race condition occurring when …
Browse files Browse the repository at this point in the history
…showing/hiding the navigation bar multiple times before the animation ends.

PiperOrigin-RevId: 361224275
  • Loading branch information
Nobody authored and material-automation committed Mar 5, 2021
1 parent f40116b commit 4f12b7d
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions components/BottomNavigation/src/MDCBottomNavigationBarController.m
Expand Up @@ -266,19 +266,17 @@ - (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated {
self.navigationBarBottomAnchorConstraint.constant =
hidden ? CGRectGetHeight(navigationBar.frame) : 0;

void (^completionBlock)(BOOL) = nil;

if (hidden && animated) {
// For animated hides we deffer updating the nav-bar hidden state until the animation finishes.
completionBlock = ^(BOOL finished) {
if (finished) {
// Hide the view to avoid visual artifacts on rotations.
navigationBar.hidden = hidden;
}
};
} else {
// Update `hidden` state immediately for unhide or non-animated transitions to ensure it gets
// applied in the same run loop.
void (^completionBlock)(BOOL) = ^(BOOL finished) {
// Update the end hidden state of the navigation bar if it was not interrupted (the end state
// matches the current state). Otherwise an already scheduled animation will take care of this.
if (finished && !hidden != !self.navigationBarItemsBottomAnchorConstraint.active) {
navigationBar.hidden = hidden;
}
};

// Immediatelly update the navigation bar's hidden state when it is going to become visible to be
// able to see the animation).
if (!hidden) {
navigationBar.hidden = hidden;
}

Expand Down

0 comments on commit 4f12b7d

Please sign in to comment.