From cdf7ffccc2a4ab366b630eae460099ce977ea2c7 Mon Sep 17 00:00:00 2001 From: Nobody Date: Fri, 12 Feb 2021 10:42:27 -0800 Subject: [PATCH] Honor the `animated` param when changing the hidden state of the bottom navigation bar. PiperOrigin-RevId: 357221948 --- .../src/MDCBottomNavigationBarController.m | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/components/BottomNavigation/src/MDCBottomNavigationBarController.m b/components/BottomNavigation/src/MDCBottomNavigationBarController.m index 77b54e2c02a..78cf09dd9f4 100644 --- a/components/BottomNavigation/src/MDCBottomNavigationBarController.m +++ b/components/BottomNavigation/src/MDCBottomNavigationBarController.m @@ -18,9 +18,7 @@ #import "private/MDCBottomNavigationBar+Private.h" #import "private/MDCBottomNavigationLargeItemDialogView.h" -#import "MDCBottomNavigationBarControllerDelegate.h" #import "MaterialBottomNavigation.h" -#import "MaterialApplication.h" // A context for Key Value Observing static void *const kObservationContext = (void *)&kObservationContext; @@ -263,16 +261,35 @@ - (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated { _navigationBarHidden = hidden; + MDCBottomNavigationBar *navigationBar = self.navigationBar; self.navigationBarItemsBottomAnchorConstraint.active = !hidden; self.navigationBarBottomAnchorConstraint.constant = - hidden ? CGRectGetHeight(self.navigationBar.frame) : 0; + hidden ? CGRectGetHeight(navigationBar.frame) : 0; - [UIView animateWithDuration:kNavigationBarHideShowAnimationDuration + 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. + navigationBar.hidden = hidden; + } + + NSTimeInterval duration = animated ? kNavigationBarHideShowAnimationDuration : 0; + [UIView animateWithDuration:duration animations:^{ [self.view setNeedsLayout]; [self.view layoutIfNeeded]; [self updateNavigationBarInsets]; - }]; + } + completion:completionBlock]; } #pragma mark - MDCBottomNavigationBarDelegate