hybrid-navigation 2.12.4 → 2.13.0-beta.2

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.
Files changed (85) hide show
  1. package/README.md +63 -0
  2. package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +6 -2
  3. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +29 -30
  4. package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +2 -3
  5. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +4 -4
  6. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +6 -6
  7. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +24 -33
  8. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +22 -22
  9. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +8 -8
  10. package/ios/HybridNavigation/GlobalStyle.h +0 -8
  11. package/ios/HybridNavigation/GlobalStyle.m +2 -8
  12. package/ios/HybridNavigation/HBDAnimationObserver.h +24 -0
  13. package/ios/HybridNavigation/HBDAnimationObserver.m +45 -0
  14. package/ios/HybridNavigation/HBDUtils.h +5 -13
  15. package/ios/HybridNavigation/HBDUtils.m +26 -12
  16. package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.h +0 -9
  17. package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.m +91 -67
  18. package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.h +2 -7
  19. package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +28 -26
  20. package/ios/HybridNavigation/Navigator/HBDScreenNavigator.h +0 -9
  21. package/ios/HybridNavigation/Navigator/HBDScreenNavigator.m +132 -99
  22. package/ios/HybridNavigation/Navigator/HBDStackNavigator.h +0 -9
  23. package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +203 -142
  24. package/ios/HybridNavigation/Navigator/HBDTabNavigator.h +0 -9
  25. package/ios/HybridNavigation/Navigator/HBDTabNavigator.m +144 -124
  26. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.h +1 -11
  27. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.m +4 -10
  28. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +6 -0
  29. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +161 -0
  30. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +6 -0
  31. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +239 -0
  32. package/ios/HybridNavigation/ReactBridge/HBDNavigator.h +20 -0
  33. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.h +12 -20
  34. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.m +91 -91
  35. package/ios/HybridNavigation/View/HBDBarButtonItem.h +0 -8
  36. package/ios/HybridNavigation/View/HBDBarButtonItem.m +1 -11
  37. package/ios/HybridNavigation/View/HBDNavigationBar.h +0 -8
  38. package/ios/HybridNavigation/View/HBDNavigationBar.m +3 -12
  39. package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -8
  40. package/ios/HybridNavigation/View/HBDReactTabBar.m +1 -8
  41. package/ios/HybridNavigation/View/HBDRootView.h +3 -10
  42. package/ios/HybridNavigation/View/HBDRootView.m +14 -25
  43. package/ios/HybridNavigation/View/HBDTitleView.h +0 -9
  44. package/ios/HybridNavigation/View/HBDTitleView.m +1 -26
  45. package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -8
  46. package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -7
  47. package/ios/HybridNavigation/ViewController/HBDDrawerController.h +0 -8
  48. package/ios/HybridNavigation/ViewController/HBDDrawerController.m +2 -9
  49. package/ios/HybridNavigation/ViewController/HBDFadeAnimation.h +9 -0
  50. package/ios/HybridNavigation/ViewController/HBDFadeAnimation.m +22 -0
  51. package/ios/HybridNavigation/ViewController/HBDNavigationController.h +0 -8
  52. package/ios/HybridNavigation/ViewController/HBDNavigationController.m +17 -120
  53. package/ios/HybridNavigation/ViewController/HBDPopAnimation.h +0 -7
  54. package/ios/HybridNavigation/ViewController/HBDPopAnimation.m +1 -8
  55. package/ios/HybridNavigation/ViewController/HBDPushAnimation.h +0 -7
  56. package/ios/HybridNavigation/ViewController/HBDPushAnimation.m +1 -8
  57. package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -8
  58. package/ios/HybridNavigation/ViewController/HBDReactViewController.m +60 -27
  59. package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -8
  60. package/ios/HybridNavigation/ViewController/HBDTabBarController.m +15 -11
  61. package/ios/HybridNavigation/ViewController/HBDViewController+Garden.m +23 -33
  62. package/ios/HybridNavigation/ViewController/HBDViewController.h +1 -8
  63. package/ios/HybridNavigation/ViewController/HBDViewController.m +12 -25
  64. package/ios/HybridNavigation/ViewController/UINavigationController+HBD.h +0 -8
  65. package/ios/HybridNavigation/ViewController/UINavigationController+HBD.m +0 -8
  66. package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +2 -16
  67. package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +32 -46
  68. package/lib/Garden.d.ts +3 -0
  69. package/lib/Garden.js +12 -1
  70. package/lib/NavigationModule.d.ts +0 -2
  71. package/lib/NavigationModule.js +0 -3
  72. package/lib/Navigator.d.ts +25 -25
  73. package/lib/Navigator.js +116 -73
  74. package/lib/index.d.ts +1 -1
  75. package/lib/index.js +1 -1
  76. package/package.json +4 -6
  77. package/src/Garden.ts +15 -1
  78. package/src/NavigationModule.ts +0 -4
  79. package/src/Navigator.ts +96 -58
  80. package/src/index.ts +1 -1
  81. package/ios/HybridNavigation/Bridge/HBDGardenModule.h +0 -14
  82. package/ios/HybridNavigation/Bridge/HBDGardenModule.m +0 -155
  83. package/ios/HybridNavigation/Bridge/HBDNavigationModule.h +0 -15
  84. package/ios/HybridNavigation/Bridge/HBDNavigationModule.m +0 -272
  85. package/ios/HybridNavigation/Navigator/HBDNavigator.h +0 -26
@@ -1,11 +1,3 @@
1
- //
2
- // GlobalStyle.h
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2018/2/8.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
1
  #import <UIKit/UIKit.h>
10
2
 
11
3
  @interface GlobalStyle : NSObject
@@ -1,13 +1,7 @@
1
- //
2
- // GlobalStyle.m
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2018/2/8.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
1
  #import "GlobalStyle.h"
2
+
10
3
  #import "HBDUtils.h"
4
+
11
5
  #import <React/RCTUtils.h>
12
6
 
13
7
  @interface GlobalStyle ()
@@ -0,0 +1,24 @@
1
+ // fork from: https://github.com/wix/react-native-navigation/blob/master/lib/ios/AnimationObserver.h
2
+ #import <Foundation/Foundation.h>
3
+
4
+ typedef void (^HBDAnimationEndedBlock)(void);
5
+
6
+ NS_ASSUME_NONNULL_BEGIN
7
+
8
+ @interface HBDAnimationObserver : NSObject
9
+
10
+ + (HBDAnimationObserver *)sharedObserver;
11
+
12
+ @property(nonatomic) BOOL isAnimating;
13
+
14
+ - (void)registerAnimationEndedBlock:(HBDAnimationEndedBlock)block;
15
+
16
+ - (void)beginAnimation;
17
+
18
+ - (void)endAnimation;
19
+
20
+ - (void)invalidate;
21
+
22
+ @end
23
+
24
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,45 @@
1
+ #import "HBDAnimationObserver.h"
2
+
3
+ @implementation HBDAnimationObserver {
4
+ NSMutableArray<HBDAnimationEndedBlock> *_animationEndedBlocks;
5
+ }
6
+
7
+ - (instancetype)init {
8
+ self = [super init];
9
+ _animationEndedBlocks = [NSMutableArray array];
10
+ return self;
11
+ }
12
+
13
+ + (HBDAnimationObserver *)sharedObserver {
14
+ static HBDAnimationObserver *_sharedObserver = nil;
15
+ static dispatch_once_t onceToken;
16
+ dispatch_once(&onceToken, ^{
17
+ _sharedObserver = [[HBDAnimationObserver alloc] init];
18
+ });
19
+
20
+ return _sharedObserver;
21
+ }
22
+
23
+ - (void)registerAnimationEndedBlock:(HBDAnimationEndedBlock)block {
24
+ [_animationEndedBlocks addObject:block];
25
+ }
26
+
27
+ - (void)beginAnimation {
28
+ _isAnimating = YES;
29
+ }
30
+
31
+ - (void)endAnimation {
32
+ _isAnimating = NO;
33
+
34
+ for (HBDAnimationEndedBlock block in _animationEndedBlocks) {
35
+ block();
36
+ }
37
+
38
+ [_animationEndedBlocks removeAllObjects];
39
+ }
40
+
41
+ - (void)invalidate {
42
+ [_animationEndedBlocks removeAllObjects];
43
+ }
44
+
45
+ @end
@@ -1,11 +1,3 @@
1
- //
2
- // HBDUtils.h
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2017/12/25.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
1
  #import <UIKit/UIKit.h>
10
2
  #import <objc/runtime.h>
11
3
 
@@ -29,13 +21,13 @@ UIKIT_STATIC_INLINE BOOL imageHasAlphaChannel(UIImage *image) {
29
21
  alpha == kCGImageAlphaPremultipliedLast);
30
22
  }
31
23
 
32
- UIKIT_STATIC_INLINE void hbd_exchangeImplementations(Class klass, SEL originalSelector, SEL swizzledSelector) {
33
- Method originalMethod = class_getInstanceMethod(klass, originalSelector);
34
- Method swizzledMethod = class_getInstanceMethod(klass, swizzledSelector);
24
+ UIKIT_STATIC_INLINE void hbd_exchangeImplementations(Class clazz, SEL originalSelector, SEL swizzledSelector) {
25
+ Method originalMethod = class_getInstanceMethod(clazz, originalSelector);
26
+ Method swizzledMethod = class_getInstanceMethod(clazz, swizzledSelector);
35
27
 
36
- BOOL success = class_addMethod(klass, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
28
+ BOOL success = class_addMethod(clazz, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
37
29
  if (success) {
38
- class_replaceMethod(klass, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
30
+ class_replaceMethod(clazz, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
39
31
  } else {
40
32
  method_exchangeImplementations(originalMethod, swizzledMethod);
41
33
  }
@@ -1,12 +1,6 @@
1
- //
2
- // HBDUtils.m
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2017/12/25.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
1
  #import "HBDUtils.h"
2
+
3
+ #import "HBDAnimationObserver.h"
10
4
  #import <React/RCTConvert.h>
11
5
 
12
6
  @implementation HBDUtils
@@ -172,10 +166,7 @@
172
166
  }
173
167
 
174
168
  + (BOOL)isIphoneX {
175
- if (@available(iOS 11.0, *)) {
176
- return UIApplication.sharedApplication.keyWindow.safeAreaInsets.bottom > 0.0;
177
- }
178
- return NO;
169
+ return UIApplication.sharedApplication.keyWindow.safeAreaInsets.bottom > 0.0;
179
170
  }
180
171
 
181
172
  + (BOOL)isInCall {
@@ -187,4 +178,27 @@
187
178
  }
188
179
  }
189
180
 
181
+ static void (*__SWZ_didMoveToWindow_orig)(id self, SEL _cmd);
182
+
183
+ static void __HBD_didMoveToWindow(UIView *self, SEL _cmd) {
184
+ if (![[HBDAnimationObserver sharedObserver] isAnimating] || !self.window) {
185
+ __SWZ_didMoveToWindow_orig(self, _cmd);
186
+ } else {
187
+ [[HBDAnimationObserver sharedObserver] registerAnimationEndedBlock:^{
188
+ __SWZ_didMoveToWindow_orig(self, _cmd);
189
+ }];
190
+ }
191
+ }
192
+
193
+ + (void)load {
194
+ Class clazz = NSClassFromString(@"RCTBaseTextInputView");
195
+ if (clazz == NULL) {
196
+ return;
197
+ }
198
+ Method method = class_getInstanceMethod(clazz, NSSelectorFromString(@"didMoveToWindow"));
199
+ __SWZ_didMoveToWindow_orig = (void *)method_getImplementation(method);
200
+ method_setImplementation(method, (IMP)__HBD_didMoveToWindow);
201
+ }
202
+
203
+
190
204
  @end
@@ -1,12 +1,3 @@
1
- //
2
- // HBDDrawerNavigator.h
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2018/6/28.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
- #import <Foundation/Foundation.h>
10
1
  #import "HBDNavigator.h"
11
2
 
12
3
  @interface HBDDrawerNavigator : NSObject <HBDNavigator>
@@ -1,12 +1,5 @@
1
- //
2
- // HBDDrawerNavigator.m
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2018/6/28.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
1
  #import "HBDDrawerNavigator.h"
2
+
10
3
  #import "HBDReactBridgeManager.h"
11
4
 
12
5
  @implementation HBDDrawerNavigator
@@ -19,91 +12,122 @@
19
12
  return @[@"toggleMenu", @"openMenu", @"closeMenu"];
20
13
  }
21
14
 
22
- - (UIViewController *)createViewControllerWithLayout:(NSDictionary *)layout {
23
- NSDictionary *drawer = layout[self.name];
24
- NSArray *children = drawer[@"children"];
25
- if (children.count == 2) {
26
- NSDictionary *content = children[0];
27
- NSDictionary *menu = children[1];
28
-
29
- UIViewController *contentController = [[HBDReactBridgeManager get] controllerWithLayout:content];
30
- UIViewController *menuController = [[HBDReactBridgeManager get] controllerWithLayout:menu];
31
-
32
- if (contentController && menuController) {
33
- HBDDrawerController *drawerController = [[HBDDrawerController alloc] initWithContentViewController:contentController menuViewController:menuController];
34
- NSDictionary *options = drawer[@"options"];
35
- if (options) {
36
- NSNumber *maxDrawerWidth = options[@"maxDrawerWidth"];
37
- if (maxDrawerWidth) {
38
- [drawerController setMaxDrawerWidth:[maxDrawerWidth floatValue]];
39
- }
40
-
41
- NSNumber *minDrawerMargin = options[@"minDrawerMargin"];
42
- if (minDrawerMargin) {
43
- [drawerController setMinDrawerMargin:[minDrawerMargin floatValue]];
44
- }
45
-
46
- NSNumber *menuInteractive = options[@"menuInteractive"];
47
- if (menuInteractive) {
48
- drawerController.menuInteractive = [menuInteractive boolValue];
49
- }
50
- }
51
- return drawerController;
15
+ - (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout {
16
+ NSDictionary *model = layout[self.name];
17
+ if (!model) {
18
+ return nil;
19
+ }
20
+
21
+ NSArray *children = model[@"children"];
22
+ if (children.count < 2) {
23
+ return nil;
24
+ }
25
+
26
+ UIViewController *content = [[HBDReactBridgeManager get] viewControllerWithLayout:children[0]];
27
+ UIViewController *menu = [[HBDReactBridgeManager get] viewControllerWithLayout:children[1]];
28
+
29
+ if (!content || !menu) {
30
+ return nil;
31
+ }
32
+
33
+ HBDDrawerController *drawer = [[HBDDrawerController alloc] initWithContentViewController:content menuViewController:menu];
34
+ NSDictionary *options = model[@"options"];
35
+
36
+ if (options) {
37
+ NSNumber *maxDrawerWidth = options[@"maxDrawerWidth"];
38
+ if (maxDrawerWidth) {
39
+ [drawer setMaxDrawerWidth:[maxDrawerWidth floatValue]];
40
+ }
41
+
42
+ NSNumber *minDrawerMargin = options[@"minDrawerMargin"];
43
+ if (minDrawerMargin) {
44
+ [drawer setMinDrawerMargin:[minDrawerMargin floatValue]];
45
+ }
46
+
47
+ NSNumber *menuInteractive = options[@"menuInteractive"];
48
+ if (menuInteractive) {
49
+ drawer.menuInteractive = [menuInteractive boolValue];
52
50
  }
53
51
  }
54
- return nil;
52
+
53
+ return drawer;
55
54
  }
56
55
 
57
- - (NSDictionary *)buildRouteGraphWithViewController:(UIViewController *)vc {
58
- if ([vc isKindOfClass:[HBDDrawerController class]]) {
59
- HBDDrawerController *drawer = (HBDDrawerController *) vc;
60
- NSDictionary *content = [[HBDReactBridgeManager get] buildRouteGraphWithViewController:drawer.contentController];
61
- NSDictionary *menu = [[HBDReactBridgeManager get] buildRouteGraphWithViewController:drawer.menuController];
62
- return @{
63
- @"layout": @"drawer",
64
- @"sceneId": vc.sceneId,
65
- @"children": @[content, menu],
66
- @"mode": [vc hbd_mode],
67
- };
56
+ - (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc {
57
+ if (![vc isKindOfClass:[HBDDrawerController class]]) {
58
+ return nil;
68
59
  }
69
- return nil;
60
+
61
+ HBDDrawerController *drawer = (HBDDrawerController *) vc;
62
+ NSDictionary *content = [[HBDReactBridgeManager get] routeGraphWithViewController:drawer.contentController];
63
+ NSDictionary *menu = [[HBDReactBridgeManager get] routeGraphWithViewController:drawer.menuController];
64
+ return @{
65
+ @"layout": @"drawer",
66
+ @"sceneId": drawer.sceneId,
67
+ @"children": @[content, menu],
68
+ @"mode": [drawer hbd_mode],
69
+ };
70
70
  }
71
71
 
72
72
  - (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc {
73
- if ([vc isKindOfClass:[HBDDrawerController class]]) {
74
- HBDDrawerController *drawer = (HBDDrawerController *) vc;
75
- if (drawer.isMenuOpened) {
76
- return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:drawer.menuController];
77
- } else {
78
- return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:drawer.contentController];
79
- }
73
+ if (![vc isKindOfClass:[HBDDrawerController class]]) {
74
+ return nil;
75
+ }
76
+
77
+ HBDDrawerController *drawer = (HBDDrawerController *)vc;
78
+ if (drawer.isMenuOpened) {
79
+ return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:drawer.menuController];
80
+ } else {
81
+ return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:drawer.contentController];
80
82
  }
81
- return nil;
82
83
  }
83
84
 
84
- - (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
85
+ - (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
86
+ if (!vc.hbd_inViewHierarchy) {
87
+ callback(@[NSNull.null, @NO]);
88
+ return;
89
+ }
90
+
85
91
  HBDDrawerController *drawer = [vc drawerController];
86
92
  if (!drawer) {
87
- resolve(@(NO));
93
+ callback(@[NSNull.null, @NO]);
88
94
  return;
89
95
  }
90
96
 
91
97
  if (!drawer.hbd_viewAppeared) {
92
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
93
- [self handleNavigationWithViewController:vc action:action extras:extras resolver:resolve rejecter:reject];
94
- });
98
+ [self performSelector:@selector(handleNavigation:) withObject:@{
99
+ @"viewController": vc,
100
+ @"action": action,
101
+ @"extras": extras,
102
+ @"callback": callback,
103
+ } afterDelay:0.05];
95
104
  return;
96
105
  }
106
+
107
+ callback(@[NSNull.null, @YES]);
97
108
 
98
109
  if ([action isEqualToString:@"toggleMenu"]) {
99
110
  [drawer toggleMenu];
100
- } else if ([action isEqualToString:@"openMenu"]) {
111
+ return;
112
+ }
113
+
114
+ if ([action isEqualToString:@"openMenu"]) {
101
115
  [drawer openMenu];
102
- } else if ([action isEqualToString:@"closeMenu"]) {
116
+ return;
117
+ }
118
+
119
+ if ([action isEqualToString:@"closeMenu"]) {
103
120
  [drawer closeMenu];
121
+ return;
104
122
  }
123
+ }
124
+
125
+ -(void)handleNavigation:(NSDictionary *)params {
126
+ [self handleNavigationWithViewController:params[@"viewController"] action:params[@"action"] extras:params[@"extras"] callback:params[@"callback"]];
127
+ }
105
128
 
106
- resolve(@(YES));
129
+ - (void)invalidate {
130
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
107
131
  }
108
132
 
109
133
  @end
@@ -1,10 +1,3 @@
1
- //
2
- // HBDNavigatorRegistry.h
3
- // HybridNavigation
4
- //
5
- // Created by 李生 on 2021/1/7.
6
- //
7
-
8
1
  #import "HBDNavigator.h"
9
2
 
10
3
  NS_ASSUME_NONNULL_BEGIN
@@ -23,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN
23
16
 
24
17
  - (NSArray<NSString *> *)allLayouts;
25
18
 
19
+ - (NSArray<id<HBDNavigator>> *)allNavigators;
20
+
26
21
  @end
27
22
 
28
23
  NS_ASSUME_NONNULL_END
@@ -1,25 +1,18 @@
1
- //
2
- // HBDNavigatorRegistry.m
3
- // HybridNavigation
4
- //
5
- // Created by 李生 on 2021/1/7.
6
- //
7
-
8
1
  #import "HBDNavigatorRegistry.h"
9
2
 
10
- #import <React/RCTLog.h>
11
-
12
3
  #import "HBDScreenNavigator.h"
13
4
  #import "HBDStackNavigator.h"
14
5
  #import "HBDTabNavigator.h"
15
6
  #import "HBDDrawerNavigator.h"
16
-
17
7
  #import "HBDNavigationController.h"
18
8
  #import "HBDTabBarController.h"
19
9
 
10
+ #import <React/RCTLog.h>
11
+
20
12
  @interface HBDNavigatorRegistry ()
21
13
 
22
14
  @property(nonatomic, strong) NSMutableArray<NSString *> *layouts;
15
+ @property(nonatomic, strong) NSMutableArray<id <HBDNavigator>> *navigators;
23
16
  @property(nonatomic, strong) NSMutableDictionary<NSString *, id <HBDNavigator>> *actionNavigatorPairs;
24
17
  @property(nonatomic, strong) NSMutableDictionary<NSString *, id <HBDNavigator>> *layoutNavigatorPairs;
25
18
  @property(nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *classLayoutPairs;
@@ -45,8 +38,6 @@
45
38
  }
46
39
 
47
40
  - (void)registerNavigator:(id <HBDNavigator>)navigator {
48
- [self.layouts addObject:[navigator name]];
49
-
50
41
  for (NSString *action in [navigator supportActions]) {
51
42
  id <HBDNavigator> duplicated = self.actionNavigatorPairs[action];
52
43
  if (duplicated) {
@@ -56,11 +47,15 @@
56
47
  }
57
48
 
58
49
  NSString *layout = [navigator name];
50
+ [self.layouts addObject:layout];
51
+
59
52
  id <HBDNavigator> duplicatedLayout = self.layoutNavigatorPairs[layout];
60
53
  if (duplicatedLayout) {
61
54
  RCTLogError(@"[Navigator] The layout %@ that %@ wants to register has been registered by %@", layout, [navigator class], [duplicatedLayout class]);
62
55
  }
63
56
  self.layoutNavigatorPairs[layout] = navigator;
57
+
58
+ [self.navigators addObject:navigator];
64
59
  }
65
60
 
66
61
  - (id <HBDNavigator>)navigatorForAction:(NSString *)action {
@@ -73,21 +68,24 @@
73
68
 
74
69
  - (NSString *)layoutForViewController:(UIViewController *)vc {
75
70
  NSString *layout = self.classLayoutPairs[NSStringFromClass([vc class])];
76
- if (!layout) {
77
- if ([vc isKindOfClass:[HBDViewController class]]) {
78
- return @"screen";
79
- }
80
- if ([vc isKindOfClass:[HBDNavigationController class]]) {
81
- return @"stack";
82
- }
83
- if ([vc isKindOfClass:[HBDTabBarController class]]) {
84
- return @"tabs";
85
- }
86
- if ([vc isKindOfClass:[HBDDrawerController class]]) {
87
- return @"drawer";
88
- }
71
+ if (layout) {
72
+ return layout;
73
+ }
74
+
75
+ if ([vc isKindOfClass:[HBDViewController class]]) {
76
+ return @"screen";
77
+ }
78
+ if ([vc isKindOfClass:[HBDNavigationController class]]) {
79
+ return @"stack";
89
80
  }
90
- return layout;
81
+ if ([vc isKindOfClass:[HBDTabBarController class]]) {
82
+ return @"tabs";
83
+ }
84
+ if ([vc isKindOfClass:[HBDDrawerController class]]) {
85
+ return @"drawer";
86
+ }
87
+
88
+ return nil;
91
89
  }
92
90
 
93
91
  - (void)setLayout:(NSString *)layout forViewController:(UIViewController *)vc {
@@ -101,4 +99,8 @@
101
99
  return [self.layouts copy];
102
100
  }
103
101
 
102
+ - (NSArray<id<HBDNavigator>> *)allNavigators {
103
+ return [self.navigators copy];
104
+ }
105
+
104
106
  @end
@@ -1,12 +1,3 @@
1
- //
2
- // HBDScreenNavigator.h
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2018/6/28.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
- #import <Foundation/Foundation.h>
10
1
  #import "HBDNavigator.h"
11
2
 
12
3
  @interface HBDScreenNavigator : NSObject <HBDNavigator>