Skip to content

Commit

Permalink
feat: NXNavigationBar 支持 semanticContentAttribute 属性,方便从右往左的导航栏布局。
Browse files Browse the repository at this point in the history
  • Loading branch information
l1Dan committed Dec 15, 2021
1 parent b3aecaa commit 6eeecda
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion NXNavigationExtension.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
D61CCBF3251A13F100A91580 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1310;
LastUpgradeCheck = 1320;
ORGANIZATIONNAME = "";
TargetAttributes = {
D64039C8273CB13F0047F25E = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1310"
LastUpgradeVersion = "1320"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1310"
LastUpgradeVersion = "1320"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
11 changes: 11 additions & 0 deletions NXNavigationExtension/Core/NXNavigationBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,24 @@ - (void)setUserInteractionEnabled:(BOOL)userInteractionEnabled {
self.contentView.userInteractionEnabled = userInteractionEnabled;
}

- (void)setSemanticContentAttribute:(UISemanticContentAttribute)semanticContentAttribute {
[super setSemanticContentAttribute:semanticContentAttribute];
[self setSubviewsSemanticContentAttribute:semanticContentAttribute];
}

#pragma mark - Private

- (void)setBlurEffectEnabled:(BOOL)blurEffectEnabled {
_blurEffectEnabled = blurEffectEnabled;
[self setBackgroundColor:self.originalBackgroundColor];
}

- (void)setSubviewsSemanticContentAttribute:(UISemanticContentAttribute)semanticContentAttribute {
for (UIView *subview in self.subviews) {
subview.semanticContentAttribute = semanticContentAttribute;
}
}

/// 更新导航栏 frame
/// @param callSuper 是否需要调用 super setFrame: 方法
- (void)updateNavigationBarFrame:(CGRect)frame callSuper:(BOOL)callSuper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ - (void)nx_updateNavigationBarAppearance {
[self.navigationController nx_configureNavigationBar];

self.nx_navigationBar.backgroundColor = self.nx_navigationBarBackgroundColor;
self.nx_navigationBar.semanticContentAttribute = self.navigationController.navigationBar.semanticContentAttribute;
self.nx_navigationBar.shadowImageView.image = self.nx_shadowImage;

if (self.nx_shadowImageTintColor) {
Expand Down Expand Up @@ -325,7 +326,6 @@ - (void)nx_updateNavigationBarSubviewState {
self.navigationController.navigationBar.nx_userInteractionEnabled = !systemNavigationBarUserInteractionDisabled;
self.navigationController.navigationBar.userInteractionEnabled = !systemNavigationBarUserInteractionDisabled;
}

}
}

Expand Down
13 changes: 8 additions & 5 deletions NXNavigationExtension/Private/NXNavigationExtensionInternal.m
Original file line number Diff line number Diff line change
Expand Up @@ -556,15 +556,18 @@ - (void)nx_configureNavigationBarWithNavigationController:(__kindof UINavigation
if (customView) {
backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:customView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(nx_triggerSystemPopViewController)];
customView.semanticContentAttribute = navigationController.navigationBar.semanticContentAttribute;
customView.userInteractionEnabled = YES;
[customView addGestureRecognizer:tap];
self.nx_customBackButtonItem = backButtonItem;
} else {
UIImage *backImage = self.nx_backImage;
UIImage *landscapeBackImage = self.nx_backImage;
backButtonItem = [[UIBarButtonItem alloc] initWithImage:backImage landscapeImagePhone:landscapeBackImage style:UIBarButtonItemStylePlain target:self action:@selector(nx_triggerSystemPopViewController)];
backButtonItem.imageInsets = navigationController.nx_backImageInsets;
backButtonItem.landscapeImagePhoneInsets = navigationController.nx_landscapeBackImageInsets;
BOOL isRightToLeft = navigationController.navigationBar.semanticContentAttribute == UISemanticContentAttributeForceRightToLeft;
SEL selector = @selector(nx_triggerSystemPopViewController);
UIImage *backImage = isRightToLeft ? self.nx_backImage.imageFlippedForRightToLeftLayoutDirection : self.nx_backImage;
UIImage *landscapeBackImage = isRightToLeft ? self.nx_landscapeBackImage.imageFlippedForRightToLeftLayoutDirection : self.nx_landscapeBackImage;
backButtonItem = [[UIBarButtonItem alloc] initWithImage:backImage landscapeImagePhone:landscapeBackImage style:UIBarButtonItemStylePlain target:self action:selector];
backButtonItem.imageInsets = self.nx_backImageInsets;
backButtonItem.landscapeImagePhoneInsets = self.nx_landscapeBackImageInsets;
self.nx_customBackButtonItem = backButtonItem;
}
self.navigationItem.leftBarButtonItem = backButtonItem;
Expand Down

0 comments on commit 6eeecda

Please sign in to comment.