Skip to content

Commit 4f12b7d

Browse files
Nobodymaterial-automation
authored andcommitted
Update hidden state logic to address a race condition occurring when showing/hiding the navigation bar multiple times before the animation ends.
PiperOrigin-RevId: 361224275
1 parent f40116b commit 4f12b7d

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

components/BottomNavigation/src/MDCBottomNavigationBarController.m

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -266,19 +266,17 @@ - (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated {
266266
self.navigationBarBottomAnchorConstraint.constant =
267267
hidden ? CGRectGetHeight(navigationBar.frame) : 0;
268268

269-
void (^completionBlock)(BOOL) = nil;
270-
271-
if (hidden && animated) {
272-
// For animated hides we deffer updating the nav-bar hidden state until the animation finishes.
273-
completionBlock = ^(BOOL finished) {
274-
if (finished) {
275-
// Hide the view to avoid visual artifacts on rotations.
276-
navigationBar.hidden = hidden;
277-
}
278-
};
279-
} else {
280-
// Update `hidden` state immediately for unhide or non-animated transitions to ensure it gets
281-
// applied in the same run loop.
269+
void (^completionBlock)(BOOL) = ^(BOOL finished) {
270+
// Update the end hidden state of the navigation bar if it was not interrupted (the end state
271+
// matches the current state). Otherwise an already scheduled animation will take care of this.
272+
if (finished && !hidden != !self.navigationBarItemsBottomAnchorConstraint.active) {
273+
navigationBar.hidden = hidden;
274+
}
275+
};
276+
277+
// Immediatelly update the navigation bar's hidden state when it is going to become visible to be
278+
// able to see the animation).
279+
if (!hidden) {
282280
navigationBar.hidden = hidden;
283281
}
284282

0 commit comments

Comments
 (0)