Skip to content
This repository was archived by the owner on Dec 11, 2025. It is now read-only.

Commit 72aeb25

Browse files
Nobodymaterial-automation
authored andcommitted
Don't pin BottomNavigationBar trailing/leading edges to safe area in horizontal mode.
BEGIN_PUBLIC Don't pin BottomNavigationBar trailing/leading edges to safe area in horizontal mode. END_PUBLIC PiperOrigin-RevId: 770227285
1 parent d304ac1 commit 72aeb25

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

components/BottomNavigation/src/MDCBottomNavigationBarController.m

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ @interface MDCBottomNavigationBarController ()
8787
@property(nonatomic, strong, nullable) NSLayoutConstraint *navigationBarBottomAnchorConstraint;
8888

8989
/** The constraint between @c navigationBar.barItemsBottomAnchor and the bottom of the safe area. */
90-
@property(nonatomic, strong, nullable) NSLayoutConstraint *navigationBarItemsBottomAnchorConstraint;
90+
@property(nonatomic, strong, nonnull) NSLayoutConstraint *navigationBarItemsBottomAnchorConstraint;
9191

9292
/** The constraints for the @c navigationBar in a vertical layout. */
9393
@property(nonatomic, strong, nonnull)
9494
NSMutableArray<NSLayoutConstraint *> *navigationBarVerticalLayoutConstraints;
9595

9696
/** The constraint between the leading edge of @c navigationBar and its superview. */
97-
@property(nonatomic, strong, nullable) NSLayoutConstraint *navigationBarLeadingAnchorConstraint;
97+
@property(nonatomic, strong, nonnull) NSLayoutConstraint *navigationBarLeadingAnchorConstraint;
9898

9999
/** The constraints for the @c navigationBar in a horizontal layout. */
100100
@property(nonatomic, strong, nonnull)
@@ -217,7 +217,6 @@ - (void)hideNavigationBarHelper:(BOOL)hidden {
217217
if (!navigationBar.enableVerticalLayout) {
218218
CGFloat height = CGRectGetHeight(navigationBar.frame);
219219
self.navigationBarBottomAnchorConstraint.constant = hidden ? height : 0;
220-
self.navigationBarLeadingAnchorConstraint.constant = 0;
221220
} else {
222221
CGFloat width = CGRectGetWidth(navigationBar.frame);
223222
self.navigationBarBottomAnchorConstraint.constant = 0;
@@ -720,21 +719,24 @@ - (void)loadConstraintsBasedOnRule {
720719

721720
- (void)loadConstraintsForNavigationBar {
722721
self.navigationBar.translatesAutoresizingMaskIntoConstraints = NO;
723-
self.navigationBarLeadingAnchorConstraint = [self.navigationBar.leadingAnchor
724-
constraintEqualToAnchor:self.view.safeAreaLayoutGuide.leadingAnchor];
725-
self.navigationBarLeadingAnchorConstraint.active = YES;
726722
self.navigationBarBottomAnchorConstraint =
727723
[self.navigationBar.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor];
728724
self.navigationBarBottomAnchorConstraint.active = YES;
725+
726+
self.navigationBarLeadingAnchorConstraint = [self.navigationBar.leadingAnchor
727+
constraintEqualToAnchor:self.view.safeAreaLayoutGuide.leadingAnchor];
729728
self.navigationBarItemsBottomAnchorConstraint = [self.navigationBar.barItemsBottomAnchor
730729
constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor];
731730

732731
[self.navigationBarVerticalLayoutConstraints
733732
addObject:[self.navigationBar.topAnchor constraintEqualToAnchor:self.view.topAnchor]];
733+
[self.navigationBarVerticalLayoutConstraints addObject:self.navigationBarLeadingAnchorConstraint];
734734

735735
[self.navigationBarHorizontalLayoutConstraints
736-
addObject:[self.view.safeAreaLayoutGuide.trailingAnchor
736+
addObject:[self.view.trailingAnchor
737737
constraintEqualToAnchor:self.navigationBar.trailingAnchor]];
738+
[self.navigationBarHorizontalLayoutConstraints
739+
addObject:[self.navigationBar.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor]];
738740
[self.navigationBarHorizontalLayoutConstraints
739741
addObject:self.navigationBarItemsBottomAnchorConstraint];
740742
}

0 commit comments

Comments
 (0)