[NavigationSuite] Add delegate API that allows users to set a callback block that is called when the layout changed under automatic mode.

PiperOrigin-RevId: 521460143
This commit is contained in:
Nobody 2023-04-03 08:02:15 -07:00 committed by Material Automation
parent 9d578d398d
commit cdacd21dfd
2 changed files with 21 additions and 7 deletions

View File

@ -238,15 +238,10 @@ static UIViewController *_Nullable DecodeViewController(NSCoder *coder, NSString
if (self.layoutMode != MDCBottomNavigationBarLayoutModeAutomatic) {
return;
}
BOOL shouldUseVerticalLayout = [self useVerticalLayoutAfterTransitioningToSize:size];
if (shouldUseVerticalLayout == self.enableVerticalLayout) {
BOOL enableVerticalLayout = [self useVerticalLayoutAfterTransitioningToSize:size];
if (enableVerticalLayout == self.enableVerticalLayout) {
return;
}
[self enableVerticalLayout:shouldUseVerticalLayout withTransitionCoordinator:coordinator];
}
- (void)enableVerticalLayout:(BOOL)enableVerticalLayout
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
// The setter is not used here since the setter also sets the navigationBar's enableVerticalLayout
// flag and we set that here manually to control animations.
_enableVerticalLayout = enableVerticalLayout;
@ -280,6 +275,11 @@ static UIViewController *_Nullable DecodeViewController(NSCoder *coder, NSString
options:UIViewAnimationOptionCurveEaseOut
animations:lastAnimations
completion:nil];
if ([self.delegate
respondsToSelector:@selector(bottomNavigationBarControllerDidUpdateLayout)]) {
[self.delegate bottomNavigationBarControllerDidUpdateLayout];
}
}];
}

View File

@ -16,6 +16,8 @@
#import "MDCMinimumOS.h" // IWYU pragma: keep
NS_ASSUME_NONNULL_BEGIN
@class MDCBottomNavigationBarController;
/**
@ -43,4 +45,16 @@
(nonnull MDCBottomNavigationBarController *)bottomNavigationBarController
shouldSelectViewController:(nonnull UIViewController *)viewController;
/**
Delegates may implement this method if they want to execute some code right
after the controller changes layout in @c MDCBottomNavigationBarLayoutModeAutomatic
mode.
@warning Do not rely on this method when
@c MDCBottomNavigationBarLayoutModeVertical or
@c MDCBottomNavigationBarLayoutModeHorizontal mode is used.
*/
- (void)bottomNavigationBarControllerDidUpdateLayout;
@end
NS_ASSUME_NONNULL_END