Skip to content

Commit

Permalink
Honor the animated param when changing the hidden state of the bott…
Browse files Browse the repository at this point in the history
…om navigation bar.

PiperOrigin-RevId: 357221948
  • Loading branch information
Nobody authored and material-automation committed Feb 12, 2021
1 parent 3404e87 commit cdf7ffc
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions components/BottomNavigation/src/MDCBottomNavigationBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cdf7ffc

Please sign in to comment.