From cdacd21dfdffc676cbfe290dbe68f6111c0e850f Mon Sep 17 00:00:00 2001 From: Nobody Date: Mon, 3 Apr 2023 08:02:15 -0700 Subject: [PATCH] [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 --- .../src/MDCBottomNavigationBarController.m | 14 +++++++------- .../src/MDCBottomNavigationBarControllerDelegate.h | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/components/BottomNavigation/src/MDCBottomNavigationBarController.m b/components/BottomNavigation/src/MDCBottomNavigationBarController.m index c2632d719..f94d384dd 100644 --- a/components/BottomNavigation/src/MDCBottomNavigationBarController.m +++ b/components/BottomNavigation/src/MDCBottomNavigationBarController.m @@ -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)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]; + } }]; } diff --git a/components/BottomNavigation/src/MDCBottomNavigationBarControllerDelegate.h b/components/BottomNavigation/src/MDCBottomNavigationBarControllerDelegate.h index f18b26aa4..db49d4e6f 100644 --- a/components/BottomNavigation/src/MDCBottomNavigationBarControllerDelegate.h +++ b/components/BottomNavigation/src/MDCBottomNavigationBarControllerDelegate.h @@ -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