hybrid-navigation 2.8.0 → 2.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## 2.8.3 (2022-05-05)
2
+
3
+ ### Android
4
+
5
+ - 修复 reload 时,会重复 run application 的问题
6
+
7
+ ## 2.8.2 (2022-04-27)
8
+
9
+ ### iOS specific
10
+
11
+ - 修复由于隐藏 back title 而导致 back icon 在转场时表现异常的问题
12
+
13
+ ## 2.8.1 (2022-04-25)
14
+
15
+ ### iOS specific
16
+
17
+ - 优化 `redirectTo` 路由实现,避免在转场过程中执行新的路由动作
18
+
1
19
  ## 2.8.0 (2022-04-13)
2
20
 
3
21
  - 添加 `forceTransparentDialogWindow` 配置项,用于设置当页面是 Dialog 时,是否强制背景透明
@@ -65,6 +65,23 @@ public class HBDReactRootView extends ReactRootView {
65
65
  super.startReactApplication(reactInstanceManager, moduleName, initialProperties);
66
66
  removeOnGlobalLayoutListener();
67
67
  }
68
+
69
+ // 避免 reload 时,重复 run 的问题
70
+ private boolean shouldRunApplication = true;
71
+
72
+ @Override
73
+ public void runApplication() {
74
+ if (shouldRunApplication) {
75
+ shouldRunApplication = false;
76
+ super.runApplication();
77
+ }
78
+ }
79
+
80
+ @Override
81
+ public void setAppProperties(@Nullable Bundle appProperties) {
82
+ shouldRunApplication = true;
83
+ super.setAppProperties(appProperties);
84
+ }
68
85
 
69
86
  @Override
70
87
  public void unmountReactApplication() {
@@ -9,6 +9,7 @@
9
9
  #import "HBDGardenModule.h"
10
10
  #import "HBDReactBridgeManager.h"
11
11
  #import "HBDTabBarController.h"
12
+ #import "GlobalStyle.h"
12
13
  #import <React/RCTLog.h>
13
14
 
14
15
  @interface HBDGardenModule ()
@@ -42,7 +43,7 @@ RCT_EXPORT_MODULE(GardenModule)
42
43
 
43
44
  RCT_EXPORT_METHOD(setStyle:
44
45
  (NSDictionary *) style) {
45
- [HBDGarden createGlobalStyleWithOptions:style];
46
+ [GlobalStyle createWithOptions:style];
46
47
  }
47
48
 
48
49
  RCT_EXPORT_METHOD(setTitleItem:
@@ -10,6 +10,10 @@
10
10
 
11
11
  @interface GlobalStyle : NSObject
12
12
 
13
+ + (void)createWithOptions:(NSDictionary *)options;
14
+
15
+ + (GlobalStyle *)globalStyle;
16
+
13
17
  @property(nonatomic, strong, readonly) UIColor *screenBackgroundColor;
14
18
 
15
19
  @property(nonatomic, assign, readonly, getter=isBackTitleHidden) BOOL backTitleHidden;
@@ -40,6 +40,19 @@
40
40
 
41
41
  @implementation GlobalStyle
42
42
 
43
+ static GlobalStyle *globalStyle;
44
+
45
+ + (void)createWithOptions:(NSDictionary *)options {
46
+ globalStyle = [[GlobalStyle alloc] initWithOptions:options];
47
+ [globalStyle inflateNavigationBar:[UINavigationBar appearance]];
48
+ [globalStyle inflateBarButtonItem:[UIBarButtonItem appearance]];
49
+ [globalStyle inflateTabBar:[UITabBar appearance]];
50
+ }
51
+
52
+ + (GlobalStyle *)globalStyle {
53
+ return globalStyle;
54
+ }
55
+
43
56
  - (instancetype)initWithOptions:(NSDictionary *)options {
44
57
  if (self = [super init]) {
45
58
  _options = options;
@@ -3,10 +3,10 @@
3
3
 
4
4
  #import "HBDBarButtonItem.h"
5
5
  #import "HBDNavigationBar.h"
6
- #import "HBDGarden.h"
7
6
  #import "HBDReactBridgeManager.h"
8
7
 
9
8
  #import "HBDViewController.h"
9
+ #import "HBDViewController+Garden.h"
10
10
  #import "HBDNavigationController.h"
11
11
  #import "HBDTabBarController.h"
12
12
  #import "HBDDrawerController.h"
@@ -67,10 +67,21 @@
67
67
  resolve(@(NO));
68
68
  return;
69
69
  }
70
+
71
+ if (nav.transitionCoordinator) {
72
+ __weak typeof(self) selfObj = self;
73
+ [nav.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
74
+
75
+ } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
76
+ [selfObj handleNavigationWithViewController:target action:action extras:extras resolver:resolve rejecter:reject];
77
+ }];
78
+ return;
79
+ }
70
80
 
71
81
  if (!nav.hbd_viewAppeared) {
82
+ __weak typeof(self) selfObj = self;
72
83
  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
73
- [self handleNavigationWithViewController:target action:action extras:extras resolver:resolve rejecter:reject];
84
+ [selfObj handleNavigationWithViewController:target action:action extras:extras resolver:resolve rejecter:reject];
74
85
  });
75
86
  return;
76
87
  }
@@ -10,6 +10,7 @@
10
10
  #import "HBDTabBarController.h"
11
11
  #import "HBDReactBridgeManager.h"
12
12
  #import "HBDUtils.h"
13
+ #import "GlobalStyle.h"
13
14
  #import <React/RCTUtils.h>
14
15
 
15
16
  @implementation HBDTabNavigator
@@ -45,7 +46,7 @@
45
46
  tabBarOptions[@"tabBarModuleName"] = tabBarModuleName;
46
47
  tabBarOptions[@"sizeIndeterminate"] = @([options[@"sizeIndeterminate"] boolValue]);
47
48
  tabBarOptions[@"selectedIndex"] = options[@"selectedIndex"] ?: @(0);
48
- GlobalStyle *style = [HBDGarden globalStyle];
49
+ GlobalStyle *style = [GlobalStyle globalStyle];
49
50
  tabBarOptions[@"tabBarItemColor"] = style.tabBarItemColorHexString;
50
51
  tabBarOptions[@"tabBarUnselectedItemColor"] = style.tabBarUnselectedItemColorHexString;
51
52
  tabBarOptions[@"badgeColor"] = style.badgeColorHexString;
@@ -10,10 +10,9 @@
10
10
 
11
11
  @interface HBDNavigationBar : UINavigationBar
12
12
 
13
- @property(nonatomic, strong, readonly) UIImageView *shadowImageView;
14
- @property(nonatomic, strong, readonly) UIVisualEffectView *fakeView;
13
+ @property(nonatomic, strong, readonly) UIImageView *fakeShadowView;
14
+ @property(nonatomic, strong, readonly) UIView *fakeBackgroundView;
15
15
  @property(nonatomic, strong, readonly) UILabel *backButtonLabel;
16
- @property(nonatomic, strong, readonly) UIView *hbd_backgroundView;
17
16
 
18
17
  @end
19
18
 
@@ -11,8 +11,8 @@
11
11
 
12
12
  @interface HBDNavigationBar ()
13
13
 
14
- @property(nonatomic, strong, readwrite) UIImageView *shadowImageView;
15
- @property(nonatomic, strong, readwrite) UIVisualEffectView *fakeView;
14
+ @property(nonatomic, strong, readwrite) UIImageView *fakeShadowView;
15
+ @property(nonatomic, strong, readwrite) UIView *fakeBackgroundView;
16
16
 
17
17
  @end
18
18
 
@@ -45,7 +45,7 @@
45
45
 
46
46
  NSArray *array = @[@"UINavigationBarContentView", @"UIButtonBarStackView", @"HBDNavigationBar"];
47
47
  if ([array containsObject:viewName]) {
48
- if (self.fakeView.alpha < 0.01) {
48
+ if (self.fakeBackgroundView.alpha < 0.01) {
49
49
  return nil;
50
50
  }
51
51
  }
@@ -59,29 +59,25 @@
59
59
 
60
60
  - (void)layoutSubviews {
61
61
  [super layoutSubviews];
62
- self.fakeView.frame = self.fakeView.superview.bounds;
63
- self.shadowImageView.frame = CGRectMake(0, CGRectGetHeight(self.shadowImageView.superview.bounds), CGRectGetWidth(self.shadowImageView.superview.bounds), 0.5);
64
- }
65
-
66
- - (UIView *)hbd_backgroundView {
67
- return [self valueForKey:@"_backgroundView"];
62
+ self.fakeBackgroundView.frame = self.fakeBackgroundView.superview.bounds;
63
+ self.fakeShadowView.frame = CGRectMake(0, CGRectGetHeight(self.fakeShadowView.superview.bounds), CGRectGetWidth(self.fakeShadowView.superview.bounds), 0.5);
68
64
  }
69
65
 
70
66
  - (void)setBarTintColor:(UIColor *)barTintColor {
71
67
  [super setBarTintColor:barTintColor];
72
- self.fakeView.subviews.lastObject.backgroundColor = barTintColor;
73
- [self makeSureFakeView];
68
+ self.fakeBackgroundView.backgroundColor = barTintColor;
69
+ [self makesureFakeBackgroundView];
74
70
  }
75
71
 
76
- - (UIVisualEffectView *)fakeView {
77
- if (!_fakeView) {
72
+ - (UIView *)fakeBackgroundView {
73
+ if (!_fakeBackgroundView) {
78
74
  [super setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
79
- _fakeView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
80
- _fakeView.userInteractionEnabled = NO;
81
- _fakeView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
82
- [[self.subviews firstObject] insertSubview:_fakeView atIndex:0];
75
+ _fakeBackgroundView = [[UIView alloc] init];
76
+ _fakeBackgroundView.userInteractionEnabled = NO;
77
+ _fakeBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
78
+ [[self.subviews firstObject] insertSubview:_fakeBackgroundView atIndex:0];
83
79
  }
84
- return _fakeView;
80
+ return _fakeBackgroundView;
85
81
  }
86
82
 
87
83
  - (void)setTranslucent:(BOOL)translucent {
@@ -94,35 +90,35 @@
94
90
  }
95
91
 
96
92
  - (void)setShadowImage:(UIImage *)shadowImage {
97
- self.shadowImageView.image = shadowImage;
93
+ self.fakeShadowView.image = shadowImage;
98
94
  if (shadowImage) {
99
- self.shadowImageView.backgroundColor = nil;
95
+ self.fakeShadowView.backgroundColor = nil;
100
96
  } else {
101
- self.shadowImageView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:77.0 / 255];
97
+ self.fakeShadowView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:77.0 / 255];
102
98
  }
103
99
  }
104
100
 
105
- - (UIImageView *)shadowImageView {
106
- if (!_shadowImageView) {
101
+ - (UIImageView *)fakeShadowView {
102
+ if (!_fakeShadowView) {
107
103
  [super setShadowImage:[UIImage new]];
108
- _shadowImageView = [[UIImageView alloc] init];
109
- _shadowImageView.userInteractionEnabled = NO;
110
- _shadowImageView.contentScaleFactor = 1;
111
- [[self.subviews firstObject] insertSubview:_shadowImageView aboveSubview:self.fakeView];
104
+ _fakeShadowView = [[UIImageView alloc] init];
105
+ _fakeShadowView.userInteractionEnabled = NO;
106
+ _fakeShadowView.contentScaleFactor = 1;
107
+ [[self.subviews firstObject] insertSubview:_fakeShadowView aboveSubview:self.fakeBackgroundView];
112
108
  }
113
- return _shadowImageView;
109
+ return _fakeShadowView;
114
110
  }
115
111
 
116
- - (void)makeSureFakeView {
112
+ - (void)makesureFakeBackgroundView {
117
113
  [UIView setAnimationsEnabled:NO];
118
- if (!self.fakeView.superview) {
119
- [[self.subviews firstObject] insertSubview:_fakeView atIndex:0];
120
- self.fakeView.frame = self.fakeView.superview.bounds;
114
+ if (!self.fakeBackgroundView.superview) {
115
+ [[self.subviews firstObject] insertSubview:_fakeBackgroundView atIndex:0];
116
+ self.fakeBackgroundView.frame = self.fakeBackgroundView.superview.bounds;
121
117
  }
122
118
 
123
- if (!self.shadowImageView.superview) {
124
- [[self.subviews firstObject] insertSubview:_shadowImageView aboveSubview:self.fakeView];
125
- self.shadowImageView.frame = CGRectMake(0, CGRectGetHeight(self.shadowImageView.superview.bounds), CGRectGetWidth(self.shadowImageView.superview.bounds), 0.5);
119
+ if (!self.fakeShadowView.superview) {
120
+ [[self.subviews firstObject] insertSubview:_fakeShadowView aboveSubview:self.fakeBackgroundView];
121
+ self.fakeShadowView.frame = CGRectMake(0, CGRectGetHeight(self.fakeShadowView.superview.bounds), CGRectGetWidth(self.fakeShadowView.superview.bounds), 0.5);
126
122
  }
127
123
  [UIView setAnimationsEnabled:YES];
128
124
  }
@@ -11,6 +11,7 @@
11
11
  #import "HBDModalViewController.h"
12
12
  #import "HBDRootView.h"
13
13
  #import "HBDUtils.h"
14
+ #import "HBDViewController+Garden.h"
14
15
 
15
16
  @interface UIViewController ()
16
17
 
@@ -450,7 +451,7 @@
450
451
  modalViewController.contentViewController = vc;
451
452
  if ([vc isKindOfClass:[HBDViewController class]]) {
452
453
  HBDViewController *hbdvc = (HBDViewController *)vc;
453
- if (hbdvc.garden.forceTransparentDialogWindow) {
454
+ if (hbdvc.forceTransparentDialogWindow) {
454
455
  modalViewController.dimmingView.backgroundColor = UIColor.clearColor;
455
456
  }
456
457
  }
@@ -10,6 +10,7 @@
10
10
  #import "HBDViewController.h"
11
11
  #import "HBDNavigationBar.h"
12
12
  #import "HBDUtils.h"
13
+ #import "GlobalStyle.h"
13
14
  #import "HBDPushAnimation.h"
14
15
  #import "HBDPopAnimation.h"
15
16
  #import <React/RCTLog.h>
@@ -79,8 +80,8 @@ void printViewHierarchy(UIView *view, NSString *prefix) {
79
80
  @interface HBDNavigationController ()
80
81
 
81
82
  @property(nonatomic, readonly) HBDNavigationBar *navigationBar;
82
- @property(nonatomic, strong) UIVisualEffectView *fromFakeBar;
83
- @property(nonatomic, strong) UIVisualEffectView *toFakeBar;
83
+ @property(nonatomic, strong) UIView *fromFakeBar;
84
+ @property(nonatomic, strong) UIView *toFakeBar;
84
85
  @property(nonatomic, strong) UIImageView *fromFakeShadow;
85
86
  @property(nonatomic, strong) UIImageView *toFakeShadow;
86
87
  @property(nonatomic, weak) UIViewController *poppingViewController;
@@ -402,7 +403,7 @@ void printViewHierarchy(UIView *view, NSString *prefix) {
402
403
  }
403
404
 
404
405
  - (BOOL)shouldShowFakeBarFrom:(UIViewController *)from to:(UIViewController *)to viewController:(UIViewController *_Nonnull)viewController {
405
- if ([HBDGarden globalStyle].alwaysSplitNavigationBarTransition && to == viewController) {
406
+ if ([GlobalStyle globalStyle].alwaysSplitNavigationBarTransition && to == viewController) {
406
407
  return YES;
407
408
  }
408
409
 
@@ -635,14 +636,8 @@ void printViewHierarchy(UIView *view, NSString *prefix) {
635
636
  }
636
637
 
637
638
  - (void)updateNavigationBarAlphaForViewController:(UIViewController *)vc {
638
- self.navigationBar.fakeView.alpha = vc.hbd_barAlpha;
639
- self.navigationBar.shadowImageView.alpha = vc.hbd_barShadowAlpha;
640
-
641
- if (vc.hbd_barAlpha == 0) {
642
- self.navigationBar.hbd_backgroundView.layer.mask = [CALayer new];
643
- } else {
644
- self.navigationBar.hbd_backgroundView.layer.mask = nil;
645
- }
639
+ self.navigationBar.fakeBackgroundView.alpha = vc.hbd_barAlpha;
640
+ self.navigationBar.fakeShadowView.alpha = vc.hbd_barShadowAlpha;
646
641
  }
647
642
 
648
643
  - (void)updateNavigationBarBackgroundForViewController:(UIViewController *)vc {
@@ -651,19 +646,16 @@ void printViewHierarchy(UIView *view, NSString *prefix) {
651
646
 
652
647
  - (void)showFakeBarFrom:(UIViewController *)from to:(UIViewController *_Nonnull)to {
653
648
  [UIView setAnimationsEnabled:NO];
654
- self.navigationBar.fakeView.alpha = 0;
655
- self.navigationBar.shadowImageView.alpha = 0;
649
+ self.navigationBar.fakeBackgroundView.alpha = 0;
650
+ self.navigationBar.fakeShadowView.alpha = 0;
656
651
  [self showFakeBarFrom:from];
657
652
  [self showFakeBarTo:to];
658
653
  [UIView setAnimationsEnabled:YES];
659
654
  }
660
655
 
661
656
  - (void)showFakeBarFrom:(UIViewController *)from {
662
- self.fromFakeBar.subviews.lastObject.backgroundColor = from.hbd_barTintColor;
657
+ self.fromFakeBar.backgroundColor = from.hbd_barTintColor;
663
658
  self.fromFakeBar.alpha = from.hbd_barAlpha;
664
- if (from.hbd_barAlpha == 0) {
665
- self.fromFakeBar.subviews.lastObject.layer.mask = [CALayer new];
666
- }
667
659
  self.fromFakeBar.frame = [self fakeBarFrameForViewController:from];
668
660
  [from.view addSubview:self.fromFakeBar];
669
661
  self.fromFakeShadow.alpha = from.hbd_barShadowAlpha;
@@ -672,7 +664,7 @@ void printViewHierarchy(UIView *view, NSString *prefix) {
672
664
  }
673
665
 
674
666
  - (void)showFakeBarTo:(UIViewController *_Nonnull)to {
675
- self.toFakeBar.subviews.lastObject.backgroundColor = to.hbd_barTintColor;
667
+ self.toFakeBar.backgroundColor = to.hbd_barTintColor;
676
668
  self.toFakeBar.alpha = to.hbd_barAlpha;
677
669
  self.toFakeBar.frame = [self fakeBarFrameForViewController:to];
678
670
  [to.view addSubview:self.toFakeBar];
@@ -681,32 +673,32 @@ void printViewHierarchy(UIView *view, NSString *prefix) {
681
673
  [to.view addSubview:self.toFakeShadow];
682
674
  }
683
675
 
684
- - (UIVisualEffectView *)fromFakeBar {
676
+ - (UIView *)fromFakeBar {
685
677
  if (!_fromFakeBar) {
686
- _fromFakeBar = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
678
+ _fromFakeBar = [[UIView alloc] init];
687
679
  }
688
680
  return _fromFakeBar;
689
681
  }
690
682
 
691
- - (UIVisualEffectView *)toFakeBar {
683
+ - (UIView *)toFakeBar {
692
684
  if (!_toFakeBar) {
693
- _toFakeBar = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
685
+ _toFakeBar = [[UIView alloc] init];
694
686
  }
695
687
  return _toFakeBar;
696
688
  }
697
689
 
698
690
  - (UIImageView *)fromFakeShadow {
699
691
  if (!_fromFakeShadow) {
700
- _fromFakeShadow = [[UIImageView alloc] initWithImage:self.navigationBar.shadowImageView.image];
701
- _fromFakeShadow.backgroundColor = self.navigationBar.shadowImageView.backgroundColor;
692
+ _fromFakeShadow = [[UIImageView alloc] initWithImage:self.navigationBar.fakeShadowView.image];
693
+ _fromFakeShadow.backgroundColor = self.navigationBar.fakeShadowView.backgroundColor;
702
694
  }
703
695
  return _fromFakeShadow;
704
696
  }
705
697
 
706
698
  - (UIImageView *)toFakeShadow {
707
699
  if (!_toFakeShadow) {
708
- _toFakeShadow = [[UIImageView alloc] initWithImage:self.navigationBar.shadowImageView.image];
709
- _toFakeShadow.backgroundColor = self.navigationBar.shadowImageView.backgroundColor;
700
+ _toFakeShadow = [[UIImageView alloc] initWithImage:self.navigationBar.fakeShadowView.image];
701
+ _toFakeShadow.backgroundColor = self.navigationBar.fakeShadowView.backgroundColor;
710
702
  }
711
703
  return _toFakeShadow;
712
704
  }
@@ -0,0 +1,21 @@
1
+ #import "HBDViewController.h"
2
+
3
+ NS_ASSUME_NONNULL_BEGIN
4
+
5
+ @interface HBDViewController (Garden)
6
+
7
+ @property(nonatomic, assign) BOOL forceTransparentDialogWindow;
8
+
9
+ - (void)setLeftBarButtonItem:(NSDictionary *)item;
10
+
11
+ - (void)setRightBarButtonItem:(NSDictionary *)item;
12
+
13
+ - (void)setLeftBarButtonItems:(NSArray *)items;
14
+
15
+ - (void)setRightBarButtonItems:(NSArray *)items;
16
+
17
+ - (void)setPassThroughTouches:(BOOL)passThrough;
18
+
19
+ @end
20
+
21
+ NS_ASSUME_NONNULL_END
@@ -1,49 +1,24 @@
1
- //
2
- // HBDGarden.m
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2017/11/26.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
- #import "HBDGarden.h"
10
1
  #import <React/RCTConvert.h>
11
2
  #import <React/RCTRootView.h>
12
3
 
4
+ #import "HBDViewController+Garden.h"
5
+
13
6
  #import "HBDBarButtonItem.h"
14
7
  #import "HBDUtils.h"
15
8
  #import "HBDEventEmitter.h"
16
9
 
10
+ @implementation HBDViewController (Garden)
17
11
 
18
- @interface HBDGarden ()
19
-
20
- @property(nonatomic, weak, readonly) HBDViewController *viewController;
21
-
22
- @end
23
-
24
- @implementation HBDGarden
25
-
26
- static GlobalStyle *globalStyle;
27
-
28
- + (void)createGlobalStyleWithOptions:(NSDictionary *)options {
29
- globalStyle = [[GlobalStyle alloc] initWithOptions:options];
30
- [globalStyle inflateNavigationBar:[UINavigationBar appearance]];
31
- [globalStyle inflateBarButtonItem:[UIBarButtonItem appearance]];
32
- [globalStyle inflateTabBar:[UITabBar appearance]];
12
+ - (BOOL)forceTransparentDialogWindow {
13
+ id obj = objc_getAssociatedObject(self, _cmd);
14
+ return obj ? [obj boolValue] : NO;
33
15
  }
34
16
 
35
- + (GlobalStyle *)globalStyle {
36
- return globalStyle;
17
+ - (void)setForceTransparentDialogWindow:(BOOL)transparent {
18
+ objc_setAssociatedObject(self, @selector(forceTransparentDialogWindow), @(transparent), OBJC_ASSOCIATION_COPY_NONATOMIC);
37
19
  }
38
20
 
39
- - (instancetype)initWithViewController:(HBDViewController *)vc {
40
- if (self = [super init]) {
41
- _viewController = vc;
42
- }
43
- return self;
44
- }
45
-
46
- - (void)setLeftBarButtonItem:(NSDictionary *__nullable)item {
21
+ - (void)setLeftBarButtonItem:(NSDictionary *)item {
47
22
  if (item) {
48
23
  NSMutableArray *array = [[NSMutableArray alloc] init];
49
24
  if (@available(iOS 11.0, *)) {
@@ -61,13 +36,13 @@ static GlobalStyle *globalStyle;
61
36
  }
62
37
  [array addObject:buttonItem];
63
38
 
64
- self.viewController.navigationItem.leftBarButtonItems = array;
39
+ self.navigationItem.leftBarButtonItems = array;
65
40
  } else {
66
- self.viewController.navigationItem.leftBarButtonItems = nil;
41
+ self.navigationItem.leftBarButtonItems = nil;
67
42
  }
68
43
  }
69
44
 
70
- - (void)setRightBarButtonItem:(NSDictionary *__nullable)item {
45
+ - (void)setRightBarButtonItem:(NSDictionary *)item {
71
46
  if (item) {
72
47
  NSMutableArray *array = [[NSMutableArray alloc] init];
73
48
  if (@available(iOS 11.0, *)) {
@@ -85,9 +60,9 @@ static GlobalStyle *globalStyle;
85
60
  }
86
61
  [array addObject:buttonItem];
87
62
 
88
- self.viewController.navigationItem.rightBarButtonItems = array;
63
+ self.navigationItem.rightBarButtonItems = array;
89
64
  } else {
90
- self.viewController.navigationItem.rightBarButtonItems = nil;
65
+ self.navigationItem.rightBarButtonItems = nil;
91
66
  }
92
67
  }
93
68
 
@@ -113,7 +88,7 @@ static GlobalStyle *globalStyle;
113
88
  }
114
89
  }
115
90
 
116
- self.viewController.navigationItem.leftBarButtonItems = array;
91
+ self.navigationItem.leftBarButtonItems = array;
117
92
  }
118
93
  }
119
94
 
@@ -138,7 +113,7 @@ static GlobalStyle *globalStyle;
138
113
  }
139
114
  }
140
115
 
141
- self.viewController.navigationItem.rightBarButtonItems = array;
116
+ self.navigationItem.rightBarButtonItems = array;
142
117
  }
143
118
  }
144
119
 
@@ -181,7 +156,7 @@ static GlobalStyle *globalStyle;
181
156
  }
182
157
 
183
158
  NSString *action = item[@"action"];
184
- NSString *sceneId = self.viewController.sceneId;
159
+ NSString *sceneId = self.sceneId;
185
160
 
186
161
  NSString *tintColor = item[@"tintColor"];
187
162
  if (tintColor) {
@@ -206,11 +181,10 @@ static GlobalStyle *globalStyle;
206
181
  }
207
182
 
208
183
  - (void)setPassThroughTouches:(BOOL)passThrough {
209
- if ([self.viewController.view isKindOfClass:[RCTRootView class]]) {
210
- RCTRootView *rootView = (RCTRootView *) self.viewController.view;
184
+ if ([self.view isKindOfClass:[RCTRootView class]]) {
185
+ RCTRootView *rootView = (RCTRootView *) self.view;
211
186
  rootView.passThroughTouches = passThrough;
212
187
  }
213
188
  }
214
189
 
215
190
  @end
216
-
@@ -8,16 +8,12 @@
8
8
 
9
9
  #import <UIKit/UIKit.h>
10
10
  #import "UIViewController+HBD.h"
11
- #import "HBDGarden.h"
12
-
13
- @class HBDGarden;
14
11
 
15
12
  @interface HBDViewController : UIViewController
16
13
 
17
14
  @property(nonatomic, copy, readonly) NSString *moduleName;
18
15
  @property(nonatomic, copy, readonly) NSDictionary *props;
19
- @property(nonatomic, copy) NSDictionary *options;
20
- @property(nonatomic, strong, readonly) HBDGarden *garden;
16
+ @property(nonatomic, copy, readonly) NSDictionary *options;
21
17
 
22
18
  - (instancetype)initWithModuleName:(NSString *)moduleName props:(NSDictionary *)props options:(NSDictionary *)options NS_DESIGNATED_INITIALIZER;
23
19
 
@@ -6,14 +6,17 @@
6
6
  // Copyright © 2018年 Listen. All rights reserved.
7
7
  //
8
8
 
9
+ #import <React/RCTLog.h>
10
+
9
11
  #import "HBDViewController.h"
12
+ #import "HBDViewController+Garden.h"
10
13
  #import "HBDUtils.h"
11
- #import <React/RCTLog.h>
14
+ #import "GlobalStyle.h"
12
15
 
13
16
  @interface HBDViewController ()
14
17
 
15
18
  @property(nonatomic, copy, readwrite) NSDictionary *props;
16
- @property(nonatomic, strong, readwrite) HBDGarden *garden;
19
+ @property(nonatomic, copy, readwrite) NSDictionary *options;
17
20
 
18
21
  @end
19
22
 
@@ -36,8 +39,8 @@
36
39
  _moduleName = moduleName;
37
40
  _options = options;
38
41
  _props = props;
39
- _garden = [[HBDGarden alloc] initWithViewController:self];
40
- _garden.forceTransparentDialogWindow = [options[@"forceTransparentDialogWindow"] boolValue];
42
+
43
+ self.forceTransparentDialogWindow = [options[@"forceTransparentDialogWindow"] boolValue];
41
44
  [self applyNavigationBarOptions:options];
42
45
  [self applyTabBarOptions:options];
43
46
  }
@@ -100,7 +103,7 @@
100
103
  if (screenColor) {
101
104
  self.view.backgroundColor = [HBDUtils colorWithHexString:screenColor];
102
105
  } else {
103
- self.view.backgroundColor = [HBDGarden globalStyle].screenBackgroundColor;
106
+ self.view.backgroundColor = [GlobalStyle globalStyle].screenBackgroundColor;
104
107
  }
105
108
  }
106
109
 
@@ -170,15 +173,15 @@
170
173
  self.hbd_barHidden = YES;
171
174
  }
172
175
 
173
- if ([HBDGarden globalStyle].isBackTitleHidden) {
174
- self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:NULL];
176
+ if ([GlobalStyle globalStyle].isBackTitleHidden) {
177
+ UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:NULL];
178
+ self.navigationItem.backBarButtonItem = buttonItem;
175
179
  }
176
180
 
177
181
  NSDictionary *backItem = options[@"backItemIOS"];
178
182
  if (backItem) {
179
- NSString *title = backItem[@"title"];
180
183
  UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];
181
- backButton.title = title;
184
+ backButton.title = backItem[@"title"];
182
185
  NSString *tintColor = backItem[@"tintColor"];
183
186
  if (tintColor) {
184
187
  backButton.tintColor = [HBDUtils colorWithHexString:tintColor];
@@ -238,22 +241,22 @@
238
241
 
239
242
  id rightBarButtonItem = options[@"rightBarButtonItem"];
240
243
  if (rightBarButtonItem) {
241
- [self.garden setRightBarButtonItem:RCTNilIfNull(rightBarButtonItem)];
244
+ [self setRightBarButtonItem:RCTNilIfNull(rightBarButtonItem)];
242
245
  }
243
246
 
244
247
  id leftBarButtonItem = options[@"leftBarButtonItem"];
245
248
  if (leftBarButtonItem) {
246
- [self.garden setLeftBarButtonItem:RCTNilIfNull(leftBarButtonItem)];
249
+ [self setLeftBarButtonItem:RCTNilIfNull(leftBarButtonItem)];
247
250
  }
248
251
 
249
252
  NSArray *rightBarButtonItems = options[@"rightBarButtonItems"];
250
253
  if (rightBarButtonItems) {
251
- [self.garden setRightBarButtonItems:rightBarButtonItems];
254
+ [self setRightBarButtonItems:rightBarButtonItems];
252
255
  }
253
256
 
254
257
  NSArray *leftBarButtonItems = options[@"leftBarButtonItems"];
255
258
  if (leftBarButtonItems) {
256
- [self.garden setLeftBarButtonItems:leftBarButtonItems];
259
+ [self setLeftBarButtonItems:leftBarButtonItems];
257
260
  }
258
261
  }
259
262
 
@@ -303,7 +306,7 @@
303
306
 
304
307
  NSNumber *passThroughTouches = options[@"passThroughTouches"];
305
308
  if (passThroughTouches) {
306
- [self.garden setPassThroughTouches:[passThroughTouches boolValue]];
309
+ [self setPassThroughTouches:[passThroughTouches boolValue]];
307
310
  }
308
311
 
309
312
  if ([self shouldUpdateNavigationBar:options compareTo:previous]) {
@@ -16,15 +16,12 @@
16
16
 
17
17
  - (void)redirectToViewController:(UIViewController *)controller target:(UIViewController *)target animated:(BOOL)animated {
18
18
  NSMutableArray *children = [self.childViewControllers mutableCopy];
19
- NSUInteger count = self.childViewControllers.count;
20
- for (NSUInteger i = count; i > 0; i--) {
21
- NSUInteger index = i - 1;
22
- UIViewController *child = children[index];
23
- [children removeObjectAtIndex:index];
24
- if (child == target) {
25
- break;
26
- }
19
+ NSUInteger index = [children indexOfObject:target];
20
+ if (index == NSNotFound) {
21
+ return;
27
22
  }
23
+ NSUInteger count = self.childViewControllers.count;
24
+ [children removeObjectsInRange:NSMakeRange(index, count - index)];
28
25
  [children addObject:controller];
29
26
  if (children.count > 1) {
30
27
  controller.hidesBottomBarWhenPushed = self.hidesBottomBarWhenPushed;
@@ -6,14 +6,17 @@
6
6
  // Copyright © 2018年 Listen. All rights reserved.
7
7
  //
8
8
 
9
- #import "UIViewController+HBD.h"
10
9
  #import <objc/runtime.h>
11
- #import "HBDNavigationController.h"
12
- #import "HBDUtils.h"
13
- #import "HBDModalViewController.h"
14
10
  #import <React/RCTLog.h>
11
+
12
+ #import "UIViewController+HBD.h"
15
13
  #import "UITabBar+Badge.h"
16
14
 
15
+ #import "HBDNavigationController.h"
16
+ #import "HBDModalViewController.h"
17
+ #import "HBDUtils.h"
18
+ #import "GlobalStyle.h"
19
+
17
20
  @implementation UIViewController (HBD)
18
21
 
19
22
  + (void)load {
@@ -122,7 +125,7 @@
122
125
  color = obj;
123
126
  }
124
127
 
125
- UIColor *colorWithBarStyle = [[HBDGarden globalStyle] barTintColorWithBarStyle:self.hbd_barStyle];
128
+ UIColor *colorWithBarStyle = [[GlobalStyle globalStyle] barTintColorWithBarStyle:self.hbd_barStyle];
126
129
  if (color == nil && colorWithBarStyle != nil) {
127
130
  color = colorWithBarStyle;
128
131
  }
@@ -148,7 +151,7 @@
148
151
  return obj;
149
152
  }
150
153
 
151
- UIColor *colorWithBarStyle = [[HBDGarden globalStyle] tintColorWithBarStyle:self.hbd_barStyle];
154
+ UIColor *colorWithBarStyle = [[GlobalStyle globalStyle] tintColorWithBarStyle:self.hbd_barStyle];
152
155
  if (colorWithBarStyle) {
153
156
  return colorWithBarStyle;
154
157
  }
@@ -167,7 +170,7 @@
167
170
  }
168
171
 
169
172
  UIBarStyle barStyle = self.hbd_barStyle;
170
- UIColor *colorWithBarStyle = [[HBDGarden globalStyle] titleTextColorWithBarStyle:barStyle];
173
+ UIColor *colorWithBarStyle = [[GlobalStyle globalStyle] titleTextColorWithBarStyle:barStyle];
171
174
  NSDictionary *colorAttributes = @{NSForegroundColorAttributeName: colorWithBarStyle};
172
175
  NSDictionary *attributes = [UINavigationBar appearance].titleTextAttributes;
173
176
  if (attributes) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hybrid-navigation",
3
3
  "description": "React Native Navigation that supports seamless navigation between Native and React.",
4
- "version": "2.8.0",
4
+ "version": "2.8.3",
5
5
  "keywords": [
6
6
  "react-native",
7
7
  "navigation",
@@ -1,38 +0,0 @@
1
- //
2
- // HBDGarden.h
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2017/11/26.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
- #import <UIKit/UIKit.h>
10
- #import "HBDViewController.h"
11
- #import "GlobalStyle.h"
12
-
13
- @class HBDViewController;
14
-
15
- @interface HBDGarden : NSObject
16
-
17
- + (void)createGlobalStyleWithOptions:(NSDictionary *)options;
18
-
19
- + (GlobalStyle *)globalStyle;
20
-
21
- // ------
22
-
23
- @property(nonatomic, assign) BOOL forceTransparentDialogWindow;
24
-
25
- - (instancetype)initWithViewController:(HBDViewController *)vc;
26
-
27
- - (void)setLeftBarButtonItem:(NSDictionary *)item;
28
-
29
- - (void)setRightBarButtonItem:(NSDictionary *)item;
30
-
31
- - (void)setLeftBarButtonItems:(NSArray *)items;
32
-
33
- - (void)setRightBarButtonItems:(NSArray *)items;
34
-
35
- - (void)setPassThroughTouches:(BOOL)passThrough;
36
-
37
-
38
- @end