hybrid-navigation 4.1.0 → 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 +4 -4
- package/android/proguard-rules.pro +0 -14
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +114 -23
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +115 -12
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +83 -18
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +185 -25
- 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 +39 -12
- 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 -89
- 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/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 -29
- 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 +36 -20
- package/ios/React/HBDReactBridgeManager.mm +450 -108
- 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 +126 -5
- 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 -159
- 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
|
|
9
35
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
36
|
+
@implementation HBDNavigationCommand
|
|
37
|
+
@end
|
|
38
|
+
|
|
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,15 +80,34 @@ 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
|
-
- (
|
|
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;
|
|
47
109
|
UIWindowScene *fallbackScene = nil;
|
|
48
|
-
for (UIScene *scene in
|
|
110
|
+
for (UIScene *scene in connectedScenes) {
|
|
49
111
|
if (![scene isKindOfClass:[UIWindowScene class]]) {
|
|
50
112
|
continue;
|
|
51
113
|
}
|
|
@@ -53,23 +115,21 @@ const NSInteger ResultBlock = -2;
|
|
|
53
115
|
if (windowScene.activationState == UISceneActivationStateForegroundActive) {
|
|
54
116
|
return windowScene;
|
|
55
117
|
}
|
|
56
|
-
if (windowScene.activationState == UISceneActivationStateForegroundInactive) {
|
|
57
|
-
fallbackScene = windowScene;
|
|
58
|
-
} else if (!fallbackScene) {
|
|
118
|
+
if (!fallbackScene || windowScene.activationState == UISceneActivationStateForegroundInactive) {
|
|
59
119
|
fallbackScene = windowScene;
|
|
60
120
|
}
|
|
61
121
|
}
|
|
62
122
|
return fallbackScene;
|
|
63
123
|
}
|
|
64
124
|
|
|
65
|
-
- (UIWindow *)
|
|
125
|
+
- (nullable UIWindow *)discoverDefaultWindow {
|
|
66
126
|
UIWindowScene *windowScene = [self activeWindowScene];
|
|
67
127
|
if (windowScene) {
|
|
68
128
|
id<UISceneDelegate> sceneDelegate = windowScene.delegate;
|
|
69
129
|
if ([sceneDelegate respondsToSelector:@selector(window)]) {
|
|
70
|
-
UIWindow *
|
|
71
|
-
if (
|
|
72
|
-
return
|
|
130
|
+
UIWindow *delegateWindow = [(id<UIWindowSceneDelegate>)sceneDelegate window];
|
|
131
|
+
if (delegateWindow) {
|
|
132
|
+
return delegateWindow;
|
|
73
133
|
}
|
|
74
134
|
}
|
|
75
135
|
if (@available(iOS 15.0, *)) {
|
|
@@ -85,42 +145,333 @@ const NSInteger ResultBlock = -2;
|
|
|
85
145
|
if (windowScene.windows.firstObject) {
|
|
86
146
|
return windowScene.windows.firstObject;
|
|
87
147
|
}
|
|
88
|
-
UIWindow *
|
|
89
|
-
|
|
148
|
+
UIWindow *newWindow = [[UIWindow alloc] initWithWindowScene:windowScene];
|
|
149
|
+
newWindow.backgroundColor = UIColor.whiteColor;
|
|
90
150
|
if ([sceneDelegate respondsToSelector:@selector(setWindow:)]) {
|
|
91
|
-
[(id<UIWindowSceneDelegate>)sceneDelegate setWindow:
|
|
151
|
+
[(id<UIWindowSceneDelegate>)sceneDelegate setWindow:newWindow];
|
|
92
152
|
}
|
|
93
|
-
return
|
|
153
|
+
return newWindow;
|
|
94
154
|
}
|
|
95
155
|
|
|
96
156
|
id<UIApplicationDelegate> appDelegate = RCTSharedApplication().delegate;
|
|
97
|
-
UIWindow *
|
|
98
|
-
if (!
|
|
99
|
-
|
|
100
|
-
|
|
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;
|
|
101
161
|
if ([appDelegate respondsToSelector:@selector(setWindow:)]) {
|
|
102
|
-
appDelegate.window =
|
|
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;
|
|
103
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();
|
|
104
391
|
}
|
|
105
|
-
return mainWindow;
|
|
106
392
|
}
|
|
107
393
|
|
|
108
394
|
- (void)invalidate {
|
|
109
395
|
RCTLogInfo(@"[Navigation] HBDReactBridgeManager#invalidate");
|
|
110
396
|
[NSObject cancelPreviousPerformRequestsWithTarget:self];
|
|
111
|
-
|
|
112
|
-
|
|
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];
|
|
113
439
|
for (id<HBDNavigator> navigator in navigators) {
|
|
114
440
|
[navigator invalidate];
|
|
115
441
|
}
|
|
116
442
|
|
|
117
|
-
self.viewHierarchyReady = NO;
|
|
118
443
|
self.reactModuleRegisterCompleted = NO;
|
|
119
|
-
|
|
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
|
+
}
|
|
120
471
|
}
|
|
121
472
|
|
|
122
473
|
- (void)installWithReactHost:(RCTHost *)rctHost {
|
|
123
|
-
|
|
474
|
+
_rctHost = rctHost;
|
|
124
475
|
}
|
|
125
476
|
|
|
126
477
|
- (void)registerNativeModule:(NSString *)moduleName forViewController:(Class)clazz {
|
|
@@ -154,27 +505,30 @@ const NSInteger ResultBlock = -2;
|
|
|
154
505
|
|
|
155
506
|
- (void)endRegisterReactModule {
|
|
156
507
|
_reactModuleRegisterCompleted = YES;
|
|
508
|
+
[self drainCommandQueue];
|
|
157
509
|
if (self.delegate != nil) {
|
|
158
510
|
[self.delegate reactModuleRegisterDidCompleted:self];
|
|
159
511
|
}
|
|
160
|
-
[[NSNotificationCenter defaultCenter] postNotificationName:
|
|
512
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:HBDReactModuleRegistryDidCompletedNotification object:nil];
|
|
161
513
|
}
|
|
162
514
|
|
|
515
|
+
#pragma mark - ViewController Factory & Hierarchy Queries
|
|
516
|
+
|
|
163
517
|
- (UIViewController *)createViewControllerWithLayout:(NSDictionary *)layout {
|
|
164
518
|
NSArray<NSString *> *layouts = [self.navigatorRegistry allLayouts];
|
|
165
519
|
for (NSString *name in layouts) {
|
|
166
520
|
if (![[layout allKeys] containsObject:name]) {
|
|
167
521
|
continue;
|
|
168
522
|
}
|
|
169
|
-
|
|
170
|
-
id
|
|
523
|
+
|
|
524
|
+
id<HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:name];
|
|
171
525
|
UIViewController *vc = [navigator viewControllerWithLayout:layout];
|
|
172
526
|
if (vc) {
|
|
173
527
|
[self.navigatorRegistry setLayout:name forViewController:vc];
|
|
174
528
|
}
|
|
175
529
|
return vc;
|
|
176
530
|
}
|
|
177
|
-
|
|
531
|
+
|
|
178
532
|
return nil;
|
|
179
533
|
}
|
|
180
534
|
|
|
@@ -184,7 +538,7 @@ const NSInteger ResultBlock = -2;
|
|
|
184
538
|
}
|
|
185
539
|
|
|
186
540
|
UIViewController *vc = [self createViewControllerWithLayout:layout];
|
|
187
|
-
|
|
541
|
+
|
|
188
542
|
if (!vc) {
|
|
189
543
|
RCTLogError(@"[Navigation] Can't find a navigator that can handle layout '%@'. Did you forget to register?", layout);
|
|
190
544
|
return nil;
|
|
@@ -207,7 +561,7 @@ const NSInteger ResultBlock = -2;
|
|
|
207
561
|
}
|
|
208
562
|
|
|
209
563
|
if ([self hasReactModule:moduleName]) {
|
|
210
|
-
NSDictionary *staticOptions = [
|
|
564
|
+
NSDictionary *staticOptions = [self reactModuleOptions:moduleName];
|
|
211
565
|
options = [HBDUtils mergeItem:options withTarget:staticOptions];
|
|
212
566
|
return [[HBDReactViewController alloc] initWithModuleName:moduleName props:props options:options];
|
|
213
567
|
} else {
|
|
@@ -217,13 +571,16 @@ const NSInteger ResultBlock = -2;
|
|
|
217
571
|
}
|
|
218
572
|
}
|
|
219
573
|
|
|
220
|
-
- (UIViewController *)viewControllerBySceneId:(NSString *)sceneId {
|
|
221
|
-
UIWindow *
|
|
222
|
-
return [self viewControllerWithSceneId:sceneId viewController:
|
|
574
|
+
- (nullable UIViewController *)viewControllerBySceneId:(NSString *)sceneId {
|
|
575
|
+
UIWindow *targetWindow = [self mainWindow];
|
|
576
|
+
return [self viewControllerWithSceneId:sceneId viewController:targetWindow.rootViewController];
|
|
223
577
|
}
|
|
224
578
|
|
|
225
|
-
- (UIViewController *)viewControllerWithSceneId:(NSString *)sceneId viewController:(UIViewController *)vc {
|
|
226
|
-
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]) {
|
|
227
584
|
return vc;
|
|
228
585
|
}
|
|
229
586
|
|
|
@@ -235,12 +592,7 @@ const NSInteger ResultBlock = -2;
|
|
|
235
592
|
}
|
|
236
593
|
}
|
|
237
594
|
|
|
238
|
-
|
|
239
|
-
if (children.count == 0) {
|
|
240
|
-
return nil;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
for (UIViewController *child in children) {
|
|
595
|
+
for (UIViewController *child in vc.childViewControllers) {
|
|
244
596
|
UIViewController *target = [self viewControllerWithSceneId:sceneId viewController:child];
|
|
245
597
|
if (target) {
|
|
246
598
|
return target;
|
|
@@ -250,59 +602,46 @@ const NSInteger ResultBlock = -2;
|
|
|
250
602
|
return nil;
|
|
251
603
|
}
|
|
252
604
|
|
|
253
|
-
- (
|
|
254
|
-
UIWindow *
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
[mainWindow.rootViewController dismissViewControllerAnimated:NO completion:^{
|
|
258
|
-
[self performSetRootViewController:rootViewController animated:NO];
|
|
259
|
-
}];
|
|
260
|
-
} else {
|
|
261
|
-
[self performSetRootViewController:rootViewController animated:YES];
|
|
605
|
+
- (nullable NSString *)findSceneIdByModuleName:(NSString *)moduleName {
|
|
606
|
+
UIWindow *targetWindow = [self mainWindow];
|
|
607
|
+
if (!targetWindow.rootViewController) {
|
|
608
|
+
return nil;
|
|
262
609
|
}
|
|
610
|
+
return [self findSceneIdByModuleName:moduleName withViewController:targetWindow.rootViewController];
|
|
263
611
|
}
|
|
264
612
|
|
|
265
|
-
- (
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
mainWindow.windowLevel = UIWindowLevelNormal;
|
|
274
|
-
if (!mainWindow.isKeyWindow) {
|
|
275
|
-
[mainWindow makeKeyAndVisible];
|
|
276
|
-
}
|
|
277
|
-
[UIView setAnimationsEnabled:oldState];
|
|
278
|
-
} completion:^(BOOL finished) {
|
|
279
|
-
self.viewHierarchyReady = YES;
|
|
280
|
-
if (self.didSetRoot) {
|
|
281
|
-
self.didSetRoot(@[NSNull.null, @YES]);
|
|
282
|
-
self.didSetRoot = NULL;
|
|
283
|
-
}
|
|
284
|
-
[[HBDNativeEvent getInstance] emitDidSetRoot];
|
|
285
|
-
}];
|
|
286
|
-
} else {
|
|
287
|
-
mainWindow.rootViewController = rootViewController;
|
|
288
|
-
mainWindow.windowLevel = UIWindowLevelNormal;
|
|
289
|
-
if (!mainWindow.isKeyWindow) {
|
|
290
|
-
[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;
|
|
291
621
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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;
|
|
297
629
|
}
|
|
298
|
-
[[HBDNativeEvent getInstance] emitDidSetRoot];
|
|
299
630
|
}
|
|
631
|
+
|
|
632
|
+
for (UIViewController *child in vc.childViewControllers) {
|
|
633
|
+
NSString *sceneId = [self findSceneIdByModuleName:moduleName withViewController:child];
|
|
634
|
+
if (sceneId) {
|
|
635
|
+
return sceneId;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
return nil;
|
|
300
640
|
}
|
|
301
641
|
|
|
302
|
-
- (HBDViewController *)primaryViewController {
|
|
303
|
-
UIWindow *
|
|
304
|
-
|
|
305
|
-
return [self primaryViewControllerWithViewController:controller];
|
|
642
|
+
- (nullable HBDViewController *)primaryViewController {
|
|
643
|
+
UIWindow *targetWindow = [self mainWindow];
|
|
644
|
+
return [self primaryViewControllerWithViewController:targetWindow.rootViewController];
|
|
306
645
|
}
|
|
307
646
|
|
|
308
647
|
- (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc {
|
|
@@ -313,19 +652,24 @@ const NSInteger ResultBlock = -2;
|
|
|
313
652
|
|
|
314
653
|
NSString *layout = [self.navigatorRegistry layoutForViewController:vc];
|
|
315
654
|
if (layout) {
|
|
316
|
-
id
|
|
655
|
+
id<HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:layout];
|
|
317
656
|
return [navigator primaryViewControllerWithViewController:vc];
|
|
318
657
|
}
|
|
319
|
-
|
|
658
|
+
|
|
320
659
|
return nil;
|
|
321
660
|
}
|
|
322
661
|
|
|
323
662
|
- (NSArray *)routeGraph {
|
|
324
|
-
UIWindow *
|
|
325
|
-
UIViewController *vc =
|
|
663
|
+
UIWindow *targetWindow = [self mainWindow];
|
|
664
|
+
UIViewController *vc = targetWindow.rootViewController;
|
|
665
|
+
if (!vc) {
|
|
666
|
+
return @[];
|
|
667
|
+
}
|
|
326
668
|
NSDictionary *graph = [self routeGraphWithViewController:vc];
|
|
327
669
|
NSMutableArray *root = [[NSMutableArray alloc] init];
|
|
328
|
-
|
|
670
|
+
if (graph) {
|
|
671
|
+
[root addObject:graph];
|
|
672
|
+
}
|
|
329
673
|
[root addObjectsFromArray:[self presentedGraphsWithRootViewController:vc]];
|
|
330
674
|
return root;
|
|
331
675
|
}
|
|
@@ -333,38 +677,36 @@ const NSInteger ResultBlock = -2;
|
|
|
333
677
|
- (NSArray *)presentedGraphsWithRootViewController:(UIViewController *)vc {
|
|
334
678
|
NSMutableArray *graphs = [[NSMutableArray alloc] init];
|
|
335
679
|
UIViewController *presented = vc.presentedViewController;
|
|
336
|
-
|
|
337
|
-
while (presented && !presented.beingDismissed && ![presented isKindOfClass:[UIAlertController class]]) {
|
|
680
|
+
while (presented && !presented.isBeingDismissed && ![presented isKindOfClass:[UIAlertController class]]) {
|
|
338
681
|
NSDictionary *graph = [self routeGraphWithViewController:presented];
|
|
339
682
|
if (graph) {
|
|
340
683
|
[graphs addObject:graph];
|
|
341
684
|
}
|
|
342
685
|
presented = presented.presentedViewController;
|
|
343
686
|
}
|
|
344
|
-
|
|
345
687
|
return graphs;
|
|
346
688
|
}
|
|
347
689
|
|
|
348
690
|
- (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc {
|
|
349
691
|
NSString *layout = [self.navigatorRegistry layoutForViewController:vc];
|
|
350
692
|
if (layout) {
|
|
351
|
-
id
|
|
693
|
+
id<HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:layout];
|
|
352
694
|
return [navigator routeGraphWithViewController:vc];
|
|
353
695
|
}
|
|
354
696
|
return nil;
|
|
355
697
|
}
|
|
356
698
|
|
|
357
|
-
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras
|
|
358
|
-
id
|
|
699
|
+
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
700
|
+
id<HBDNavigator> navigator = [self.navigatorRegistry navigatorForAction:action];
|
|
359
701
|
if (!navigator) {
|
|
360
702
|
RCTLogInfo(@"[Navigation] Can't find a navigator that can handle action '%@'", action);
|
|
361
|
-
|
|
703
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"No navigator registered for action: %@", action]));
|
|
362
704
|
return;
|
|
363
705
|
}
|
|
364
|
-
[navigator handleNavigationWithViewController:vc action:action extras:extras
|
|
706
|
+
[navigator handleNavigationWithViewController:vc action:action extras:extras completion:completion];
|
|
365
707
|
}
|
|
366
708
|
|
|
367
|
-
- (void)registerNavigator:(id
|
|
709
|
+
- (void)registerNavigator:(id<HBDNavigator>)navigator {
|
|
368
710
|
[self.navigatorRegistry registerNavigator:navigator];
|
|
369
711
|
}
|
|
370
712
|
|