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
@@ -0,0 +1,239 @@
1
+ #import "HBDNavigationModule.h"
2
+
3
+ #import "HBDReactBridgeManager.h"
4
+ #import "HBDReactViewController.h"
5
+ #import "HBDAnimationObserver.h"
6
+
7
+ #import <React/RCTLog.h>
8
+
9
+ @interface HBDNavigationModule () <RCTInvalidating>
10
+
11
+ @property(nonatomic, strong, readonly) HBDReactBridgeManager *bridgeManager;
12
+
13
+ @end
14
+
15
+ @implementation HBDNavigationModule
16
+
17
+ + (BOOL)requiresMainQueueSetup {
18
+ return YES;
19
+ }
20
+
21
+ RCT_EXPORT_MODULE(NavigationModule)
22
+
23
+ - (instancetype)init {
24
+ if (self = [super init]) {
25
+ _bridgeManager = [HBDReactBridgeManager get];
26
+ }
27
+ return self;
28
+ }
29
+
30
+ - (void)invalidate {
31
+ RCTLogInfo(@"[Navigator] NavigationModule#invalidate");
32
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
33
+ [[HBDAnimationObserver sharedObserver] invalidate];
34
+ [self.bridgeManager invalidate];
35
+ }
36
+
37
+ - (dispatch_queue_t)methodQueue {
38
+ return dispatch_get_main_queue();
39
+ }
40
+
41
+ - (NSDictionary *)constantsToExport {
42
+ return @{
43
+ @"RESULT_OK": @(ResultOK),
44
+ @"RESULT_CANCEL": @(ResultCancel)
45
+ };
46
+ }
47
+
48
+ RCT_EXPORT_METHOD(startRegisterReactComponent) {
49
+ [self.bridgeManager startRegisterReactModule];
50
+ }
51
+
52
+ RCT_EXPORT_METHOD(endRegisterReactComponent) {
53
+ [self.bridgeManager endRegisterReactModule];
54
+ }
55
+
56
+ RCT_EXPORT_METHOD(registerReactComponent:(NSString *)appKey options:(NSDictionary *)options) {
57
+ [self.bridgeManager registerReactModule:appKey options:options];
58
+ }
59
+
60
+ RCT_EXPORT_METHOD(signalFirstRenderComplete:(NSString *) sceneId) {
61
+ // RCTLogInfo(@"[Navigator] signalFirstRenderComplete sceneId:%@", sceneId);
62
+ UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
63
+ if ([vc isKindOfClass:[HBDReactViewController class]]) {
64
+ [(HBDReactViewController *) vc signalFirstRenderComplete];
65
+ }
66
+ }
67
+
68
+ RCT_EXPORT_METHOD(setRoot:(NSDictionary *)layout sticky:(BOOL)sticky tag:(NSNumber *__nonnull)tag) {
69
+ self.bridgeManager.viewHierarchyReady = NO;
70
+ UIViewController *vc = [self.bridgeManager viewControllerWithLayout:layout];
71
+ if (vc) {
72
+ self.bridgeManager.hasRootLayout = YES;
73
+ [self.bridgeManager setRootViewController:vc withTag:tag];
74
+ }
75
+ }
76
+
77
+ RCT_EXPORT_METHOD(dispatch:(NSString *)sceneId action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback) {
78
+ UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
79
+ if (!vc) {
80
+ callback(@[NSNull.null, @NO]);
81
+ RCTLogWarn(@"[Navigator] Can't find target scene for action: %@, maybe the scene is gone. \nextras: %@", action, extras);
82
+ return;
83
+ }
84
+
85
+ [self.bridgeManager handleNavigationWithViewController:vc action:action extras:extras callback:(RCTResponseSenderBlock)callback];
86
+ }
87
+
88
+ RCT_EXPORT_METHOD(currentTab:(NSString *)sceneId callback:(RCTResponseSenderBlock)callback) {
89
+ UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
90
+ UITabBarController *tabs = vc.tabBarController;
91
+ if (tabs) {
92
+ callback(@[NSNull.null, @(tabs.selectedIndex)]);
93
+ } else {
94
+ callback(@[NSNull.null, @(-1)]);
95
+ }
96
+ }
97
+
98
+ RCT_EXPORT_METHOD(isStackRoot:(NSString *)sceneId callback:(RCTResponseSenderBlock)callback) {
99
+ UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
100
+ UINavigationController *nav = vc.navigationController;
101
+ if (!nav) {
102
+ callback(@[NSNull.null, @NO]);
103
+ return;
104
+ }
105
+
106
+ NSArray *children = nav.childViewControllers;
107
+ if (children.count == 0) {
108
+ callback(@[NSNull.null, @NO]);
109
+ return;
110
+ }
111
+
112
+ UIViewController *root = children[0];
113
+ if ([root.sceneId isEqualToString:sceneId]) {
114
+ callback(@[NSNull.null, @YES]);
115
+ return;
116
+ }
117
+
118
+ callback(@[NSNull.null, @NO]);
119
+ }
120
+
121
+ RCT_EXPORT_METHOD(setResult:(NSString *)sceneId resultCode:(NSInteger)resultCode data:(NSDictionary *)data) {
122
+ UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
123
+ [vc setResultCode:resultCode resultData:data];
124
+ }
125
+
126
+ RCT_EXPORT_METHOD(findSceneIdByModuleName:(NSString *)moduleName callback:(RCTResponseSenderBlock)callback) {
127
+ [self performSelector:@selector(findSceneIdWithParams:) withObject:@{
128
+ @"callback": callback,
129
+ @"moduleName": moduleName,
130
+ }];
131
+ }
132
+
133
+ - (void)findSceneIdWithParams:(NSDictionary *)params {
134
+ if (!self.bridgeManager.isViewHierarchyReady) {
135
+ [self performSelector:@selector(findSceneIdWithParams:) withObject:params afterDelay:0.016];
136
+ return;
137
+ }
138
+
139
+ NSString *moduleName = params[@"moduleName"];
140
+ RCTResponseSenderBlock callback = params[@"callback"];
141
+
142
+ NSString *sceneId = [self findSceneIdByModuleName:moduleName];
143
+ if (sceneId == nil) {
144
+ RCTLogInfo(@"[Navigator] Can't find sceneId by : %@", moduleName);
145
+ callback(@[NSNull.null, NSNull.null]);
146
+ return;
147
+ }
148
+
149
+ RCTLogInfo(@"[Navigator] The sceneId found by %@ : %@", moduleName, sceneId);
150
+ callback(@[[NSNull null], sceneId]);
151
+ }
152
+
153
+ - (NSString *)findSceneIdByModuleName:(NSString *)moduleName {
154
+ UIApplication *application = [[UIApplication class] performSelector:@selector(sharedApplication)];
155
+ NSUInteger count = application.windows.count;
156
+
157
+ for (NSInteger i = count - 1; i > -1; i--) {
158
+ UIWindow *window = application.windows[i];
159
+ NSString *sceneId = [self findSceneIdByModuleName:moduleName withViewController:window.rootViewController];
160
+ if (sceneId != nil) {
161
+ RCTLogInfo(@"[Navigator] The sceneId found by %@ : %@", moduleName, sceneId);
162
+ return sceneId;
163
+ }
164
+ }
165
+
166
+ return nil;
167
+ }
168
+
169
+ - (NSString *)findSceneIdByModuleName:(NSString *)moduleName withViewController:(UIViewController *)vc {
170
+ if ([vc isKindOfClass:[HBDViewController class]]) {
171
+ HBDViewController *hbd = (HBDViewController *)vc;
172
+ if ([moduleName isEqualToString:hbd.moduleName]) {
173
+ return hbd.sceneId;
174
+ }
175
+ }
176
+
177
+ if (vc.presentedViewController && !vc.presentedViewController.isBeingDismissed) {
178
+ NSString *sceneId = [self findSceneIdByModuleName:moduleName withViewController:vc.presentedViewController];
179
+ if (sceneId) {
180
+ return sceneId;
181
+ }
182
+ }
183
+
184
+ NSArray<UIViewController *> *children = vc.childViewControllers;
185
+ if (children.count == 0) {
186
+ return nil;
187
+ }
188
+
189
+ for (UIViewController *child in children) {
190
+ NSString *sceneId = [self findSceneIdByModuleName:moduleName withViewController:child];
191
+ if (sceneId) {
192
+ return sceneId;
193
+ }
194
+ }
195
+
196
+ return nil;
197
+ }
198
+
199
+ RCT_EXPORT_METHOD(currentRoute:(RCTResponseSenderBlock)callback) {
200
+ [self performSelector:@selector(currentRouteWithCallback:) withObject:callback];
201
+ }
202
+
203
+ - (void)currentRouteWithCallback:(RCTResponseSenderBlock)callback {
204
+ if (!self.bridgeManager.isViewHierarchyReady) {
205
+ [self performSelector:@selector(currentRouteWithCallback:) withObject:callback afterDelay:0.016];
206
+ return;
207
+ }
208
+
209
+ HBDViewController *current = [self.bridgeManager primaryViewController];
210
+ if (current) {
211
+ callback(@[[NSNull null], @{
212
+ @"moduleName": RCTNullIfNil(current.moduleName),
213
+ @"sceneId": current.sceneId,
214
+ @"mode": [current hbd_mode]
215
+ }]);
216
+ } else {
217
+ [self performSelector:@selector(currentRouteWithCallback:) withObject:callback afterDelay:0.016];
218
+ }
219
+ }
220
+
221
+ RCT_EXPORT_METHOD(routeGraph:(RCTResponseSenderBlock)callback) {
222
+ [self performSelector:@selector(routeGraphWithCallback:) withObject:callback];
223
+ }
224
+
225
+ - (void)routeGraphWithCallback:(RCTResponseSenderBlock)callback {
226
+ if (!self.bridgeManager.isViewHierarchyReady) {
227
+ [self performSelector:@selector(routeGraphWithCallback:) withObject:callback afterDelay:0.016];
228
+ return;
229
+ }
230
+
231
+ NSArray *root = [self.bridgeManager routeGraph];
232
+ if (root.count > 0) {
233
+ callback(@[[NSNull null], root]);
234
+ } else {
235
+ [self performSelector:@selector(routeGraphWithCallback:) withObject:callback afterDelay:0.016];
236
+ }
237
+ }
238
+
239
+ @end
@@ -0,0 +1,20 @@
1
+ #import "HBDViewController.h"
2
+
3
+ #import <React/RCTBridge.h>
4
+
5
+ @protocol HBDNavigator <NSObject>
6
+
7
+ @property(nonatomic, copy, readonly) NSString *name;
8
+ @property(nonatomic, copy, readonly) NSArray<NSString *> *supportActions;
9
+
10
+ - (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout;
11
+
12
+ - (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc;
13
+
14
+ - (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc;
15
+
16
+ - (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback;
17
+
18
+ - (void)invalidate;
19
+
20
+ @end
@@ -1,11 +1,3 @@
1
- //
2
- // HBDReactBridgeManager.h
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2017/11/25.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
1
  #import <React/RCTBridge.h>
10
2
  #import "HBDNavigator.h"
11
3
 
@@ -32,31 +24,29 @@ extern const NSInteger ResultCancel;
32
24
  @property(nonatomic, assign, getter=isViewHierarchyReady) BOOL viewHierarchyReady;
33
25
  @property(nonatomic, assign) BOOL hasRootLayout;
34
26
 
35
- - (void)installWithBundleURL:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions;
36
-
37
27
  - (void)installWithBridge:(RCTBridge *)bridge;
38
28
 
39
- - (void)registerNativeModule:(NSString *)moduleName forController:(Class)clazz;
29
+ - (void)registerNativeModule:(NSString *)moduleName forViewController:(Class)clazz;
40
30
 
41
31
  - (BOOL)hasNativeModule:(NSString *)moduleName;
42
32
 
43
- - (Class)nativeModuleClassFromName:(NSString *)moduleName;
33
+ - (Class)nativeModuleClass:(NSString *)moduleName;
44
34
 
45
35
  - (void)registerReactModule:(NSString *)moduleName options:(NSDictionary *)options;
46
36
 
47
- - (NSDictionary *)reactModuleOptionsForKey:(NSString *)moduleName;
37
+ - (NSDictionary *)reactModuleOptions:(NSString *)moduleName;
48
38
 
49
- - (BOOL)hasReactModuleForName:(NSString *)moduleName;
39
+ - (BOOL)hasReactModule:(NSString *)moduleName;
50
40
 
51
41
  - (void)startRegisterReactModule;
52
42
 
53
43
  - (void)endRegisterReactModule;
54
44
 
55
- - (HBDViewController *)controllerWithModuleName:(NSString *)moduleName props:(NSDictionary *)props options:(NSDictionary *)options;
45
+ - (HBDViewController *)viewControllerWithModuleName:(NSString *)moduleName props:(NSDictionary *)props options:(NSDictionary *)options;
56
46
 
57
- - (UIViewController *)controllerWithLayout:(NSDictionary *)layout;
47
+ - (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout;
58
48
 
59
- - (UIViewController *)controllerForSceneId:(NSString *)sceneId;
49
+ - (UIViewController *)viewControllerWithSceneId:(NSString *)sceneId;
60
50
 
61
51
  - (void)setRootViewController:(UIViewController *)rootViewController;
62
52
 
@@ -64,14 +54,16 @@ extern const NSInteger ResultCancel;
64
54
 
65
55
  - (NSArray *)routeGraph;
66
56
 
67
- - (NSDictionary *)buildRouteGraphWithViewController:(UIViewController *)vc;
57
+ - (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc;
68
58
 
69
59
  - (HBDViewController *)primaryViewController;
70
60
 
71
61
  - (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc;
72
62
 
73
- - (void)handleNavigationWithViewController:(UIViewController *)target action:(NSString *)action extras:(NSDictionary *)extras resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
63
+ - (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback;
64
+
65
+ - (void)registerNavigator:(id<HBDNavigator>)navigator;
74
66
 
75
- - (void)registerNavigator:(id <HBDNavigator>)navigator;
67
+ - (void)invalidate;
76
68
 
77
69
  @end
@@ -1,25 +1,18 @@
1
- //
2
- // HBDReactBridgeManager.m
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2017/11/25.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
1
  #import "HBDReactBridgeManager.h"
10
- #import <React/RCTLog.h>
2
+
11
3
  #import "HBDUtils.h"
12
4
  #import "HBDReactViewController.h"
13
5
  #import "HBDNavigatorRegistry.h"
14
6
  #import "HBDEventEmitter.h"
15
7
 
8
+ #import <React/RCTLog.h>
9
+
16
10
  NSString *const ReactModuleRegistryDidCompletedNotification = @"ReactModuleRegistryDidCompletedNotification";
17
11
  const NSInteger ResultOK = -1;
18
12
  const NSInteger ResultCancel = 0;
19
13
 
20
- @interface HBDReactBridgeManager () <RCTBridgeDelegate>
14
+ @interface HBDReactBridgeManager ()
21
15
 
22
- @property(nonatomic, copy) NSURL *jsCodeLocation;
23
16
  @property(nonatomic, strong) NSMutableDictionary *nativeModules;
24
17
  @property(nonatomic, strong) NSMutableDictionary *reactModules;
25
18
  @property(nonatomic, assign, readwrite, getter=isReactModuleRegisterCompleted) BOOL reactModuleRegisterCompleted;
@@ -45,15 +38,10 @@ const NSInteger ResultCancel = 0;
45
38
  _reactModuleRegisterCompleted = NO;
46
39
  _viewHierarchyReady = NO;
47
40
  _navigatorRegistry = [[HBDNavigatorRegistry alloc] init];
48
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleReload) name:RCTBridgeWillReloadNotification object:nil];
49
41
  }
50
42
  return self;
51
43
  }
52
44
 
53
- - (void)dealloc {
54
- [[NSNotificationCenter defaultCenter] removeObserver:self name:RCTBridgeWillReloadNotification object:nil];
55
- }
56
-
57
45
  - (UIWindow *)mainWindow {
58
46
  UIWindow *mainWindow = RCTSharedApplication().delegate.window;
59
47
  if (!mainWindow) {
@@ -64,7 +52,15 @@ const NSInteger ResultCancel = 0;
64
52
  return mainWindow;
65
53
  }
66
54
 
67
- - (void)handleReload {
55
+ - (void)invalidate {
56
+ RCTLogInfo(@"[Navigator] HBDReactBridgeManager#invalidate");
57
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
58
+
59
+ NSArray<id <HBDNavigator>> *navigators = [self.navigatorRegistry allNavigators];
60
+ for (id<HBDNavigator> navigator in navigators) {
61
+ [navigator invalidate];
62
+ }
63
+
68
64
  self.viewHierarchyReady = NO;
69
65
  self.reactModuleRegisterCompleted = NO;
70
66
 
@@ -81,22 +77,22 @@ const NSInteger ResultCancel = 0;
81
77
 
82
78
  - (void)setLoadingViewController {
83
79
  UIWindow *mainWindow = [self mainWindow];
84
- UIViewController *vc = [UIViewController new];
85
- vc.view.backgroundColor = UIColor.whiteColor;
80
+ UIViewController *vc;
81
+ @try {
82
+ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil];
83
+ vc = [storyboard instantiateInitialViewController];
84
+ } @catch (NSException * e){
85
+ vc = [UIViewController new];
86
+ vc.view.backgroundColor = UIColor.whiteColor;
87
+ }
86
88
  mainWindow.rootViewController = vc;
87
89
  }
88
90
 
89
- - (void)installWithBundleURL:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
90
- _jsCodeLocation = jsCodeLocation;
91
-
92
- _bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
93
- }
94
-
95
91
  - (void)installWithBridge:(RCTBridge *)bridge {
96
92
  _bridge = bridge;
97
93
  }
98
94
 
99
- - (void)registerNativeModule:(NSString *)moduleName forController:(Class)clazz {
95
+ - (void)registerNativeModule:(NSString *)moduleName forViewController:(Class)clazz {
100
96
  [_nativeModules setObject:clazz forKey:moduleName];
101
97
  }
102
98
 
@@ -104,7 +100,7 @@ const NSInteger ResultCancel = 0;
104
100
  return _nativeModules[moduleName] != nil;
105
101
  }
106
102
 
107
- - (Class)nativeModuleClassFromName:(NSString *)moduleName {
103
+ - (Class)nativeModuleClass:(NSString *)moduleName {
108
104
  return _nativeModules[moduleName];
109
105
  }
110
106
 
@@ -112,11 +108,11 @@ const NSInteger ResultCancel = 0;
112
108
  _reactModules[moduleName] = options;
113
109
  }
114
110
 
115
- - (NSDictionary *)reactModuleOptionsForKey:(NSString *)moduleName {
111
+ - (NSDictionary *)reactModuleOptions:(NSString *)moduleName {
116
112
  return _reactModules[moduleName];
117
113
  }
118
114
 
119
- - (BOOL)hasReactModuleForName:(NSString *)moduleName {
115
+ - (BOOL)hasReactModule:(NSString *)moduleName {
120
116
  return _reactModules[moduleName] != nil;
121
117
  }
122
118
 
@@ -133,30 +129,40 @@ const NSInteger ResultCancel = 0;
133
129
  [[NSNotificationCenter defaultCenter] postNotificationName:ReactModuleRegistryDidCompletedNotification object:nil];
134
130
  }
135
131
 
136
- - (UIViewController *)controllerWithLayout:(NSDictionary *)layout {
137
- if (!self.isReactModuleRegisterCompleted) {
138
- return nil;
139
- }
140
-
132
+ - (UIViewController *)createViewControllerWithLayout:(NSDictionary *)layout {
141
133
  NSArray<NSString *> *layouts = [self.navigatorRegistry allLayouts];
142
134
  for (NSString *name in layouts) {
143
- if ([[layout allKeys] containsObject:name]) {
144
- id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:name];
145
- UIViewController *vc = [navigator createViewControllerWithLayout:layout];
146
- if (vc) {
147
- [self.navigatorRegistry setLayout:name forViewController:vc];
148
- }
149
- return vc;
135
+ if (![[layout allKeys] containsObject:name]) {
136
+ continue;
137
+ }
138
+
139
+ id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:name];
140
+ UIViewController *vc = [navigator viewControllerWithLayout:layout];
141
+ if (vc) {
142
+ [self.navigatorRegistry setLayout:name forViewController:vc];
150
143
  }
144
+ return vc;
151
145
  }
152
-
153
- RCTLogError(@"[Navigator] Can't find a navigator that can handle layout '%@'. Did you forget to register?", layout);
146
+
154
147
  return nil;
155
148
  }
156
149
 
157
- - (HBDViewController *)controllerWithModuleName:(NSString *)moduleName props:(NSDictionary *)props options:(NSDictionary *)options {
158
- HBDViewController *vc = nil;
150
+ - (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout {
151
+ if (!self.isReactModuleRegisterCompleted) {
152
+ return nil;
153
+ }
159
154
 
155
+ UIViewController *vc = [self createViewControllerWithLayout:layout];
156
+
157
+ if (!vc) {
158
+ RCTLogError(@"[Navigator] Can't find a navigator that can handle layout '%@'. Did you forget to register?", layout);
159
+ return nil;
160
+ }
161
+
162
+ return vc;
163
+ }
164
+
165
+ - (HBDViewController *)viewControllerWithModuleName:(NSString *)moduleName props:(NSDictionary *)props options:(NSDictionary *)options {
160
166
  if (!self.isReactModuleRegisterCompleted) {
161
167
  @throw [NSException exceptionWithName:@"IllegalStateException" reason:@"React module hasn't register completed." userInfo:@{}];
162
168
  }
@@ -169,51 +175,52 @@ const NSInteger ResultCancel = 0;
169
175
  options = @{};
170
176
  }
171
177
 
172
- if ([self hasReactModuleForName:moduleName]) {
173
- NSDictionary *staticOptions = [[HBDReactBridgeManager get] reactModuleOptionsForKey:moduleName];
178
+ if ([self hasReactModule:moduleName]) {
179
+ NSDictionary *staticOptions = [[HBDReactBridgeManager get] reactModuleOptions:moduleName];
174
180
  options = [HBDUtils mergeItem:options withTarget:staticOptions];
175
- vc = [[HBDReactViewController alloc] initWithModuleName:moduleName props:props options:options];
181
+ return [[HBDReactViewController alloc] initWithModuleName:moduleName props:props options:options];
176
182
  } else {
177
- Class clazz = [self nativeModuleClassFromName:moduleName];
183
+ Class clazz = [self nativeModuleClass:moduleName];
178
184
  NSCAssert([self hasNativeModule:moduleName], @"Can't find module named with %@ , do you forget to register?", moduleName);
179
- vc = [[clazz alloc] initWithModuleName:moduleName props:props options:options];
185
+ return [[clazz alloc] initWithModuleName:moduleName props:props options:options];
180
186
  }
181
- return vc;
182
187
  }
183
188
 
184
- - (UIViewController *)controllerForSceneId:(NSString *)sceneId {
189
+ - (UIViewController *)viewControllerWithSceneId:(NSString *)sceneId {
185
190
  if (!self.viewHierarchyReady) {
186
191
  return nil;
187
192
  }
193
+
188
194
  UIWindow *window = [self mainWindow];
189
- return [self controllerForSceneId:sceneId withController:window.rootViewController];
195
+ return [self viewControllerWithSceneId:sceneId viewController:window.rootViewController];
190
196
  }
191
197
 
192
- - (UIViewController *)controllerForSceneId:(NSString *)sceneId withController:(UIViewController *)controller {
193
- UIViewController *target;
194
-
195
- if ([controller.sceneId isEqualToString:sceneId]) {
196
- target = controller;
198
+ - (UIViewController *)viewControllerWithSceneId:(NSString *)sceneId viewController:(UIViewController *)vc {
199
+ if ([vc.sceneId isEqualToString:sceneId]) {
200
+ return vc;
197
201
  }
198
202
 
199
- if (!target) {
200
- UIViewController *presentedController = controller.presentedViewController;
201
- if (presentedController && ![presentedController isBeingDismissed]) {
202
- target = [self controllerForSceneId:sceneId withController:presentedController];
203
+ UIViewController *presentedViewController = vc.presentedViewController;
204
+ if (presentedViewController && ![presentedViewController isBeingDismissed]) {
205
+ UIViewController *target = [self viewControllerWithSceneId:sceneId viewController:presentedViewController];
206
+ if (target) {
207
+ return target;
203
208
  }
204
209
  }
205
210
 
206
- if (!target && controller.childViewControllers.count > 0) {
207
- NSUInteger count = controller.childViewControllers.count;
208
- for (NSUInteger i = 0; i < count; i++) {
209
- UIViewController *child = controller.childViewControllers[i];
210
- target = [self controllerForSceneId:sceneId withController:child];
211
- if (target) {
212
- break;
213
- }
211
+ NSArray<UIViewController *> *children = vc.childViewControllers;
212
+ if (children.count == 0) {
213
+ return nil;
214
+ }
215
+
216
+ for (UIViewController *child in children) {
217
+ UIViewController *target = [self viewControllerWithSceneId:sceneId viewController:child];
218
+ if (target) {
219
+ return target;
214
220
  }
215
221
  }
216
- return target;
222
+
223
+ return nil;
217
224
  }
218
225
 
219
226
  - (void)setRootViewController:(UIViewController *)rootViewController {
@@ -274,18 +281,17 @@ const NSInteger ResultCancel = 0;
274
281
  }
275
282
 
276
283
  NSString *layout = [self.navigatorRegistry layoutForViewController:vc];
277
- if (layout) {
278
- id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:layout];
279
- return [navigator primaryViewControllerWithViewController:vc];
284
+ if (!layout) {
285
+ return nil;
280
286
  }
281
-
282
- return nil;
287
+ id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:layout];
288
+ return [navigator primaryViewControllerWithViewController:vc];
283
289
  }
284
290
 
285
291
  - (NSArray *)routeGraph {
286
292
  UIWindow *mainWindow = [self mainWindow];
287
293
  UIViewController *vc = mainWindow.rootViewController;
288
- NSDictionary *graph = [self buildRouteGraphWithViewController:vc];
294
+ NSDictionary *graph = [self routeGraphWithViewController:vc];
289
295
  NSMutableArray *root = [[NSMutableArray alloc] init];
290
296
  [root addObject:graph];
291
297
  [root addObjectsFromArray:[self presentedGraphsWithRootViewController:vc]];
@@ -297,7 +303,7 @@ const NSInteger ResultCancel = 0;
297
303
  NSMutableArray *graphs = [[NSMutableArray alloc] init];
298
304
  UIViewController *presented = vc.presentedViewController;
299
305
  while (presented && !presented.beingDismissed && ![presented isKindOfClass:[UIAlertController class]]) {
300
- NSDictionary *graph = [self buildRouteGraphWithViewController:presented];
306
+ NSDictionary *graph = [self routeGraphWithViewController:presented];
301
307
  if (graph) {
302
308
  [graphs addObject:graph];
303
309
  }
@@ -307,33 +313,27 @@ const NSInteger ResultCancel = 0;
307
313
  return graphs;
308
314
  }
309
315
 
310
- - (NSDictionary *)buildRouteGraphWithViewController:(UIViewController *)vc {
316
+ - (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc {
311
317
  NSString *layout = [self.navigatorRegistry layoutForViewController:vc];
312
318
  if (!layout) {
313
319
  return nil;
314
320
  }
315
-
316
321
  id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:layout];
317
- return [navigator buildRouteGraphWithViewController:vc];
322
+ return [navigator routeGraphWithViewController:vc];
318
323
  }
319
324
 
320
- - (void)handleNavigationWithViewController:(UIViewController *)target action:(NSString *)action extras:(NSDictionary *)extras resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
325
+ - (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
321
326
  id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForAction:action];
322
- if (navigator) {
323
- [navigator handleNavigationWithViewController:target action:action extras:extras resolver:resolve rejecter:reject];
324
- } else {
327
+ if (!navigator) {
325
328
  RCTLogWarn(@"[Navigator] Can't find a navigator that can handle action '%@'", action);
329
+ callback(@[NSNull.null, @NO]);
330
+ return;
326
331
  }
332
+ [navigator handleNavigationWithViewController:vc action:action extras:extras callback:(RCTResponseSenderBlock)callback];
327
333
  }
328
334
 
329
335
  - (void)registerNavigator:(id <HBDNavigator>)navigator {
330
336
  [self.navigatorRegistry registerNavigator:navigator];
331
337
  }
332
338
 
333
- #pragma mark - bridge delegate
334
-
335
- - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
336
- return _jsCodeLocation;
337
- }
338
-
339
339
  @end
@@ -1,11 +1,3 @@
1
- //
2
- // HBDBarButtonItem.h
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2017/11/26.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
1
  #import <UIKit/UIKit.h>
10
2
 
11
3
  typedef void(^HBDButtonActionBlock)(void);