hybrid-navigation 2.12.3 → 2.13.0-beta.1
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/README.md +63 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +6 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +29 -30
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +2 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +4 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +24 -33
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +22 -22
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +8 -8
- package/ios/HybridNavigation/GlobalStyle.h +0 -8
- package/ios/HybridNavigation/GlobalStyle.m +2 -8
- package/ios/HybridNavigation/HBDUtils.h +5 -13
- package/ios/HybridNavigation/HBDUtils.m +2 -12
- package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.m +91 -67
- package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.h +2 -7
- package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +28 -26
- package/ios/HybridNavigation/Navigator/HBDScreenNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDScreenNavigator.m +127 -99
- package/ios/HybridNavigation/Navigator/HBDStackNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +199 -142
- package/ios/HybridNavigation/Navigator/HBDTabNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDTabNavigator.m +144 -124
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.h +1 -11
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.m +4 -10
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +6 -0
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +161 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +6 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +237 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigator.h +20 -0
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.h +12 -20
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.m +91 -91
- package/ios/HybridNavigation/View/HBDBarButtonItem.h +0 -8
- package/ios/HybridNavigation/View/HBDBarButtonItem.m +1 -11
- package/ios/HybridNavigation/View/HBDNavigationBar.h +0 -8
- package/ios/HybridNavigation/View/HBDNavigationBar.m +13 -20
- package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -8
- package/ios/HybridNavigation/View/HBDReactTabBar.m +1 -8
- package/ios/HybridNavigation/View/HBDRootView.h +3 -10
- package/ios/HybridNavigation/View/HBDRootView.m +14 -25
- package/ios/HybridNavigation/View/HBDTitleView.h +0 -9
- package/ios/HybridNavigation/View/HBDTitleView.m +1 -26
- package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -8
- package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -7
- package/ios/HybridNavigation/ViewController/HBDDrawerController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDDrawerController.m +2 -9
- package/ios/HybridNavigation/ViewController/HBDFadeAnimation.h +9 -0
- package/ios/HybridNavigation/ViewController/HBDFadeAnimation.m +22 -0
- package/ios/HybridNavigation/ViewController/HBDNavigationController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDNavigationController.m +17 -120
- package/ios/HybridNavigation/ViewController/HBDPopAnimation.h +0 -7
- package/ios/HybridNavigation/ViewController/HBDPopAnimation.m +1 -8
- package/ios/HybridNavigation/ViewController/HBDPushAnimation.h +0 -7
- package/ios/HybridNavigation/ViewController/HBDPushAnimation.m +1 -8
- package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDReactViewController.m +60 -27
- package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDTabBarController.m +15 -11
- package/ios/HybridNavigation/ViewController/HBDViewController+Garden.m +23 -33
- package/ios/HybridNavigation/ViewController/HBDViewController.h +1 -8
- package/ios/HybridNavigation/ViewController/HBDViewController.m +6 -23
- package/ios/HybridNavigation/ViewController/UINavigationController+HBD.h +0 -8
- package/ios/HybridNavigation/ViewController/UINavigationController+HBD.m +0 -8
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +2 -16
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +32 -46
- package/lib/Garden.d.ts +3 -0
- package/lib/Garden.js +12 -1
- package/lib/NavigationModule.d.ts +0 -2
- package/lib/NavigationModule.js +0 -3
- package/lib/Navigator.d.ts +25 -25
- package/lib/Navigator.js +116 -73
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/package.json +4 -6
- package/src/Garden.ts +15 -1
- package/src/NavigationModule.ts +0 -4
- package/src/Navigator.ts +96 -58
- package/src/index.ts +1 -1
- package/ios/HybridNavigation/Bridge/HBDGardenModule.h +0 -14
- package/ios/HybridNavigation/Bridge/HBDGardenModule.m +0 -155
- package/ios/HybridNavigation/Bridge/HBDNavigationModule.h +0 -15
- package/ios/HybridNavigation/Bridge/HBDNavigationModule.m +0 -272
- package/ios/HybridNavigation/Navigator/HBDNavigator.h +0 -26
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
#import "HBDNavigationModule.h"
|
|
2
|
+
|
|
3
|
+
#import "HBDReactBridgeManager.h"
|
|
4
|
+
#import "HBDReactViewController.h"
|
|
5
|
+
|
|
6
|
+
#import <React/RCTLog.h>
|
|
7
|
+
|
|
8
|
+
@interface HBDNavigationModule () <RCTInvalidating>
|
|
9
|
+
|
|
10
|
+
@property(nonatomic, strong, readonly) HBDReactBridgeManager *bridgeManager;
|
|
11
|
+
|
|
12
|
+
@end
|
|
13
|
+
|
|
14
|
+
@implementation HBDNavigationModule
|
|
15
|
+
|
|
16
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
17
|
+
return YES;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
RCT_EXPORT_MODULE(NavigationModule)
|
|
21
|
+
|
|
22
|
+
- (instancetype)init {
|
|
23
|
+
if (self = [super init]) {
|
|
24
|
+
_bridgeManager = [HBDReactBridgeManager get];
|
|
25
|
+
}
|
|
26
|
+
return self;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
- (void)invalidate {
|
|
30
|
+
RCTLogInfo(@"[Navigator] NavigationModule#invalidate");
|
|
31
|
+
[NSObject cancelPreviousPerformRequestsWithTarget:self];
|
|
32
|
+
[self.bridgeManager invalidate];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
- (dispatch_queue_t)methodQueue {
|
|
36
|
+
return dispatch_get_main_queue();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
- (NSDictionary *)constantsToExport {
|
|
40
|
+
return @{
|
|
41
|
+
@"RESULT_OK": @(ResultOK),
|
|
42
|
+
@"RESULT_CANCEL": @(ResultCancel)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
RCT_EXPORT_METHOD(startRegisterReactComponent) {
|
|
47
|
+
[self.bridgeManager startRegisterReactModule];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
RCT_EXPORT_METHOD(endRegisterReactComponent) {
|
|
51
|
+
[self.bridgeManager endRegisterReactModule];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
RCT_EXPORT_METHOD(registerReactComponent:(NSString *)appKey options:(NSDictionary *)options) {
|
|
55
|
+
[self.bridgeManager registerReactModule:appKey options:options];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
RCT_EXPORT_METHOD(signalFirstRenderComplete:(NSString *) sceneId) {
|
|
59
|
+
// RCTLogInfo(@"[Navigator] signalFirstRenderComplete sceneId:%@", sceneId);
|
|
60
|
+
UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
|
|
61
|
+
if ([vc isKindOfClass:[HBDReactViewController class]]) {
|
|
62
|
+
[(HBDReactViewController *) vc signalFirstRenderComplete];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
RCT_EXPORT_METHOD(setRoot:(NSDictionary *)layout sticky:(BOOL)sticky tag:(NSNumber *__nonnull)tag) {
|
|
67
|
+
self.bridgeManager.viewHierarchyReady = NO;
|
|
68
|
+
UIViewController *vc = [self.bridgeManager viewControllerWithLayout:layout];
|
|
69
|
+
if (vc) {
|
|
70
|
+
self.bridgeManager.hasRootLayout = YES;
|
|
71
|
+
[self.bridgeManager setRootViewController:vc withTag:tag];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
RCT_EXPORT_METHOD(dispatch:(NSString *)sceneId action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback) {
|
|
76
|
+
UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
|
|
77
|
+
if (!vc) {
|
|
78
|
+
callback(@[NSNull.null, @NO]);
|
|
79
|
+
RCTLogWarn(@"[Navigator] Can't find target scene for action: %@, maybe the scene is gone. \nextras: %@", action, extras);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
[self.bridgeManager handleNavigationWithViewController:vc action:action extras:extras callback:(RCTResponseSenderBlock)callback];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
RCT_EXPORT_METHOD(currentTab:(NSString *)sceneId callback:(RCTResponseSenderBlock)callback) {
|
|
87
|
+
UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
|
|
88
|
+
UITabBarController *tabs = vc.tabBarController;
|
|
89
|
+
if (tabs) {
|
|
90
|
+
callback(@[NSNull.null, @(tabs.selectedIndex)]);
|
|
91
|
+
} else {
|
|
92
|
+
callback(@[NSNull.null, @(-1)]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
RCT_EXPORT_METHOD(isStackRoot:(NSString *)sceneId callback:(RCTResponseSenderBlock)callback) {
|
|
97
|
+
UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
|
|
98
|
+
UINavigationController *nav = vc.navigationController;
|
|
99
|
+
if (!nav) {
|
|
100
|
+
callback(@[NSNull.null, @NO]);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
NSArray *children = nav.childViewControllers;
|
|
105
|
+
if (children.count == 0) {
|
|
106
|
+
callback(@[NSNull.null, @NO]);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
UIViewController *root = children[0];
|
|
111
|
+
if ([root.sceneId isEqualToString:sceneId]) {
|
|
112
|
+
callback(@[NSNull.null, @YES]);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
callback(@[NSNull.null, @NO]);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
RCT_EXPORT_METHOD(setResult:(NSString *)sceneId resultCode:(NSInteger)resultCode data:(NSDictionary *)data) {
|
|
120
|
+
UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
|
|
121
|
+
[vc setResultCode:resultCode resultData:data];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
RCT_EXPORT_METHOD(findSceneIdByModuleName:(NSString *)moduleName callback:(RCTResponseSenderBlock)callback) {
|
|
125
|
+
[self performSelector:@selector(findSceneIdWithParams:) withObject:@{
|
|
126
|
+
@"callback": callback,
|
|
127
|
+
@"moduleName": moduleName,
|
|
128
|
+
}];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
- (void)findSceneIdWithParams:(NSDictionary *)params {
|
|
132
|
+
if (!self.bridgeManager.isViewHierarchyReady) {
|
|
133
|
+
[self performSelector:@selector(findSceneIdWithParams:) withObject:params afterDelay:0.016];
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
NSString *moduleName = params[@"moduleName"];
|
|
138
|
+
RCTResponseSenderBlock callback = params[@"callback"];
|
|
139
|
+
|
|
140
|
+
NSString *sceneId = [self findSceneIdByModuleName:moduleName];
|
|
141
|
+
if (sceneId == nil) {
|
|
142
|
+
RCTLogInfo(@"[Navigator] Can't find sceneId by : %@", moduleName);
|
|
143
|
+
callback(@[NSNull.null, NSNull.null]);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
RCTLogInfo(@"[Navigator] The sceneId found by %@ : %@", moduleName, sceneId);
|
|
148
|
+
callback(@[[NSNull null], sceneId]);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
- (NSString *)findSceneIdByModuleName:(NSString *)moduleName {
|
|
152
|
+
UIApplication *application = [[UIApplication class] performSelector:@selector(sharedApplication)];
|
|
153
|
+
NSUInteger count = application.windows.count;
|
|
154
|
+
|
|
155
|
+
for (NSInteger i = count - 1; i > -1; i--) {
|
|
156
|
+
UIWindow *window = application.windows[i];
|
|
157
|
+
NSString *sceneId = [self findSceneIdByModuleName:moduleName withViewController:window.rootViewController];
|
|
158
|
+
if (sceneId != nil) {
|
|
159
|
+
RCTLogInfo(@"[Navigator] The sceneId found by %@ : %@", moduleName, sceneId);
|
|
160
|
+
return sceneId;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return nil;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
- (NSString *)findSceneIdByModuleName:(NSString *)moduleName withViewController:(UIViewController *)vc {
|
|
168
|
+
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
169
|
+
HBDViewController *hbd = (HBDViewController *)vc;
|
|
170
|
+
if ([moduleName isEqualToString:hbd.moduleName]) {
|
|
171
|
+
return hbd.sceneId;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (vc.presentedViewController && !vc.presentedViewController.isBeingDismissed) {
|
|
176
|
+
NSString *sceneId = [self findSceneIdByModuleName:moduleName withViewController:vc.presentedViewController];
|
|
177
|
+
if (sceneId) {
|
|
178
|
+
return sceneId;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
NSArray<UIViewController *> *children = vc.childViewControllers;
|
|
183
|
+
if (children.count == 0) {
|
|
184
|
+
return nil;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
for (UIViewController *child in children) {
|
|
188
|
+
NSString *sceneId = [self findSceneIdByModuleName:moduleName withViewController:child];
|
|
189
|
+
if (sceneId) {
|
|
190
|
+
return sceneId;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return nil;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
RCT_EXPORT_METHOD(currentRoute:(RCTResponseSenderBlock)callback) {
|
|
198
|
+
[self performSelector:@selector(currentRouteWithCallback:) withObject:callback];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
- (void)currentRouteWithCallback:(RCTResponseSenderBlock)callback {
|
|
202
|
+
if (!self.bridgeManager.isViewHierarchyReady) {
|
|
203
|
+
[self performSelector:@selector(currentRouteWithCallback:) withObject:callback afterDelay:0.016];
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
HBDViewController *current = [self.bridgeManager primaryViewController];
|
|
208
|
+
if (current) {
|
|
209
|
+
callback(@[[NSNull null], @{
|
|
210
|
+
@"moduleName": RCTNullIfNil(current.moduleName),
|
|
211
|
+
@"sceneId": current.sceneId,
|
|
212
|
+
@"mode": [current hbd_mode]
|
|
213
|
+
}]);
|
|
214
|
+
} else {
|
|
215
|
+
[self performSelector:@selector(currentRouteWithCallback:) withObject:callback afterDelay:0.016];
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
RCT_EXPORT_METHOD(routeGraph:(RCTResponseSenderBlock)callback) {
|
|
220
|
+
[self performSelector:@selector(routeGraphWithCallback:) withObject:callback];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
- (void)routeGraphWithCallback:(RCTResponseSenderBlock)callback {
|
|
224
|
+
if (!self.bridgeManager.isViewHierarchyReady) {
|
|
225
|
+
[self performSelector:@selector(routeGraphWithCallback:) withObject:callback afterDelay:0.016];
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
NSArray *root = [self.bridgeManager routeGraph];
|
|
230
|
+
if (root.count > 0) {
|
|
231
|
+
callback(@[[NSNull null], root]);
|
|
232
|
+
} else {
|
|
233
|
+
[self performSelector:@selector(routeGraphWithCallback:) withObject:callback afterDelay:0.016];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
@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
|
|
29
|
+
- (void)registerNativeModule:(NSString *)moduleName forViewController:(Class)clazz;
|
|
40
30
|
|
|
41
31
|
- (BOOL)hasNativeModule:(NSString *)moduleName;
|
|
42
32
|
|
|
43
|
-
- (Class)
|
|
33
|
+
- (Class)nativeModuleClass:(NSString *)moduleName;
|
|
44
34
|
|
|
45
35
|
- (void)registerReactModule:(NSString *)moduleName options:(NSDictionary *)options;
|
|
46
36
|
|
|
47
|
-
- (NSDictionary *)
|
|
37
|
+
- (NSDictionary *)reactModuleOptions:(NSString *)moduleName;
|
|
48
38
|
|
|
49
|
-
- (BOOL)
|
|
39
|
+
- (BOOL)hasReactModule:(NSString *)moduleName;
|
|
50
40
|
|
|
51
41
|
- (void)startRegisterReactModule;
|
|
52
42
|
|
|
53
43
|
- (void)endRegisterReactModule;
|
|
54
44
|
|
|
55
|
-
- (HBDViewController *)
|
|
45
|
+
- (HBDViewController *)viewControllerWithModuleName:(NSString *)moduleName props:(NSDictionary *)props options:(NSDictionary *)options;
|
|
56
46
|
|
|
57
|
-
- (UIViewController *)
|
|
47
|
+
- (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout;
|
|
58
48
|
|
|
59
|
-
- (UIViewController *)
|
|
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 *)
|
|
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 *)
|
|
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)
|
|
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
|
-
|
|
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 ()
|
|
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)
|
|
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
|
|
85
|
-
|
|
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
|
|
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)
|
|
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 *)
|
|
111
|
+
- (NSDictionary *)reactModuleOptions:(NSString *)moduleName {
|
|
116
112
|
return _reactModules[moduleName];
|
|
117
113
|
}
|
|
118
114
|
|
|
119
|
-
- (BOOL)
|
|
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 *)
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
- (
|
|
158
|
-
|
|
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
|
|
173
|
-
NSDictionary *staticOptions = [[HBDReactBridgeManager get]
|
|
178
|
+
if ([self hasReactModule:moduleName]) {
|
|
179
|
+
NSDictionary *staticOptions = [[HBDReactBridgeManager get] reactModuleOptions:moduleName];
|
|
174
180
|
options = [HBDUtils mergeItem:options withTarget:staticOptions];
|
|
175
|
-
|
|
181
|
+
return [[HBDReactViewController alloc] initWithModuleName:moduleName props:props options:options];
|
|
176
182
|
} else {
|
|
177
|
-
Class clazz = [self
|
|
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
|
-
|
|
185
|
+
return [[clazz alloc] initWithModuleName:moduleName props:props options:options];
|
|
180
186
|
}
|
|
181
|
-
return vc;
|
|
182
187
|
}
|
|
183
188
|
|
|
184
|
-
- (UIViewController *)
|
|
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
|
|
195
|
+
return [self viewControllerWithSceneId:sceneId viewController:window.rootViewController];
|
|
190
196
|
}
|
|
191
197
|
|
|
192
|
-
- (UIViewController *)
|
|
193
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
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
|
-
|
|
279
|
-
return [navigator primaryViewControllerWithViewController:vc];
|
|
284
|
+
if (!layout) {
|
|
285
|
+
return nil;
|
|
280
286
|
}
|
|
281
|
-
|
|
282
|
-
return
|
|
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
|
|
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
|
|
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 *)
|
|
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
|
|
322
|
+
return [navigator routeGraphWithViewController:vc];
|
|
318
323
|
}
|
|
319
324
|
|
|
320
|
-
- (void)handleNavigationWithViewController:(UIViewController *)
|
|
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
|