hybrid-navigation 5.0.0 → 5.1.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/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +2 -4
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +48 -2
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +7 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +2 -4
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +3 -0
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +50 -0
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +4 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +16 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +19 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +17 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +66 -7
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +116 -18
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +8 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +376 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +72 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +26 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +134 -12
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +35 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +29 -4
- package/dist/NativeEvent.d.ts +15 -0
- package/dist/NativeNavigation.d.ts +8 -0
- package/dist/Navigation.d.ts +14 -1
- package/dist/Navigation.js +153 -12
- package/dist/NavigationComponentWrap.d.ts +3 -2
- package/dist/Navigator.d.ts +3 -2
- package/dist/Navigator.js +28 -9
- package/dist/Options.d.ts +12 -2
- package/dist/Route.d.ts +70 -5
- package/dist/defineRoutes.d.ts +19 -0
- package/dist/defineRoutes.js +6 -0
- package/dist/handler/DispatchCommandHandler.d.ts +16 -1
- package/dist/handler/DispatchCommandHandler.js +63 -5
- package/dist/handler/LayoutCommandHandler.d.ts +1 -0
- package/dist/handler/LayoutCommandHandler.js +3 -0
- package/dist/handler/LeaveGuardHandler.d.ts +17 -0
- package/dist/handler/LeaveGuardHandler.js +350 -0
- package/dist/handler/LifecycleEventHandler.d.ts +7 -3
- package/dist/handler/LifecycleEventHandler.js +36 -3
- package/dist/handler/PresentationCoordinator.d.ts +24 -0
- package/dist/handler/PresentationCoordinator.js +449 -0
- package/dist/handler/ResultEventHandler.d.ts +7 -0
- package/dist/handler/ResultEventHandler.js +13 -5
- package/dist/handler/TabEventHandler.d.ts +8 -0
- package/dist/handler/TabEventHandler.js +25 -0
- package/dist/hooks.d.ts +3 -1
- package/dist/hooks.js +20 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +3 -0
- package/dist/reveal.d.ts +46 -0
- package/dist/reveal.js +431 -0
- package/dist/routeGraph.d.ts +12 -0
- package/dist/routeGraph.js +68 -0
- package/dist/router/index.js +5 -41
- package/dist/router/tabs.d.ts +1 -0
- package/dist/store.d.ts +2 -0
- package/dist/store.js +4 -0
- package/dist/testing.d.ts +79 -0
- package/dist/testing.js +251 -0
- package/ios/HBDGlobalStyle.h +3 -0
- package/ios/HBDGlobalStyle.mm +13 -0
- package/ios/HybridNavigation.h +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +177 -11
- package/ios/Navigator/HBDStackNavigator.mm +50 -7
- package/ios/Navigator/HBDTabNavigator.mm +33 -5
- package/ios/React/HBDNativeNavigation.mm +73 -12
- package/ios/React/HBDNavigator.h +8 -0
- package/ios/React/HBDOrientationCoordinator.h +2 -0
- package/ios/React/HBDOrientationCoordinator.mm +27 -0
- package/ios/React/HBDReactBridgeManager.h +10 -0
- package/ios/React/HBDReactBridgeManager.mm +48 -2
- package/ios/ViewController/HBDNavigationController.mm +14 -0
- package/ios/ViewController/HBDReactViewController.h +6 -0
- package/ios/ViewController/HBDReactViewController.mm +177 -1
- package/ios/ViewController/HBDTabBarController.h +11 -0
- package/ios/ViewController/HBDTabBarController.mm +170 -3
- package/ios/ViewController/HBDTabBarRenderer.h +28 -0
- package/ios/ViewController/HBDViewController.h +1 -0
- package/ios/ViewController/HBDViewController.mm +57 -9
- package/ios/ViewController/UIViewController+HBD.h +1 -0
- package/ios/ViewController/UIViewController+HBD.mm +13 -4
- package/package.json +3 -1
- package/src/NativeEvent.ts +17 -0
- package/src/NativeNavigation.ts +9 -0
- package/src/Navigation.ts +228 -12
- package/src/NavigationComponentWrap.tsx +11 -2
- package/src/Navigator.ts +38 -9
- package/src/Options.ts +9 -2
- package/src/Route.ts +102 -6
- package/src/defineRoutes.ts +46 -0
- package/src/handler/DispatchCommandHandler.ts +110 -11
- package/src/handler/LayoutCommandHandler.ts +4 -0
- package/src/handler/LeaveGuardHandler.ts +436 -0
- package/src/handler/LifecycleEventHandler.ts +85 -38
- package/src/handler/PresentationCoordinator.ts +560 -0
- package/src/handler/ResultEventHandler.ts +23 -9
- package/src/handler/TabEventHandler.ts +31 -0
- package/src/hooks.ts +37 -1
- package/src/index.ts +11 -0
- package/src/reveal.ts +565 -0
- package/src/routeGraph.ts +87 -0
- package/src/router/index.ts +5 -40
- package/src/router/tabs.ts +1 -0
- package/src/store.ts +5 -0
- package/src/testing.ts +395 -0
- package/testing.d.ts +1 -0
- package/testing.js +3 -0
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
#import "HBDStackNavigator.h"
|
|
2
2
|
|
|
3
|
+
#import "HBDGlobalStyle.h"
|
|
3
4
|
#import "HBDNavigationController.h"
|
|
4
5
|
#import "HBDReactBridgeManager.h"
|
|
6
|
+
#import "HBDReactViewController.h"
|
|
5
7
|
#import "UINavigationController+HBD.h"
|
|
6
8
|
|
|
7
9
|
#import <React/RCTLog.h>
|
|
8
10
|
|
|
11
|
+
static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
12
|
+
|
|
9
13
|
@implementation HBDStackNavigator
|
|
10
14
|
|
|
11
15
|
- (NSString *)name {
|
|
@@ -141,12 +145,44 @@
|
|
|
141
145
|
animated = hbdvc.animatedTransition || hbdvc.screenOrientation == HBDScreenOrientationLandscape;
|
|
142
146
|
}
|
|
143
147
|
|
|
148
|
+
NSString *sceneId = vc.hbd_sceneId;
|
|
144
149
|
if (animated) {
|
|
150
|
+
BOOL canPrewarm = [HBDReactBridgeManager get].globalStyle.prewarmPush &&
|
|
151
|
+
[vc isKindOfClass:[HBDReactViewController class]] &&
|
|
152
|
+
nav.tabBarController == nil &&
|
|
153
|
+
nav.presentingViewController == nil &&
|
|
154
|
+
nav.view.window != nil &&
|
|
155
|
+
CGSizeEqualToSize(nav.view.bounds.size, nav.view.window.bounds.size);
|
|
156
|
+
if (canPrewarm) {
|
|
157
|
+
HBDReactViewController *reactVC = (HBDReactViewController *)vc;
|
|
158
|
+
HBDReactBridgeManager *manager = [HBDReactBridgeManager get];
|
|
159
|
+
NSUInteger commandId = manager.activeCommandId;
|
|
160
|
+
__weak HBDStackNavigator *weakSelf = self;
|
|
161
|
+
__weak UINavigationController *weakNav = nav;
|
|
162
|
+
BOOL prewarming = [reactVC prepareForAnimatedPushWithBounds:nav.view.bounds
|
|
163
|
+
timeout:HBDPushPrewarmTimeoutSeconds
|
|
164
|
+
completion:^{
|
|
165
|
+
HBDStackNavigator *strongSelf = weakSelf;
|
|
166
|
+
UINavigationController *strongNav = weakNav;
|
|
167
|
+
if (commandId != 0 && manager.activeCommandId != commandId) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (!strongSelf || !strongNav || !strongNav.view.window || vc.navigationController != nil) {
|
|
171
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeHostUnavailable, @"Navigation stack is unavailable after push prewarm."));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
[strongNav pushViewController:vc animated:YES];
|
|
175
|
+
[strongSelf animateAlongsideTransition:strongNav result:HBDDispatchResultOkWithSceneId(sceneId) completion:completion];
|
|
176
|
+
}];
|
|
177
|
+
if (prewarming) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
145
181
|
[nav pushViewController:vc animated:YES];
|
|
146
|
-
[self animateAlongsideTransition:nav completion:completion];
|
|
182
|
+
[self animateAlongsideTransition:nav result:HBDDispatchResultOkWithSceneId(sceneId) completion:completion];
|
|
147
183
|
} else {
|
|
148
184
|
[nav pushViewController:vc animated:NO];
|
|
149
|
-
completion(
|
|
185
|
+
completion(HBDDispatchResultOkWithSceneId(sceneId));
|
|
150
186
|
}
|
|
151
187
|
}
|
|
152
188
|
|
|
@@ -266,12 +302,13 @@
|
|
|
266
302
|
animated = hbdvc.animatedTransition || hbdvc.screenOrientation == HBDScreenOrientationLandscape;
|
|
267
303
|
}
|
|
268
304
|
|
|
305
|
+
NSString *sceneId = vc.hbd_sceneId;
|
|
269
306
|
if (animated) {
|
|
270
307
|
[nav hbd_redirectToViewController:vc target:target animated:YES];
|
|
271
|
-
[self animateAlongsideTransition:nav completion:completion];
|
|
308
|
+
[self animateAlongsideTransition:nav result:HBDDispatchResultOkWithSceneId(sceneId) completion:completion];
|
|
272
309
|
} else {
|
|
273
310
|
[nav hbd_redirectToViewController:vc target:target animated:NO];
|
|
274
|
-
completion(
|
|
311
|
+
completion(HBDDispatchResultOkWithSceneId(sceneId));
|
|
275
312
|
}
|
|
276
313
|
}
|
|
277
314
|
|
|
@@ -287,21 +324,27 @@
|
|
|
287
324
|
if (requestCode != 0) {
|
|
288
325
|
[vc setHbd_requestCode:requestCode];
|
|
289
326
|
}
|
|
327
|
+
HBDViewController *primary = [[HBDReactBridgeManager get] primaryViewControllerWithViewController:vc];
|
|
328
|
+
NSString *sceneId = primary.hbd_sceneId.length > 0 ? primary.hbd_sceneId : vc.hbd_sceneId;
|
|
290
329
|
|
|
291
330
|
[nav pushViewController:vc animated:YES];
|
|
292
|
-
[self animateAlongsideTransition:nav completion:completion];
|
|
331
|
+
[self animateAlongsideTransition:nav result:HBDDispatchResultOkWithSceneId(sceneId) completion:completion];
|
|
293
332
|
}
|
|
294
333
|
|
|
295
334
|
- (void)animateAlongsideTransition:(UINavigationController *)nav completion:(HBDDispatchCompletion)completion {
|
|
335
|
+
[self animateAlongsideTransition:nav result:HBDDispatchResultOk() completion:completion];
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
- (void)animateAlongsideTransition:(UINavigationController *)nav result:(NSDictionary *)result completion:(HBDDispatchCompletion)completion {
|
|
296
339
|
if (!nav.transitionCoordinator) {
|
|
297
|
-
completion(
|
|
340
|
+
completion(result);
|
|
298
341
|
return;
|
|
299
342
|
}
|
|
300
343
|
|
|
301
344
|
[nav.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
302
345
|
// empty
|
|
303
346
|
} completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
304
|
-
completion(
|
|
347
|
+
completion(result);
|
|
305
348
|
}];
|
|
306
349
|
}
|
|
307
350
|
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#import "HBDUtils.h"
|
|
6
6
|
#import "HBDGlobalStyle.h"
|
|
7
7
|
|
|
8
|
+
#import <React/RCTLog.h>
|
|
8
9
|
#import <React/RCTUtils.h>
|
|
9
10
|
|
|
10
11
|
@implementation HBDTabNavigator
|
|
@@ -37,6 +38,17 @@
|
|
|
37
38
|
|
|
38
39
|
NSDictionary *options = model[@"options"];
|
|
39
40
|
HBDTabBarController *tabBarController = [[HBDTabBarController alloc] init];
|
|
41
|
+
if ([options isKindOfClass:[NSDictionary class]]) {
|
|
42
|
+
NSString *rendererName = options[@"renderer"];
|
|
43
|
+
if ([rendererName isKindOfClass:[NSString class]] && rendererName.length > 0) {
|
|
44
|
+
id<HBDTabBarRenderer> renderer = [[HBDReactBridgeManager get] tabBarRendererWithName:rendererName];
|
|
45
|
+
if (renderer) {
|
|
46
|
+
tabBarController.tabBarRenderer = renderer;
|
|
47
|
+
} else {
|
|
48
|
+
RCTLogWarn(@"[Navigation] Unknown tab bar renderer '%@', falling back to default TabBar.", rendererName);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
40
52
|
[tabBarController setViewControllers:viewControllers];
|
|
41
53
|
|
|
42
54
|
if (options) {
|
|
@@ -64,10 +76,16 @@
|
|
|
64
76
|
}
|
|
65
77
|
}
|
|
66
78
|
|
|
79
|
+
NSMutableArray *tabKeys = [NSMutableArray arrayWithCapacity:children.count];
|
|
80
|
+
for (NSString *key in [tabBarController tabKeys]) {
|
|
81
|
+
[tabKeys addObject:key.length > 0 ? key : [NSNull null]];
|
|
82
|
+
}
|
|
83
|
+
|
|
67
84
|
return @{
|
|
68
85
|
@"layout": self.name,
|
|
69
86
|
@"sceneId": tabBarController.hbd_sceneId,
|
|
70
87
|
@"children": children,
|
|
88
|
+
@"tabKeys": tabKeys,
|
|
71
89
|
@"mode": [tabBarController hbd_mode],
|
|
72
90
|
@"selectedIndex": @(tabBarController.selectedIndex)
|
|
73
91
|
};
|
|
@@ -91,12 +109,22 @@
|
|
|
91
109
|
|
|
92
110
|
- (void)handleSwitchTabWithTabBarController:(UITabBarController *)tabBarController extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
93
111
|
BOOL popToRoot = [extras[@"popToRoot"] boolValue];
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
112
|
+
NSInteger toIndex = NSNotFound;
|
|
113
|
+
NSString *tabKey = [extras[@"tabKey"] isKindOfClass:[NSString class]] ? extras[@"tabKey"] : nil;
|
|
114
|
+
if (tabKey.length > 0 && [tabBarController isKindOfClass:[HBDTabBarController class]]) {
|
|
115
|
+
toIndex = [(HBDTabBarController *)tabBarController indexForTabKey:tabKey];
|
|
116
|
+
if (toIndex == NSNotFound) {
|
|
117
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeSceneNotFound, [NSString stringWithFormat:@"Can't find tab for key: %@", tabKey]));
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
NSNumber *toNumber = extras[@"to"];
|
|
122
|
+
if (![toNumber isKindOfClass:[NSNumber class]]) {
|
|
123
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Tab index or tabKey is required for switchTab."));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
toIndex = [toNumber integerValue];
|
|
98
127
|
}
|
|
99
|
-
NSInteger toIndex = [toNumber integerValue];
|
|
100
128
|
if (toIndex < 0 || (NSUInteger)toIndex >= tabBarController.viewControllers.count) {
|
|
101
129
|
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"Tab index out of bounds: %ld", (long)toIndex]));
|
|
102
130
|
return;
|
|
@@ -109,17 +109,25 @@
|
|
|
109
109
|
return 0;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
- (nullable NSDictionary *)routeDictionaryForViewController:(nullable HBDViewController *)current {
|
|
113
|
+
if (!current) {
|
|
114
|
+
return nil;
|
|
115
|
+
}
|
|
116
|
+
return @{
|
|
117
|
+
@"moduleName": RCTNullIfNil(current.moduleName),
|
|
118
|
+
@"sceneId": current.hbd_sceneId,
|
|
119
|
+
@"presentingId": RCTNullIfNil([self resolvedPresentingSceneIdForViewController:current]),
|
|
120
|
+
@"mode": [current hbd_mode],
|
|
121
|
+
@"requestCode": @([self resolvedRequestCodeForViewController:current]),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
112
125
|
- (void)currentRoute:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
113
126
|
[self.bridgeManager runWhenViewHierarchyReady:^{
|
|
114
127
|
HBDViewController *current = [self.bridgeManager primaryViewController];
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
@"sceneId": current.hbd_sceneId,
|
|
119
|
-
@"presentingId": RCTNullIfNil([self resolvedPresentingSceneIdForViewController:current]),
|
|
120
|
-
@"mode": [current hbd_mode],
|
|
121
|
-
@"requestCode": @([self resolvedRequestCodeForViewController:current]),
|
|
122
|
-
});
|
|
128
|
+
NSDictionary *route = [self routeDictionaryForViewController:current];
|
|
129
|
+
if (route) {
|
|
130
|
+
resolve(route);
|
|
123
131
|
} else {
|
|
124
132
|
RCTLogWarn(@"[Navigation] Can't find primaryViewController for currentRoute.");
|
|
125
133
|
resolve(nil);
|
|
@@ -138,6 +146,25 @@
|
|
|
138
146
|
}];
|
|
139
147
|
}
|
|
140
148
|
|
|
149
|
+
- (void)navigationSnapshot:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
150
|
+
[self.bridgeManager runWhenViewHierarchyReady:^{
|
|
151
|
+
HBDViewController *current = [self.bridgeManager primaryViewController];
|
|
152
|
+
NSDictionary *route = [self routeDictionaryForViewController:current];
|
|
153
|
+
NSArray *layers = [self.bridgeManager routeGraph] ?: @[];
|
|
154
|
+
resolve(@{
|
|
155
|
+
@"rootGeneration": @(self.bridgeManager.rootGeneration),
|
|
156
|
+
@"currentRoute": route ?: [NSNull null],
|
|
157
|
+
@"layers": layers,
|
|
158
|
+
});
|
|
159
|
+
} onCancelled:^{
|
|
160
|
+
resolve(@{
|
|
161
|
+
@"rootGeneration": @(self.bridgeManager.rootGeneration),
|
|
162
|
+
@"currentRoute": [NSNull null],
|
|
163
|
+
@"layers": @[],
|
|
164
|
+
});
|
|
165
|
+
}];
|
|
166
|
+
}
|
|
167
|
+
|
|
141
168
|
- (void)findSceneIdByModuleName:(nonnull NSString *)moduleName resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
142
169
|
[self.bridgeManager runWhenViewHierarchyReady:^{
|
|
143
170
|
NSString *sceneId = [self.bridgeManager findSceneIdByModuleName:moduleName];
|
|
@@ -234,10 +261,16 @@ static HBDDispatchCompletion HBDOnceDispatchResolve(RCTPromiseResolveBlock resol
|
|
|
234
261
|
}
|
|
235
262
|
}
|
|
236
263
|
|
|
264
|
+
- (void)setBeforeRemoveEnabled:(nonnull NSString *)sceneId enabled:(BOOL)enabled {
|
|
265
|
+
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
266
|
+
if (vc) {
|
|
267
|
+
vc.hbd_beforeRemoveEnabled = enabled;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
237
271
|
- (void)updateTabBar:(nonnull NSString *)sceneId item:(nonnull NSDictionary *)item {
|
|
238
272
|
RCTLogInfo(@"[Navigation] updateTabBar: %@", item);
|
|
239
|
-
|
|
240
|
-
UITabBarController *tabBarVC = [self tabBarControllerWithViewController:vc];
|
|
273
|
+
UITabBarController *tabBarVC = [self resolveTabBarControllerForSceneId:sceneId];
|
|
241
274
|
if ([tabBarVC isKindOfClass:[HBDTabBarController class]]) {
|
|
242
275
|
[(HBDTabBarController *)tabBarVC updateTabBar:item];
|
|
243
276
|
}
|
|
@@ -245,13 +278,41 @@ static HBDDispatchCompletion HBDOnceDispatchResolve(RCTPromiseResolveBlock resol
|
|
|
245
278
|
|
|
246
279
|
- (void)setTabItem:(nonnull NSString *)sceneId items:(nonnull NSArray *)items {
|
|
247
280
|
RCTLogInfo(@"[Navigation] setTabItem: %@", items);
|
|
248
|
-
|
|
249
|
-
UITabBarController *tabBarVC = [self tabBarControllerWithViewController:vc];
|
|
281
|
+
UITabBarController *tabBarVC = [self resolveTabBarControllerForSceneId:sceneId];
|
|
250
282
|
if ([tabBarVC isKindOfClass:[HBDTabBarController class]]) {
|
|
251
283
|
[(HBDTabBarController *)tabBarVC setTabItem:items];
|
|
252
284
|
}
|
|
253
285
|
}
|
|
254
286
|
|
|
287
|
+
- (nullable UITabBarController *)resolveTabBarControllerForSceneId:(NSString *)sceneId {
|
|
288
|
+
if (sceneId.length > 0) {
|
|
289
|
+
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
290
|
+
return [self tabBarControllerWithViewController:vc];
|
|
291
|
+
}
|
|
292
|
+
UIViewController *root = [self.bridgeManager mainWindow].rootViewController;
|
|
293
|
+
return [self findTabBarControllerInViewController:root];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
- (nullable UITabBarController *)findTabBarControllerInViewController:(nullable UIViewController *)vc {
|
|
297
|
+
if (!vc) {
|
|
298
|
+
return nil;
|
|
299
|
+
}
|
|
300
|
+
if ([vc isKindOfClass:[UITabBarController class]]) {
|
|
301
|
+
return (UITabBarController *)vc;
|
|
302
|
+
}
|
|
303
|
+
for (UIViewController *child in vc.childViewControllers) {
|
|
304
|
+
UITabBarController *found = [self findTabBarControllerInViewController:child];
|
|
305
|
+
if (found) {
|
|
306
|
+
return found;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
UIViewController *presented = vc.presentedViewController;
|
|
310
|
+
if (presented && presented != vc && !presented.isBeingDismissed) {
|
|
311
|
+
return [self findTabBarControllerInViewController:presented];
|
|
312
|
+
}
|
|
313
|
+
return nil;
|
|
314
|
+
}
|
|
315
|
+
|
|
255
316
|
- (UITabBarController *)tabBarControllerWithViewController:(UIViewController *)vc {
|
|
256
317
|
if ([vc isKindOfClass:[UITabBarController class]]) {
|
|
257
318
|
return (UITabBarController *)vc;
|
package/ios/React/HBDNavigator.h
CHANGED
|
@@ -8,6 +8,7 @@ static NSString *const HBDDispatchCodeOk = @"ok";
|
|
|
8
8
|
static NSString *const HBDDispatchCodeIntercepted = @"intercepted";
|
|
9
9
|
static NSString *const HBDDispatchCodeSceneNotFound = @"scene_not_found";
|
|
10
10
|
static NSString *const HBDDispatchCodeAlreadyPresenting = @"already_presenting";
|
|
11
|
+
static NSString *const HBDDispatchCodeCovered = @"covered";
|
|
11
12
|
static NSString *const HBDDispatchCodeNotReady = @"not_ready";
|
|
12
13
|
static NSString *const HBDDispatchCodeSuperseded = @"superseded";
|
|
13
14
|
static NSString *const HBDDispatchCodeInvalidAction = @"invalid_action";
|
|
@@ -17,6 +18,13 @@ static inline NSDictionary *HBDDispatchResultOk(void) {
|
|
|
17
18
|
return @{ @"ok": @YES, @"code": HBDDispatchCodeOk };
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
static inline NSDictionary *HBDDispatchResultOkWithSceneId(NSString * _Nullable sceneId) {
|
|
22
|
+
if (sceneId.length > 0) {
|
|
23
|
+
return @{ @"ok": @YES, @"code": HBDDispatchCodeOk, @"sceneId": sceneId };
|
|
24
|
+
}
|
|
25
|
+
return HBDDispatchResultOk();
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
static inline NSDictionary *HBDDispatchResultFail(NSString *code, NSString * _Nullable message) {
|
|
21
29
|
if (message.length > 0) {
|
|
22
30
|
return @{ @"ok": @NO, @"code": code ?: HBDDispatchCodeInvalidAction, @"message": message };
|
|
@@ -19,6 +19,8 @@ FOUNDATION_EXPORT HBDScreenOrientation HBDScreenOrientationFromString(NSString *
|
|
|
19
19
|
|
|
20
20
|
- (UIInterfaceOrientationMask)supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window;
|
|
21
21
|
- (HBDScreenOrientation)resolvedOrientationForViewController:(HBDViewController *)viewController;
|
|
22
|
+
- (nullable UIWindow *)windowForViewController:(UIViewController *)viewController;
|
|
23
|
+
- (BOOL)isWindowOrientationCompatibleForViewController:(HBDViewController *)viewController window:(UIWindow *)window;
|
|
22
24
|
- (void)applyOrientationForViewController:(HBDViewController *)viewController;
|
|
23
25
|
- (void)sceneOptionsDidUpdate:(HBDViewController *)viewController;
|
|
24
26
|
|
|
@@ -251,6 +251,33 @@ HBDScreenOrientation HBDScreenOrientationFromString(NSString * _Nullable value)
|
|
|
251
251
|
[self applyOrientationForViewController:viewController];
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
- (BOOL)isWindowOrientationCompatibleForViewController:(HBDViewController *)viewController window:(UIWindow *)window {
|
|
255
|
+
if (!window || window.bounds.size.width <= 0 || window.bounds.size.height <= 0) {
|
|
256
|
+
return NO;
|
|
257
|
+
}
|
|
258
|
+
UIWindowScene *windowScene = [self windowSceneForViewController:viewController window:window];
|
|
259
|
+
if (!windowScene) {
|
|
260
|
+
return NO;
|
|
261
|
+
}
|
|
262
|
+
HBDScreenOrientation targetOrientation = [self resolvedOrientationForViewController:viewController];
|
|
263
|
+
UIInterfaceOrientationMask targetMask = [self maskForOrientation:targetOrientation];
|
|
264
|
+
UIInterfaceOrientation current = windowScene.interfaceOrientation;
|
|
265
|
+
if (((1 << current) & targetMask) == 0) {
|
|
266
|
+
return NO;
|
|
267
|
+
}
|
|
268
|
+
BOOL windowIsLandscape = window.bounds.size.width > window.bounds.size.height;
|
|
269
|
+
if (UIInterfaceOrientationIsLandscape(current) != windowIsLandscape) {
|
|
270
|
+
return NO;
|
|
271
|
+
}
|
|
272
|
+
if (targetOrientation == HBDScreenOrientationLandscape && !windowIsLandscape) {
|
|
273
|
+
return NO;
|
|
274
|
+
}
|
|
275
|
+
if (targetOrientation == HBDScreenOrientationPortrait && windowIsLandscape) {
|
|
276
|
+
return NO;
|
|
277
|
+
}
|
|
278
|
+
return YES;
|
|
279
|
+
}
|
|
280
|
+
|
|
254
281
|
- (nullable UIWindow *)windowForViewController:(UIViewController *)viewController {
|
|
255
282
|
UIWindow *window = viewController.viewIfLoaded.window ?: viewController.navigationController.viewIfLoaded.window;
|
|
256
283
|
if (window) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#import "HBDNavigator.h"
|
|
2
|
+
#import "HBDTabBarRenderer.h"
|
|
2
3
|
#import <ReactCommon/RCTHost.h>
|
|
3
4
|
|
|
4
5
|
NS_ASSUME_NONNULL_BEGIN
|
|
@@ -31,6 +32,7 @@ extern const NSInteger HBDResultBlock;
|
|
|
31
32
|
@property(nonatomic, assign) BOOL hasRootLayout;
|
|
32
33
|
@property(nonatomic, copy, nullable) HBDDispatchCompletion didSetRoot;
|
|
33
34
|
@property(nonatomic, assign, readonly) NSUInteger activeCommandId;
|
|
35
|
+
@property(nonatomic, assign, readonly) NSUInteger rootGeneration;
|
|
34
36
|
|
|
35
37
|
- (void)installWithReactHost:(RCTHost *)rctHost;
|
|
36
38
|
|
|
@@ -56,6 +58,10 @@ extern const NSInteger HBDResultBlock;
|
|
|
56
58
|
|
|
57
59
|
- (nullable UIViewController *)viewControllerBySceneId:(NSString *)sceneId;
|
|
58
60
|
|
|
61
|
+
- (void)registerPrewarmingViewController:(UIViewController *)vc;
|
|
62
|
+
|
|
63
|
+
- (void)unregisterPrewarmingViewController:(UIViewController *)vc;
|
|
64
|
+
|
|
59
65
|
- (nullable UIWindow *)mainWindow;
|
|
60
66
|
|
|
61
67
|
- (void)setRootViewController:(UIViewController *)rootViewController;
|
|
@@ -82,6 +88,10 @@ extern const NSInteger HBDResultBlock;
|
|
|
82
88
|
|
|
83
89
|
- (void)registerNavigator:(id<HBDNavigator>)navigator;
|
|
84
90
|
|
|
91
|
+
- (void)registerTabBarRendererFactory:(HBDTabBarRendererFactory)factory forName:(NSString *)name;
|
|
92
|
+
|
|
93
|
+
- (nullable id<HBDTabBarRenderer>)tabBarRendererWithName:(NSString *)name;
|
|
94
|
+
|
|
85
95
|
- (void)invalidate;
|
|
86
96
|
|
|
87
97
|
@end
|
|
@@ -48,6 +48,7 @@ typedef NS_ENUM(NSInteger, HBDCommandType) {
|
|
|
48
48
|
|
|
49
49
|
@property(nonatomic, strong) NSMutableDictionary *nativeModules;
|
|
50
50
|
@property(nonatomic, strong) NSMutableDictionary *reactModules;
|
|
51
|
+
@property(nonatomic, strong) NSMutableDictionary<NSString *, HBDTabBarRendererFactory> *tabBarRendererFactories;
|
|
51
52
|
@property(nonatomic, assign, readwrite, getter=isReactModuleRegisterCompleted) BOOL reactModuleRegisterCompleted;
|
|
52
53
|
@property(nonatomic, strong) HBDNavigatorRegistry *navigatorRegistry;
|
|
53
54
|
|
|
@@ -55,9 +56,10 @@ typedef NS_ENUM(NSInteger, HBDCommandType) {
|
|
|
55
56
|
@property(nonatomic, strong) NSMutableArray<HBDReadyTask *> *viewHierarchyReadyTasks;
|
|
56
57
|
@property(nonatomic, assign) BOOL flushingViewHierarchyReadyTasks;
|
|
57
58
|
@property(nonatomic, strong) NSMutableArray<HBDNavigationCommand *> *commandQueue;
|
|
59
|
+
@property(nonatomic, strong) NSMapTable<NSString *, UIViewController *> *prewarmingViewControllers;
|
|
58
60
|
@property(nonatomic, assign) BOOL executingCommand;
|
|
59
61
|
@property(nonatomic, assign) NSUInteger commandQueueGeneration;
|
|
60
|
-
@property(nonatomic, assign) NSUInteger rootGeneration;
|
|
62
|
+
@property(nonatomic, assign, readwrite) NSUInteger rootGeneration;
|
|
61
63
|
@property(nonatomic, strong, nullable) HBDNavigationCommand *activeCommand;
|
|
62
64
|
@property(nonatomic, assign, readwrite) NSUInteger activeCommandId;
|
|
63
65
|
@property(nonatomic, assign) NSUInteger nextCommandId;
|
|
@@ -79,11 +81,13 @@ typedef NS_ENUM(NSInteger, HBDCommandType) {
|
|
|
79
81
|
if (self = [super init]) {
|
|
80
82
|
_nativeModules = [[NSMutableDictionary alloc] init];
|
|
81
83
|
_reactModules = [[NSMutableDictionary alloc] init];
|
|
84
|
+
_tabBarRendererFactories = [[NSMutableDictionary alloc] init];
|
|
82
85
|
_reactModuleRegisterCompleted = NO;
|
|
83
86
|
_navigatorRegistry = [[HBDNavigatorRegistry alloc] init];
|
|
84
87
|
_globalStyle = [[HBDGlobalStyle alloc] initWithOptions:@{}];
|
|
85
88
|
_viewHierarchyReadyTasks = [NSMutableArray array];
|
|
86
89
|
_commandQueue = [NSMutableArray array];
|
|
90
|
+
_prewarmingViewControllers = [NSMapTable strongToWeakObjectsMapTable];
|
|
87
91
|
}
|
|
88
92
|
return self;
|
|
89
93
|
}
|
|
@@ -306,6 +310,7 @@ typedef NS_ENUM(NSInteger, HBDCommandType) {
|
|
|
306
310
|
return;
|
|
307
311
|
}
|
|
308
312
|
self.viewHierarchyReady = NO;
|
|
313
|
+
[self.prewarmingViewControllers removeAllObjects];
|
|
309
314
|
self.hasRootLayout = YES;
|
|
310
315
|
if (self.didSetRoot) {
|
|
311
316
|
self.didSetRoot(HBDDispatchResultFail(HBDDispatchCodeSuperseded, @"setRoot was superseded by a newer call."));
|
|
@@ -411,6 +416,7 @@ typedef NS_ENUM(NSInteger, HBDCommandType) {
|
|
|
411
416
|
NSArray<HBDReadyTask *> *pendingReadyTasks = [self.viewHierarchyReadyTasks copy];
|
|
412
417
|
[self.viewHierarchyReadyTasks removeAllObjects];
|
|
413
418
|
self.viewHierarchyReady = NO;
|
|
419
|
+
[self.prewarmingViewControllers removeAllObjects];
|
|
414
420
|
|
|
415
421
|
NSDictionary *unavailable = HBDDispatchResultFail(HBDDispatchCodeHostUnavailable, @"Navigation host was invalidated.");
|
|
416
422
|
if (activeCommand) {
|
|
@@ -572,8 +578,33 @@ typedef NS_ENUM(NSInteger, HBDCommandType) {
|
|
|
572
578
|
}
|
|
573
579
|
|
|
574
580
|
- (nullable UIViewController *)viewControllerBySceneId:(NSString *)sceneId {
|
|
581
|
+
if (sceneId.length == 0) {
|
|
582
|
+
return nil;
|
|
583
|
+
}
|
|
575
584
|
UIWindow *targetWindow = [self mainWindow];
|
|
576
|
-
|
|
585
|
+
UIViewController *vc = [self viewControllerWithSceneId:sceneId viewController:targetWindow.rootViewController];
|
|
586
|
+
if (vc) {
|
|
587
|
+
return vc;
|
|
588
|
+
}
|
|
589
|
+
return [self.prewarmingViewControllers objectForKey:sceneId];
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
- (void)registerPrewarmingViewController:(UIViewController *)vc {
|
|
593
|
+
NSString *sceneId = vc.hbd_sceneId;
|
|
594
|
+
if (sceneId.length == 0) {
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
[self.prewarmingViewControllers setObject:vc forKey:sceneId];
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
- (void)unregisterPrewarmingViewController:(UIViewController *)vc {
|
|
601
|
+
NSString *sceneId = vc.hbd_sceneId;
|
|
602
|
+
if (sceneId.length == 0) {
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
if ([self.prewarmingViewControllers objectForKey:sceneId] == vc) {
|
|
606
|
+
[self.prewarmingViewControllers removeObjectForKey:sceneId];
|
|
607
|
+
}
|
|
577
608
|
}
|
|
578
609
|
|
|
579
610
|
- (nullable UIViewController *)viewControllerWithSceneId:(NSString *)sceneId viewController:(nullable UIViewController *)vc {
|
|
@@ -710,4 +741,19 @@ typedef NS_ENUM(NSInteger, HBDCommandType) {
|
|
|
710
741
|
[self.navigatorRegistry registerNavigator:navigator];
|
|
711
742
|
}
|
|
712
743
|
|
|
744
|
+
- (void)registerTabBarRendererFactory:(HBDTabBarRendererFactory)factory forName:(NSString *)name {
|
|
745
|
+
if (name.length == 0 || !factory) {
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
self.tabBarRendererFactories[name] = [factory copy];
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
- (nullable id<HBDTabBarRenderer>)tabBarRendererWithName:(NSString *)name {
|
|
752
|
+
if (name.length == 0) {
|
|
753
|
+
return nil;
|
|
754
|
+
}
|
|
755
|
+
HBDTabBarRendererFactory factory = self.tabBarRendererFactories[name];
|
|
756
|
+
return factory ? factory() : nil;
|
|
757
|
+
}
|
|
758
|
+
|
|
713
759
|
@end
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#import "HBDNavigationController.h"
|
|
2
2
|
|
|
3
3
|
#import "HBDViewController.h"
|
|
4
|
+
#import "HBDNativeEvent.h"
|
|
4
5
|
#import "HBDOrientationCoordinator.h"
|
|
6
|
+
#import "HBDReactBridgeManager.h"
|
|
5
7
|
|
|
6
8
|
#import <React/RCTLog.h>
|
|
7
9
|
#import <React/RCTUtils.h>
|
|
@@ -107,6 +109,18 @@
|
|
|
107
109
|
[[HBDOrientationCoordinator shared] resolvedOrientationForViewController:(HBDViewController *)topVC] == HBDScreenOrientationLandscape) {
|
|
108
110
|
return NO;
|
|
109
111
|
}
|
|
112
|
+
if (topVC.hbd_beforeRemoveEnabled) {
|
|
113
|
+
if ([HBDReactBridgeManager get].isReactModuleRegisterCompleted && topVC.hbd_sceneId.length > 0) {
|
|
114
|
+
HBDNativeEvent *event = [HBDNativeEvent getInstance];
|
|
115
|
+
if (event) {
|
|
116
|
+
[event emitOnBeforeRemoveRequest:@{
|
|
117
|
+
@"sceneId": topVC.hbd_sceneId,
|
|
118
|
+
@"action": @"back",
|
|
119
|
+
}];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return NO;
|
|
123
|
+
}
|
|
110
124
|
return topVC.hbd_backInteractive;
|
|
111
125
|
}
|
|
112
126
|
return NO;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
#import "HBDViewController.h"
|
|
2
2
|
|
|
3
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
+
|
|
3
5
|
@interface HBDReactViewController : HBDViewController
|
|
4
6
|
|
|
5
7
|
- (void)signalFirstRenderComplete;
|
|
6
8
|
|
|
9
|
+
- (BOOL)prepareForAnimatedPushWithBounds:(CGRect)bounds timeout:(NSTimeInterval)timeout completion:(dispatch_block_t)completion;
|
|
10
|
+
|
|
7
11
|
@end
|
|
12
|
+
|
|
13
|
+
NS_ASSUME_NONNULL_END
|