hybrid-navigation 4.0.8 → 5.0.0
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/HybridNavigation.podspec +9 -1
- package/README.md +12 -4
- package/android/build.gradle +5 -4
- package/android/proguard-rules.pro +3 -0
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +114 -23
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +116 -13
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +83 -18
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +192 -28
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +11 -0
- package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +563 -143
- package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +47 -15
- package/android/src/main/java/com/navigation/androidx/PresentableActivity.java +3 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +8 -3
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +29 -9
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +28 -3
- package/android/src/main/java/com/navigation/androidx/SystemUI.java +59 -90
- package/android/src/main/java/com/navigation/androidx/TabBar.java +21 -2
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +24 -7
- package/android/src/main/java/com/navigation/androidx/TabView.java +11 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +59 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +18 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +15 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +3 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +113 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +13 -24
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +5 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +196 -194
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +499 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +4 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/OrientationCoordinator.java +162 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +103 -66
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +50 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +156 -77
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactSurfaceCleanup.java +3 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +8 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleState.java +21 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleStateMachine.java +116 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ScreenOrientation.java +42 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +17 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +14 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +62 -22
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +35 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +16 -13
- package/dist/DeepLink.d.ts +3 -2
- package/dist/DeepLink.js +37 -14
- package/dist/NativeEvent.d.ts +4 -12
- package/dist/NativeNavigation.d.ts +17 -19
- package/dist/Navigation.d.ts +21 -19
- package/dist/Navigation.js +83 -89
- package/dist/NavigationComponentWrap.d.ts +4 -3
- package/dist/NavigationComponentWrap.js +3 -6
- package/dist/Navigator.d.ts +31 -42
- package/dist/Navigator.js +97 -90
- package/dist/Options.d.ts +3 -1
- package/dist/Route.d.ts +85 -18
- package/dist/handler/DispatchCommandHandler.d.ts +10 -6
- package/dist/handler/DispatchCommandHandler.js +41 -17
- package/dist/handler/LayoutCommandHandler.d.ts +7 -7
- package/dist/handler/LayoutCommandHandler.js +21 -15
- package/dist/handler/LifecycleEventHandler.d.ts +26 -0
- package/dist/handler/LifecycleEventHandler.js +136 -0
- package/dist/handler/ResultEventHandler.d.ts +14 -9
- package/dist/handler/ResultEventHandler.js +88 -13
- package/dist/hooks.d.ts +5 -2
- package/dist/hooks.js +26 -4
- package/dist/index.d.ts +13 -0
- package/dist/index.js +0 -2
- package/dist/routeConfigRegistry.d.ts +6 -0
- package/dist/routeConfigRegistry.js +19 -0
- package/dist/router/drawer.d.ts +2 -2
- package/dist/router/drawer.js +6 -3
- package/dist/router/index.d.ts +8 -5
- package/dist/router/index.js +127 -43
- package/dist/router/screen.d.ts +2 -2
- package/dist/router/screen.js +1 -1
- package/dist/router/stack.d.ts +2 -2
- package/dist/router/stack.js +59 -30
- package/dist/router/tabs.d.ts +2 -2
- package/dist/router/tabs.js +4 -1
- package/dist/store.d.ts +2 -2
- package/ios/HBDGlobalStyle.h +26 -0
- package/ios/{GlobalStyle.mm → HBDGlobalStyle.mm} +30 -27
- package/ios/HybridNavigation.h +4 -1
- package/ios/Navigator/HBDDrawerNavigator.mm +24 -8
- package/ios/Navigator/HBDNavigatorRegistry.mm +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +106 -52
- package/ios/Navigator/HBDStackNavigator.mm +109 -61
- package/ios/Navigator/HBDTabNavigator.mm +32 -14
- package/ios/React/HBDNativeNavigation.mm +109 -131
- package/ios/React/HBDNavigator.h +29 -5
- package/ios/React/HBDOrientationCoordinator.h +27 -0
- package/ios/React/HBDOrientationCoordinator.mm +282 -0
- package/ios/React/HBDReactBridgeManager.h +37 -19
- package/ios/React/HBDReactBridgeManager.mm +490 -96
- package/ios/React/HBDSceneLifecycleStateMachine.h +38 -0
- package/ios/React/HBDSceneLifecycleStateMachine.mm +180 -0
- package/ios/View/HBDRootView.h +2 -0
- package/ios/View/HBDRootView.mm +148 -0
- package/ios/View/UIImage+WithBadge.h +3 -3
- package/ios/View/UIImage+WithBadge.mm +10 -15
- package/ios/ViewController/HBDDrawerController.mm +127 -6
- package/ios/ViewController/HBDNavigationController.mm +17 -4
- package/ios/ViewController/HBDReactViewController.mm +59 -121
- package/ios/ViewController/HBDTabBarController.h +4 -0
- package/ios/ViewController/HBDTabBarController.mm +59 -44
- package/ios/ViewController/HBDViewController.h +10 -3
- package/ios/ViewController/HBDViewController.mm +161 -147
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +3 -3
- package/ios/ViewController/UIViewController+HBD.h +17 -10
- package/ios/ViewController/UIViewController+HBD.mm +85 -69
- package/package.json +1 -1
- package/src/DeepLink.ts +41 -14
- package/src/NativeEvent.ts +4 -14
- package/src/NativeNavigation.ts +22 -33
- package/src/Navigation.ts +162 -121
- package/src/NavigationComponentWrap.tsx +9 -9
- package/src/Navigator.ts +191 -153
- package/src/Options.ts +3 -1
- package/src/Route.ts +134 -19
- package/src/handler/DispatchCommandHandler.ts +55 -21
- package/src/handler/LayoutCommandHandler.ts +36 -17
- package/src/handler/LifecycleEventHandler.ts +172 -0
- package/src/handler/ResultEventHandler.ts +112 -19
- package/src/hooks.ts +39 -7
- package/src/index.ts +26 -2
- package/src/routeConfigRegistry.ts +26 -0
- package/src/router/drawer.ts +8 -5
- package/src/router/index.ts +161 -50
- package/src/router/screen.ts +3 -3
- package/src/router/stack.ts +80 -29
- package/src/router/tabs.ts +15 -7
- package/src/store.ts +1 -1
- package/android/src/main/java/androidx/fragment/app/InternalFragment.java +0 -22
- package/android/src/main/java/com/navigation/androidx/SystemUI30.java +0 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +0 -176
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +0 -130
- package/android/src/main/res/layout/nav_tab_bar_react.xml +0 -32
- package/android/src/main/res/layout/nav_tab_bar_react_indeterminate.xml +0 -32
- package/dist/NativeGarden.d.ts +0 -13
- package/dist/NativeGarden.js +0 -2
- package/dist/handler/VisibilityEventHandler.d.ts +0 -13
- package/dist/handler/VisibilityEventHandler.js +0 -39
- package/ios/GlobalStyle.h +0 -15
- package/ios/React/HBDNativeGarden.h +0 -10
- package/ios/React/HBDNativeGarden.mm +0 -111
- package/src/NativeGarden.ts +0 -16
- package/src/handler/VisibilityEventHandler.ts +0 -52
|
@@ -1,16 +1,48 @@
|
|
|
1
1
|
#import "HBDReactBridgeManager.h"
|
|
2
2
|
|
|
3
|
-
#import "
|
|
4
|
-
#import "HBDReactViewController.h"
|
|
5
|
-
#import "HBDNavigatorRegistry.h"
|
|
3
|
+
#import "HBDGlobalStyle.h"
|
|
6
4
|
#import "HBDNativeEvent.h"
|
|
5
|
+
#import "HBDNavigatorRegistry.h"
|
|
6
|
+
#import "HBDReactViewController.h"
|
|
7
|
+
#import "HBDTabBarController.h"
|
|
8
|
+
#import "HBDUtils.h"
|
|
9
|
+
#import "UIViewController+HBD.h"
|
|
7
10
|
|
|
8
11
|
#import <React/RCTLog.h>
|
|
12
|
+
#import <React/RCTUtils.h>
|
|
13
|
+
|
|
14
|
+
NSString *const HBDReactModuleRegistryDidCompletedNotification = @"HBDReactModuleRegistryDidCompletedNotification";
|
|
15
|
+
NSString *const HBDReactBridgeWillReloadNotification = @"HBDReactBridgeWillReloadNotification";
|
|
16
|
+
const NSInteger HBDResultOK = -1;
|
|
17
|
+
const NSInteger HBDResultCancel = 0;
|
|
18
|
+
const NSInteger HBDResultBlock = -2;
|
|
19
|
+
|
|
20
|
+
static const NSTimeInterval HBDCommandTimeoutSeconds = 3.0;
|
|
21
|
+
|
|
22
|
+
typedef NS_ENUM(NSInteger, HBDCommandType) {
|
|
23
|
+
HBDCommandTypeDispatch,
|
|
24
|
+
HBDCommandTypeSetRoot,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
@interface HBDNavigationCommand : NSObject
|
|
28
|
+
@property(nonatomic, assign) HBDCommandType type;
|
|
29
|
+
@property(nonatomic, copy, nullable) NSString *sceneId;
|
|
30
|
+
@property(nonatomic, copy, nullable) NSString *action;
|
|
31
|
+
@property(nonatomic, copy, nullable) NSDictionary *extras;
|
|
32
|
+
@property(nonatomic, copy, nullable) NSDictionary *layout;
|
|
33
|
+
@property(nonatomic, copy, nullable) HBDDispatchCompletion completion;
|
|
34
|
+
@end
|
|
35
|
+
|
|
36
|
+
@implementation HBDNavigationCommand
|
|
37
|
+
@end
|
|
9
38
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
39
|
+
@interface HBDReadyTask : NSObject
|
|
40
|
+
@property(nonatomic, copy) dispatch_block_t task;
|
|
41
|
+
@property(nonatomic, copy, nullable) dispatch_block_t onCancelled;
|
|
42
|
+
@end
|
|
43
|
+
|
|
44
|
+
@implementation HBDReadyTask
|
|
45
|
+
@end
|
|
14
46
|
|
|
15
47
|
@interface HBDReactBridgeManager ()
|
|
16
48
|
|
|
@@ -19,6 +51,17 @@ const NSInteger ResultBlock = -2;
|
|
|
19
51
|
@property(nonatomic, assign, readwrite, getter=isReactModuleRegisterCompleted) BOOL reactModuleRegisterCompleted;
|
|
20
52
|
@property(nonatomic, strong) HBDNavigatorRegistry *navigatorRegistry;
|
|
21
53
|
|
|
54
|
+
@property(nonatomic, strong, nullable) UIWindow *window;
|
|
55
|
+
@property(nonatomic, strong) NSMutableArray<HBDReadyTask *> *viewHierarchyReadyTasks;
|
|
56
|
+
@property(nonatomic, assign) BOOL flushingViewHierarchyReadyTasks;
|
|
57
|
+
@property(nonatomic, strong) NSMutableArray<HBDNavigationCommand *> *commandQueue;
|
|
58
|
+
@property(nonatomic, assign) BOOL executingCommand;
|
|
59
|
+
@property(nonatomic, assign) NSUInteger commandQueueGeneration;
|
|
60
|
+
@property(nonatomic, assign) NSUInteger rootGeneration;
|
|
61
|
+
@property(nonatomic, strong, nullable) HBDNavigationCommand *activeCommand;
|
|
62
|
+
@property(nonatomic, assign, readwrite) NSUInteger activeCommandId;
|
|
63
|
+
@property(nonatomic, assign) NSUInteger nextCommandId;
|
|
64
|
+
|
|
22
65
|
@end
|
|
23
66
|
|
|
24
67
|
@implementation HBDReactBridgeManager
|
|
@@ -37,38 +80,398 @@ const NSInteger ResultBlock = -2;
|
|
|
37
80
|
_nativeModules = [[NSMutableDictionary alloc] init];
|
|
38
81
|
_reactModules = [[NSMutableDictionary alloc] init];
|
|
39
82
|
_reactModuleRegisterCompleted = NO;
|
|
40
|
-
_viewHierarchyReady = NO;
|
|
41
83
|
_navigatorRegistry = [[HBDNavigatorRegistry alloc] init];
|
|
84
|
+
_globalStyle = [[HBDGlobalStyle alloc] initWithOptions:@{}];
|
|
85
|
+
_viewHierarchyReadyTasks = [NSMutableArray array];
|
|
86
|
+
_commandQueue = [NSMutableArray array];
|
|
42
87
|
}
|
|
43
88
|
return self;
|
|
44
89
|
}
|
|
45
90
|
|
|
46
|
-
- (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
91
|
+
- (void)setGlobalStyle:(HBDGlobalStyle *)globalStyle {
|
|
92
|
+
_globalStyle = globalStyle ?: [[HBDGlobalStyle alloc] initWithOptions:@{}];
|
|
93
|
+
[self applyGlobalStyleToHierarchy];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#pragma mark - Window Resolution
|
|
97
|
+
|
|
98
|
+
- (nullable UIWindow *)mainWindow {
|
|
99
|
+
if (self.window) {
|
|
100
|
+
return self.window;
|
|
101
|
+
}
|
|
102
|
+
UIWindow *resolved = [self discoverDefaultWindow];
|
|
103
|
+
self.window = resolved;
|
|
104
|
+
return resolved;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
- (nullable UIWindowScene *)activeWindowScene {
|
|
108
|
+
NSSet<UIScene *> *connectedScenes = RCTSharedApplication().connectedScenes;
|
|
109
|
+
UIWindowScene *fallbackScene = nil;
|
|
110
|
+
for (UIScene *scene in connectedScenes) {
|
|
111
|
+
if (![scene isKindOfClass:[UIWindowScene class]]) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
UIWindowScene *windowScene = (UIWindowScene *)scene;
|
|
115
|
+
if (windowScene.activationState == UISceneActivationStateForegroundActive) {
|
|
116
|
+
return windowScene;
|
|
117
|
+
}
|
|
118
|
+
if (!fallbackScene || windowScene.activationState == UISceneActivationStateForegroundInactive) {
|
|
119
|
+
fallbackScene = windowScene;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return fallbackScene;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
- (nullable UIWindow *)discoverDefaultWindow {
|
|
126
|
+
UIWindowScene *windowScene = [self activeWindowScene];
|
|
127
|
+
if (windowScene) {
|
|
128
|
+
id<UISceneDelegate> sceneDelegate = windowScene.delegate;
|
|
129
|
+
if ([sceneDelegate respondsToSelector:@selector(window)]) {
|
|
130
|
+
UIWindow *delegateWindow = [(id<UIWindowSceneDelegate>)sceneDelegate window];
|
|
131
|
+
if (delegateWindow) {
|
|
132
|
+
return delegateWindow;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (@available(iOS 15.0, *)) {
|
|
136
|
+
if (windowScene.keyWindow) {
|
|
137
|
+
return windowScene.keyWindow;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (UIWindow *window in windowScene.windows) {
|
|
141
|
+
if (window.isKeyWindow) {
|
|
142
|
+
return window;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (windowScene.windows.firstObject) {
|
|
146
|
+
return windowScene.windows.firstObject;
|
|
147
|
+
}
|
|
148
|
+
UIWindow *newWindow = [[UIWindow alloc] initWithWindowScene:windowScene];
|
|
149
|
+
newWindow.backgroundColor = UIColor.whiteColor;
|
|
150
|
+
if ([sceneDelegate respondsToSelector:@selector(setWindow:)]) {
|
|
151
|
+
[(id<UIWindowSceneDelegate>)sceneDelegate setWindow:newWindow];
|
|
152
|
+
}
|
|
153
|
+
return newWindow;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
id<UIApplicationDelegate> appDelegate = RCTSharedApplication().delegate;
|
|
157
|
+
UIWindow *appWindow = [appDelegate respondsToSelector:@selector(window)] ? appDelegate.window : nil;
|
|
158
|
+
if (!appWindow) {
|
|
159
|
+
appWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
|
160
|
+
appWindow.backgroundColor = UIColor.whiteColor;
|
|
161
|
+
if ([appDelegate respondsToSelector:@selector(setWindow:)]) {
|
|
162
|
+
appDelegate.window = appWindow;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return appWindow;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
#pragma mark - Readiness Gate & Command Queue
|
|
169
|
+
|
|
170
|
+
- (void)setViewHierarchyReady:(BOOL)viewHierarchyReady {
|
|
171
|
+
_viewHierarchyReady = viewHierarchyReady;
|
|
172
|
+
if (viewHierarchyReady) {
|
|
173
|
+
[self flushViewHierarchyReadyTasks];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
- (void)runWhenViewHierarchyReady:(dispatch_block_t)task {
|
|
178
|
+
[self runWhenViewHierarchyReady:task onCancelled:nil];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
- (void)runWhenViewHierarchyReady:(dispatch_block_t)task onCancelled:(nullable dispatch_block_t)onCancelled {
|
|
182
|
+
if (!task) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
HBDReadyTask *entry = [HBDReadyTask new];
|
|
186
|
+
entry.task = task;
|
|
187
|
+
entry.onCancelled = onCancelled;
|
|
188
|
+
[self.viewHierarchyReadyTasks addObject:entry];
|
|
189
|
+
if (self.isViewHierarchyReady) {
|
|
190
|
+
[self flushViewHierarchyReadyTasks];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
- (void)flushViewHierarchyReadyTasks {
|
|
195
|
+
if (!self.isViewHierarchyReady || self.flushingViewHierarchyReadyTasks) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
self.flushingViewHierarchyReadyTasks = YES;
|
|
200
|
+
while (self.isViewHierarchyReady && self.viewHierarchyReadyTasks.count > 0) {
|
|
201
|
+
HBDReadyTask *entry = self.viewHierarchyReadyTasks.firstObject;
|
|
202
|
+
[self.viewHierarchyReadyTasks removeObjectAtIndex:0];
|
|
203
|
+
if (entry.task) {
|
|
204
|
+
entry.task();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
self.flushingViewHierarchyReadyTasks = NO;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
- (void)enqueueNavigationWithSceneId:(NSString *)sceneId
|
|
211
|
+
action:(NSString *)action
|
|
212
|
+
extras:(NSDictionary *)extras
|
|
213
|
+
completion:(nullable HBDDispatchCompletion)completion {
|
|
214
|
+
HBDNavigationCommand *command = [HBDNavigationCommand new];
|
|
215
|
+
command.type = HBDCommandTypeDispatch;
|
|
216
|
+
command.sceneId = sceneId;
|
|
217
|
+
command.action = action;
|
|
218
|
+
command.extras = extras;
|
|
219
|
+
command.completion = completion;
|
|
220
|
+
[self.commandQueue addObject:command];
|
|
221
|
+
[self drainCommandQueue];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
- (void)enqueueSetRootWithLayout:(NSDictionary *)layout completion:(nullable HBDDispatchCompletion)completion {
|
|
225
|
+
NSArray<HBDNavigationCommand *> *superseded = [self.commandQueue copy];
|
|
226
|
+
[self.commandQueue removeAllObjects];
|
|
227
|
+
for (HBDNavigationCommand *cmd in superseded) {
|
|
228
|
+
if (cmd.completion) {
|
|
229
|
+
HBDDispatchCompletion cb = cmd.completion;
|
|
230
|
+
cmd.completion = nil;
|
|
231
|
+
cb(HBDDispatchResultFail(HBDDispatchCodeSuperseded, @"Navigation command was superseded by a newer setRoot call."));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
HBDNavigationCommand *command = [HBDNavigationCommand new];
|
|
236
|
+
command.type = HBDCommandTypeSetRoot;
|
|
237
|
+
command.layout = layout;
|
|
238
|
+
command.completion = completion;
|
|
239
|
+
[self.commandQueue addObject:command];
|
|
240
|
+
[self drainCommandQueue];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
- (void)drainCommandQueue {
|
|
244
|
+
if (self.executingCommand || self.commandQueue.count == 0) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
HBDNavigationCommand *peek = self.commandQueue.firstObject;
|
|
249
|
+
if (peek.type == HBDCommandTypeSetRoot && !self.isReactModuleRegisterCompleted) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
HBDNavigationCommand *command = self.commandQueue.firstObject;
|
|
254
|
+
[self.commandQueue removeObjectAtIndex:0];
|
|
255
|
+
self.executingCommand = YES;
|
|
256
|
+
self.activeCommand = command;
|
|
257
|
+
self.activeCommandId = ++self.nextCommandId;
|
|
258
|
+
|
|
259
|
+
NSUInteger generation = self.commandQueueGeneration;
|
|
260
|
+
__block BOOL completed = NO;
|
|
261
|
+
HBDDispatchCompletion finishCommand = ^(NSDictionary *result) {
|
|
262
|
+
if (completed) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
completed = YES;
|
|
266
|
+
HBDDispatchCompletion callback = command.completion;
|
|
267
|
+
command.completion = nil;
|
|
268
|
+
if (self.activeCommand == command) {
|
|
269
|
+
self.activeCommand = nil;
|
|
270
|
+
self.activeCommandId = 0;
|
|
271
|
+
}
|
|
272
|
+
if (generation != self.commandQueueGeneration) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (callback) {
|
|
276
|
+
callback(result ?: HBDDispatchResultFail(HBDDispatchCodeInvalidAction, nil));
|
|
277
|
+
}
|
|
278
|
+
self.executingCommand = NO;
|
|
279
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
280
|
+
[self drainCommandQueue];
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(HBDCommandTimeoutSeconds * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
285
|
+
if (!completed && generation == self.commandQueueGeneration) {
|
|
286
|
+
RCTLogWarn(@"[Navigation] Navigation command timed out, unlocking command queue. action=%@", command.action ?: @"setRoot");
|
|
287
|
+
if (command.type == HBDCommandTypeSetRoot) {
|
|
288
|
+
self.rootGeneration += 1;
|
|
289
|
+
if (self.didSetRoot == finishCommand) {
|
|
290
|
+
self.didSetRoot = NULL;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
finishCommand(HBDDispatchResultFail(HBDDispatchCodeNotReady, @"Navigation command timed out."));
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
if (command.type == HBDCommandTypeSetRoot) {
|
|
298
|
+
UIViewController *vc = [self viewControllerWithLayout:command.layout];
|
|
299
|
+
if (!vc) {
|
|
300
|
+
RCTLogError(@"[Navigation] 无法创建 ViewController for layout: %@", command.layout);
|
|
301
|
+
finishCommand(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create ViewController for layout."));
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (![self mainWindow]) {
|
|
305
|
+
finishCommand(HBDDispatchResultFail(HBDDispatchCodeHostUnavailable, @"Navigation host window is unavailable."));
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
self.viewHierarchyReady = NO;
|
|
309
|
+
self.hasRootLayout = YES;
|
|
310
|
+
if (self.didSetRoot) {
|
|
311
|
+
self.didSetRoot(HBDDispatchResultFail(HBDDispatchCodeSuperseded, @"setRoot was superseded by a newer call."));
|
|
312
|
+
}
|
|
313
|
+
self.didSetRoot = finishCommand;
|
|
314
|
+
[self setRootViewController:vc];
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
UIViewController *vc = [self viewControllerBySceneId:command.sceneId];
|
|
319
|
+
if (!vc) {
|
|
320
|
+
RCTLogInfo(@"[Navigation] Can't find target scene for action: %@", command.action);
|
|
321
|
+
finishCommand(HBDDispatchResultFail(HBDDispatchCodeSceneNotFound, [NSString stringWithFormat:@"Can't find target scene for action: %@", command.action]));
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
[self handleNavigationWithViewController:vc action:command.action extras:command.extras completion:finishCommand];
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
- (void)setRootViewController:(UIViewController *)rootViewController {
|
|
329
|
+
NSUInteger generation = self.commandQueueGeneration;
|
|
330
|
+
NSUInteger rootGen = ++self.rootGeneration;
|
|
331
|
+
UIWindow *targetWindow = [self mainWindow];
|
|
332
|
+
if (!targetWindow) {
|
|
333
|
+
HBDDispatchCompletion didSetRoot = self.didSetRoot;
|
|
334
|
+
self.didSetRoot = NULL;
|
|
335
|
+
if (didSetRoot) {
|
|
336
|
+
didSetRoot(HBDDispatchResultFail(HBDDispatchCodeHostUnavailable, @"Navigation host window is unavailable."));
|
|
337
|
+
}
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
UIViewController *presentedViewController = targetWindow.rootViewController.presentedViewController;
|
|
342
|
+
if (presentedViewController && !presentedViewController.isBeingDismissed) {
|
|
343
|
+
[targetWindow.rootViewController dismissViewControllerAnimated:NO completion:^{
|
|
344
|
+
if (generation != self.commandQueueGeneration || rootGen != self.rootGeneration) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
[self performSetRootViewController:rootViewController onWindow:targetWindow animated:NO rootGeneration:rootGen];
|
|
348
|
+
}];
|
|
349
|
+
} else {
|
|
350
|
+
[self performSetRootViewController:rootViewController onWindow:targetWindow animated:YES rootGeneration:rootGen];
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
- (void)performSetRootViewController:(UIViewController *)rootViewController
|
|
355
|
+
onWindow:(UIWindow *)targetWindow
|
|
356
|
+
animated:(BOOL)animated
|
|
357
|
+
rootGeneration:(NSUInteger)rootGen {
|
|
358
|
+
NSUInteger generation = self.commandQueueGeneration;
|
|
359
|
+
[[HBDNativeEvent getInstance] emitWillSetRoot];
|
|
360
|
+
void (^applyRoot)(void) = ^{
|
|
361
|
+
targetWindow.rootViewController = rootViewController;
|
|
362
|
+
targetWindow.windowLevel = UIWindowLevelNormal;
|
|
363
|
+
if (!targetWindow.isKeyWindow) {
|
|
364
|
+
[targetWindow makeKeyAndVisible];
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
void (^completeRoot)(void) = ^{
|
|
368
|
+
if (generation != self.commandQueueGeneration || rootGen != self.rootGeneration) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
HBDDispatchCompletion didSetRoot = self.didSetRoot;
|
|
372
|
+
self.didSetRoot = NULL;
|
|
373
|
+
self.viewHierarchyReady = YES;
|
|
374
|
+
if (didSetRoot) {
|
|
375
|
+
didSetRoot(HBDDispatchResultOk());
|
|
376
|
+
}
|
|
377
|
+
[[HBDNativeEvent getInstance] emitDidSetRoot];
|
|
378
|
+
};
|
|
379
|
+
if (animated) {
|
|
380
|
+
[UIView transitionWithView:targetWindow duration:0.15f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
|
|
381
|
+
BOOL oldState = [UIView areAnimationsEnabled];
|
|
382
|
+
[UIView setAnimationsEnabled:NO];
|
|
383
|
+
applyRoot();
|
|
384
|
+
[UIView setAnimationsEnabled:oldState];
|
|
385
|
+
} completion:^(BOOL finished) {
|
|
386
|
+
completeRoot();
|
|
387
|
+
}];
|
|
388
|
+
} else {
|
|
389
|
+
applyRoot();
|
|
390
|
+
completeRoot();
|
|
52
391
|
}
|
|
53
|
-
return mainWindow;
|
|
54
392
|
}
|
|
55
393
|
|
|
56
394
|
- (void)invalidate {
|
|
57
395
|
RCTLogInfo(@"[Navigation] HBDReactBridgeManager#invalidate");
|
|
58
396
|
[NSObject cancelPreviousPerformRequestsWithTarget:self];
|
|
59
|
-
|
|
60
|
-
|
|
397
|
+
|
|
398
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:HBDReactBridgeWillReloadNotification object:self];
|
|
399
|
+
|
|
400
|
+
self.commandQueueGeneration += 1;
|
|
401
|
+
self.rootGeneration += 1;
|
|
402
|
+
self.executingCommand = NO;
|
|
403
|
+
self.activeCommandId = 0;
|
|
404
|
+
|
|
405
|
+
HBDNavigationCommand *activeCommand = self.activeCommand;
|
|
406
|
+
self.activeCommand = nil;
|
|
407
|
+
NSArray<HBDNavigationCommand *> *pendingCommands = [self.commandQueue copy];
|
|
408
|
+
[self.commandQueue removeAllObjects];
|
|
409
|
+
HBDDispatchCompletion didSetRoot = self.didSetRoot;
|
|
410
|
+
self.didSetRoot = NULL;
|
|
411
|
+
NSArray<HBDReadyTask *> *pendingReadyTasks = [self.viewHierarchyReadyTasks copy];
|
|
412
|
+
[self.viewHierarchyReadyTasks removeAllObjects];
|
|
413
|
+
self.viewHierarchyReady = NO;
|
|
414
|
+
|
|
415
|
+
NSDictionary *unavailable = HBDDispatchResultFail(HBDDispatchCodeHostUnavailable, @"Navigation host was invalidated.");
|
|
416
|
+
if (activeCommand) {
|
|
417
|
+
HBDDispatchCompletion completion = activeCommand.completion;
|
|
418
|
+
activeCommand.completion = nil;
|
|
419
|
+
if (completion) {
|
|
420
|
+
completion(unavailable);
|
|
421
|
+
}
|
|
422
|
+
} else if (didSetRoot) {
|
|
423
|
+
didSetRoot(unavailable);
|
|
424
|
+
}
|
|
425
|
+
for (HBDNavigationCommand *command in pendingCommands) {
|
|
426
|
+
HBDDispatchCompletion completion = command.completion;
|
|
427
|
+
command.completion = nil;
|
|
428
|
+
if (completion) {
|
|
429
|
+
completion(unavailable);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
for (HBDReadyTask *entry in pendingReadyTasks) {
|
|
433
|
+
if (entry.onCancelled) {
|
|
434
|
+
entry.onCancelled();
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
NSArray<id<HBDNavigator>> *navigators = [self.navigatorRegistry allNavigators];
|
|
61
439
|
for (id<HBDNavigator> navigator in navigators) {
|
|
62
440
|
[navigator invalidate];
|
|
63
441
|
}
|
|
64
442
|
|
|
65
|
-
self.viewHierarchyReady = NO;
|
|
66
443
|
self.reactModuleRegisterCompleted = NO;
|
|
67
|
-
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
#pragma mark - Global Style & Registry
|
|
447
|
+
|
|
448
|
+
- (void)applyGlobalStyleToHierarchy {
|
|
449
|
+
UIWindow *targetWindow = self.window;
|
|
450
|
+
if (!targetWindow.rootViewController) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
HBDGlobalStyle *style = self.globalStyle ?: [HBDGlobalStyle globalStyle];
|
|
454
|
+
[self applyGlobalStyle:style toViewController:targetWindow.rootViewController];
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
- (void)applyGlobalStyle:(HBDGlobalStyle *)style toViewController:(UIViewController *)vc {
|
|
458
|
+
if (!vc) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
if ([vc isKindOfClass:[HBDTabBarController class]]) {
|
|
462
|
+
[(HBDTabBarController *)vc applyGlobalStyle:style];
|
|
463
|
+
}
|
|
464
|
+
for (UIViewController *child in vc.childViewControllers) {
|
|
465
|
+
[self applyGlobalStyle:style toViewController:child];
|
|
466
|
+
}
|
|
467
|
+
UIViewController *presented = vc.presentedViewController;
|
|
468
|
+
if (presented && presented != vc && !presented.isBeingDismissed) {
|
|
469
|
+
[self applyGlobalStyle:style toViewController:presented];
|
|
470
|
+
}
|
|
68
471
|
}
|
|
69
472
|
|
|
70
473
|
- (void)installWithReactHost:(RCTHost *)rctHost {
|
|
71
|
-
|
|
474
|
+
_rctHost = rctHost;
|
|
72
475
|
}
|
|
73
476
|
|
|
74
477
|
- (void)registerNativeModule:(NSString *)moduleName forViewController:(Class)clazz {
|
|
@@ -102,27 +505,30 @@ const NSInteger ResultBlock = -2;
|
|
|
102
505
|
|
|
103
506
|
- (void)endRegisterReactModule {
|
|
104
507
|
_reactModuleRegisterCompleted = YES;
|
|
508
|
+
[self drainCommandQueue];
|
|
105
509
|
if (self.delegate != nil) {
|
|
106
510
|
[self.delegate reactModuleRegisterDidCompleted:self];
|
|
107
511
|
}
|
|
108
|
-
[[NSNotificationCenter defaultCenter] postNotificationName:
|
|
512
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:HBDReactModuleRegistryDidCompletedNotification object:nil];
|
|
109
513
|
}
|
|
110
514
|
|
|
515
|
+
#pragma mark - ViewController Factory & Hierarchy Queries
|
|
516
|
+
|
|
111
517
|
- (UIViewController *)createViewControllerWithLayout:(NSDictionary *)layout {
|
|
112
518
|
NSArray<NSString *> *layouts = [self.navigatorRegistry allLayouts];
|
|
113
519
|
for (NSString *name in layouts) {
|
|
114
520
|
if (![[layout allKeys] containsObject:name]) {
|
|
115
521
|
continue;
|
|
116
522
|
}
|
|
117
|
-
|
|
118
|
-
id
|
|
523
|
+
|
|
524
|
+
id<HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:name];
|
|
119
525
|
UIViewController *vc = [navigator viewControllerWithLayout:layout];
|
|
120
526
|
if (vc) {
|
|
121
527
|
[self.navigatorRegistry setLayout:name forViewController:vc];
|
|
122
528
|
}
|
|
123
529
|
return vc;
|
|
124
530
|
}
|
|
125
|
-
|
|
531
|
+
|
|
126
532
|
return nil;
|
|
127
533
|
}
|
|
128
534
|
|
|
@@ -132,7 +538,7 @@ const NSInteger ResultBlock = -2;
|
|
|
132
538
|
}
|
|
133
539
|
|
|
134
540
|
UIViewController *vc = [self createViewControllerWithLayout:layout];
|
|
135
|
-
|
|
541
|
+
|
|
136
542
|
if (!vc) {
|
|
137
543
|
RCTLogError(@"[Navigation] Can't find a navigator that can handle layout '%@'. Did you forget to register?", layout);
|
|
138
544
|
return nil;
|
|
@@ -155,7 +561,7 @@ const NSInteger ResultBlock = -2;
|
|
|
155
561
|
}
|
|
156
562
|
|
|
157
563
|
if ([self hasReactModule:moduleName]) {
|
|
158
|
-
NSDictionary *staticOptions = [
|
|
564
|
+
NSDictionary *staticOptions = [self reactModuleOptions:moduleName];
|
|
159
565
|
options = [HBDUtils mergeItem:options withTarget:staticOptions];
|
|
160
566
|
return [[HBDReactViewController alloc] initWithModuleName:moduleName props:props options:options];
|
|
161
567
|
} else {
|
|
@@ -165,13 +571,16 @@ const NSInteger ResultBlock = -2;
|
|
|
165
571
|
}
|
|
166
572
|
}
|
|
167
573
|
|
|
168
|
-
- (UIViewController *)viewControllerBySceneId:(NSString *)sceneId {
|
|
169
|
-
UIWindow *
|
|
170
|
-
return [self viewControllerWithSceneId:sceneId viewController:
|
|
574
|
+
- (nullable UIViewController *)viewControllerBySceneId:(NSString *)sceneId {
|
|
575
|
+
UIWindow *targetWindow = [self mainWindow];
|
|
576
|
+
return [self viewControllerWithSceneId:sceneId viewController:targetWindow.rootViewController];
|
|
171
577
|
}
|
|
172
578
|
|
|
173
|
-
- (UIViewController *)viewControllerWithSceneId:(NSString *)sceneId viewController:(UIViewController *)vc {
|
|
174
|
-
if (
|
|
579
|
+
- (nullable UIViewController *)viewControllerWithSceneId:(NSString *)sceneId viewController:(nullable UIViewController *)vc {
|
|
580
|
+
if (!vc) {
|
|
581
|
+
return nil;
|
|
582
|
+
}
|
|
583
|
+
if ([vc.hbd_sceneId isEqualToString:sceneId]) {
|
|
175
584
|
return vc;
|
|
176
585
|
}
|
|
177
586
|
|
|
@@ -183,12 +592,7 @@ const NSInteger ResultBlock = -2;
|
|
|
183
592
|
}
|
|
184
593
|
}
|
|
185
594
|
|
|
186
|
-
|
|
187
|
-
if (children.count == 0) {
|
|
188
|
-
return nil;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
for (UIViewController *child in children) {
|
|
595
|
+
for (UIViewController *child in vc.childViewControllers) {
|
|
192
596
|
UIViewController *target = [self viewControllerWithSceneId:sceneId viewController:child];
|
|
193
597
|
if (target) {
|
|
194
598
|
return target;
|
|
@@ -198,59 +602,46 @@ const NSInteger ResultBlock = -2;
|
|
|
198
602
|
return nil;
|
|
199
603
|
}
|
|
200
604
|
|
|
201
|
-
- (
|
|
202
|
-
UIWindow *
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
[mainWindow.rootViewController dismissViewControllerAnimated:NO completion:^{
|
|
206
|
-
[self performSetRootViewController:rootViewController animated:NO];
|
|
207
|
-
}];
|
|
208
|
-
} else {
|
|
209
|
-
[self performSetRootViewController:rootViewController animated:YES];
|
|
605
|
+
- (nullable NSString *)findSceneIdByModuleName:(NSString *)moduleName {
|
|
606
|
+
UIWindow *targetWindow = [self mainWindow];
|
|
607
|
+
if (!targetWindow.rootViewController) {
|
|
608
|
+
return nil;
|
|
210
609
|
}
|
|
610
|
+
return [self findSceneIdByModuleName:moduleName withViewController:targetWindow.rootViewController];
|
|
211
611
|
}
|
|
212
612
|
|
|
213
|
-
- (
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
mainWindow.windowLevel = UIWindowLevelNormal;
|
|
222
|
-
if (!mainWindow.isKeyWindow) {
|
|
223
|
-
[mainWindow makeKeyAndVisible];
|
|
224
|
-
}
|
|
225
|
-
[UIView setAnimationsEnabled:oldState];
|
|
226
|
-
} completion:^(BOOL finished) {
|
|
227
|
-
self.viewHierarchyReady = YES;
|
|
228
|
-
if (self.didSetRoot) {
|
|
229
|
-
self.didSetRoot(@[NSNull.null, @YES]);
|
|
230
|
-
self.didSetRoot = NULL;
|
|
231
|
-
}
|
|
232
|
-
[[HBDNativeEvent getInstance] emitDidSetRoot];
|
|
233
|
-
}];
|
|
234
|
-
} else {
|
|
235
|
-
mainWindow.rootViewController = rootViewController;
|
|
236
|
-
mainWindow.windowLevel = UIWindowLevelNormal;
|
|
237
|
-
if (!mainWindow.isKeyWindow) {
|
|
238
|
-
[mainWindow makeKeyAndVisible];
|
|
613
|
+
- (nullable NSString *)findSceneIdByModuleName:(NSString *)moduleName withViewController:(nullable UIViewController *)vc {
|
|
614
|
+
if (!vc) {
|
|
615
|
+
return nil;
|
|
616
|
+
}
|
|
617
|
+
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
618
|
+
HBDViewController *hbd = (HBDViewController *)vc;
|
|
619
|
+
if ([moduleName isEqualToString:hbd.moduleName]) {
|
|
620
|
+
return hbd.hbd_sceneId;
|
|
239
621
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
UIViewController *presented = vc.presentedViewController;
|
|
625
|
+
if (presented && vc != presented && !presented.isBeingDismissed) {
|
|
626
|
+
NSString *sceneId = [self findSceneIdByModuleName:moduleName withViewController:presented];
|
|
627
|
+
if (sceneId) {
|
|
628
|
+
return sceneId;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
for (UIViewController *child in vc.childViewControllers) {
|
|
633
|
+
NSString *sceneId = [self findSceneIdByModuleName:moduleName withViewController:child];
|
|
634
|
+
if (sceneId) {
|
|
635
|
+
return sceneId;
|
|
245
636
|
}
|
|
246
|
-
[[HBDNativeEvent getInstance] emitDidSetRoot];
|
|
247
637
|
}
|
|
638
|
+
|
|
639
|
+
return nil;
|
|
248
640
|
}
|
|
249
641
|
|
|
250
|
-
- (HBDViewController *)primaryViewController {
|
|
251
|
-
UIWindow *
|
|
252
|
-
|
|
253
|
-
return [self primaryViewControllerWithViewController:controller];
|
|
642
|
+
- (nullable HBDViewController *)primaryViewController {
|
|
643
|
+
UIWindow *targetWindow = [self mainWindow];
|
|
644
|
+
return [self primaryViewControllerWithViewController:targetWindow.rootViewController];
|
|
254
645
|
}
|
|
255
646
|
|
|
256
647
|
- (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc {
|
|
@@ -261,19 +652,24 @@ const NSInteger ResultBlock = -2;
|
|
|
261
652
|
|
|
262
653
|
NSString *layout = [self.navigatorRegistry layoutForViewController:vc];
|
|
263
654
|
if (layout) {
|
|
264
|
-
id
|
|
655
|
+
id<HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:layout];
|
|
265
656
|
return [navigator primaryViewControllerWithViewController:vc];
|
|
266
657
|
}
|
|
267
|
-
|
|
658
|
+
|
|
268
659
|
return nil;
|
|
269
660
|
}
|
|
270
661
|
|
|
271
662
|
- (NSArray *)routeGraph {
|
|
272
|
-
UIWindow *
|
|
273
|
-
UIViewController *vc =
|
|
663
|
+
UIWindow *targetWindow = [self mainWindow];
|
|
664
|
+
UIViewController *vc = targetWindow.rootViewController;
|
|
665
|
+
if (!vc) {
|
|
666
|
+
return @[];
|
|
667
|
+
}
|
|
274
668
|
NSDictionary *graph = [self routeGraphWithViewController:vc];
|
|
275
669
|
NSMutableArray *root = [[NSMutableArray alloc] init];
|
|
276
|
-
|
|
670
|
+
if (graph) {
|
|
671
|
+
[root addObject:graph];
|
|
672
|
+
}
|
|
277
673
|
[root addObjectsFromArray:[self presentedGraphsWithRootViewController:vc]];
|
|
278
674
|
return root;
|
|
279
675
|
}
|
|
@@ -281,38 +677,36 @@ const NSInteger ResultBlock = -2;
|
|
|
281
677
|
- (NSArray *)presentedGraphsWithRootViewController:(UIViewController *)vc {
|
|
282
678
|
NSMutableArray *graphs = [[NSMutableArray alloc] init];
|
|
283
679
|
UIViewController *presented = vc.presentedViewController;
|
|
284
|
-
|
|
285
|
-
while (presented && !presented.beingDismissed && ![presented isKindOfClass:[UIAlertController class]]) {
|
|
680
|
+
while (presented && !presented.isBeingDismissed && ![presented isKindOfClass:[UIAlertController class]]) {
|
|
286
681
|
NSDictionary *graph = [self routeGraphWithViewController:presented];
|
|
287
682
|
if (graph) {
|
|
288
683
|
[graphs addObject:graph];
|
|
289
684
|
}
|
|
290
685
|
presented = presented.presentedViewController;
|
|
291
686
|
}
|
|
292
|
-
|
|
293
687
|
return graphs;
|
|
294
688
|
}
|
|
295
689
|
|
|
296
690
|
- (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc {
|
|
297
691
|
NSString *layout = [self.navigatorRegistry layoutForViewController:vc];
|
|
298
692
|
if (layout) {
|
|
299
|
-
id
|
|
693
|
+
id<HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:layout];
|
|
300
694
|
return [navigator routeGraphWithViewController:vc];
|
|
301
695
|
}
|
|
302
696
|
return nil;
|
|
303
697
|
}
|
|
304
698
|
|
|
305
|
-
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras
|
|
306
|
-
id
|
|
699
|
+
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
700
|
+
id<HBDNavigator> navigator = [self.navigatorRegistry navigatorForAction:action];
|
|
307
701
|
if (!navigator) {
|
|
308
702
|
RCTLogInfo(@"[Navigation] Can't find a navigator that can handle action '%@'", action);
|
|
309
|
-
|
|
703
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"No navigator registered for action: %@", action]));
|
|
310
704
|
return;
|
|
311
705
|
}
|
|
312
|
-
[navigator handleNavigationWithViewController:vc action:action extras:extras
|
|
706
|
+
[navigator handleNavigationWithViewController:vc action:action extras:extras completion:completion];
|
|
313
707
|
}
|
|
314
708
|
|
|
315
|
-
- (void)registerNavigator:(id
|
|
709
|
+
- (void)registerNavigator:(id<HBDNavigator>)navigator {
|
|
316
710
|
[self.navigatorRegistry registerNavigator:navigator];
|
|
317
711
|
}
|
|
318
712
|
|