hybrid-navigation 5.3.0 → 5.5.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 +1 -0
- package/android/proguard-rules.pro +5 -0
- package/android/src/main/java/com/navigation/androidx/AppUtils.java +8 -1
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +115 -36
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +153 -100
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +1 -1
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +5 -1
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +95 -39
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +195 -29
- package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +225 -27
- package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +33 -9
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +5 -107
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +37 -10
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +82 -19
- package/android/src/main/java/com/navigation/androidx/Style.java +8 -4
- package/android/src/main/java/com/navigation/androidx/SystemUI.java +17 -5
- package/android/src/main/java/com/navigation/androidx/TabBar.java +69 -29
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +48 -11
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +1 -2
- package/android/src/main/java/com/navigation/androidx/TabView.java +20 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/Constants.java +1 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +19 -15
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +10 -48
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +22 -23
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +54 -22
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +4 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +35 -64
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +185 -121
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +21 -5
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigatorRegistry.java +27 -30
- package/android/src/main/java/com/reactnative/hybridnavigation/OrientationCoordinator.java +41 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/Parameters.java +55 -154
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +30 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +12 -37
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +31 -181
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +115 -71
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +27 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactSurfaceCleanup.java +50 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +34 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +39 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/RemovalPlan.java +76 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleStateMachine.java +72 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +19 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +11 -5
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +217 -99
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +122 -59
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +87 -24
- package/dist/DeepLink.d.ts +3 -1
- package/dist/DeepLink.js +39 -19
- package/dist/NativeNavigation.d.ts +8 -5
- package/dist/Navigation.d.ts +9 -24
- package/dist/Navigation.js +32 -97
- package/dist/NavigationComponentWrap.d.ts +1 -2
- package/dist/NavigationComponentWrap.js +0 -15
- package/dist/Navigator.d.ts +7 -5
- package/dist/Navigator.js +38 -33
- package/dist/Options.d.ts +1 -6
- package/dist/Options.js +1 -2
- package/dist/Route.d.ts +24 -12
- package/dist/handler/DispatchCommandHandler.d.ts +4 -5
- package/dist/handler/DispatchCommandHandler.js +37 -16
- package/dist/handler/LayoutCommandHandler.js +18 -3
- package/dist/handler/LeaveGuardHandler.d.ts +12 -8
- package/dist/handler/LeaveGuardHandler.js +174 -281
- package/dist/handler/LifecycleEventHandler.d.ts +7 -4
- package/dist/handler/LifecycleEventHandler.js +119 -32
- package/dist/handler/ResultEventHandler.d.ts +2 -2
- package/dist/handler/ResultEventHandler.js +72 -36
- package/dist/handler/SceneExitHandler.d.ts +6 -0
- package/dist/handler/SceneExitHandler.js +48 -8
- package/dist/hooks.d.ts +1 -0
- package/dist/hooks.js +39 -23
- package/dist/index.d.ts +9 -8
- package/dist/index.js +5 -8
- package/dist/routeGraph.d.ts +5 -0
- package/dist/routeGraph.js +47 -0
- package/dist/router/drawer.d.ts +2 -2
- package/dist/router/drawer.js +19 -9
- package/dist/router/helpers.d.ts +17 -0
- package/dist/router/helpers.js +90 -0
- package/dist/router/index.d.ts +2 -2
- package/dist/router/index.js +169 -97
- package/dist/router/screen.d.ts +2 -2
- package/dist/router/screen.js +16 -7
- package/dist/router/stack.d.ts +2 -2
- package/dist/router/stack.js +24 -49
- package/dist/router/tabs.js +5 -1
- package/dist/store.d.ts +2 -0
- package/dist/store.js +4 -0
- package/ios/HBDGlobalStyle.h +0 -1
- package/ios/HBDGlobalStyle.mm +27 -39
- package/ios/HBDUtils.h +0 -2
- package/ios/HBDUtils.mm +81 -41
- package/ios/Navigator/HBDDrawerNavigator.mm +31 -26
- package/ios/Navigator/HBDNavigatorRegistry.mm +23 -26
- package/ios/Navigator/HBDScreenNavigator.mm +240 -137
- package/ios/Navigator/HBDStackNavigator.mm +147 -97
- package/ios/Navigator/HBDTabNavigator.mm +99 -46
- package/ios/React/HBDNativeEvent.mm +38 -5
- package/ios/React/HBDNativeNavigation.mm +49 -51
- package/ios/React/HBDNavigationCommandQueue.h +55 -0
- package/ios/React/HBDNavigationCommandQueue.mm +341 -0
- package/ios/React/HBDNavigator.h +20 -0
- package/ios/React/HBDOrientationCoordinator.mm +26 -3
- package/ios/React/HBDReactBridgeManager.h +18 -6
- package/ios/React/HBDReactBridgeManager.mm +536 -315
- package/ios/React/HBDSceneLifecycleStateMachine.h +2 -0
- package/ios/React/HBDSceneLifecycleStateMachine.mm +18 -0
- package/ios/View/HBDRootView.h +1 -0
- package/ios/View/HBDRootView.mm +112 -4
- package/ios/View/UIImage+WithBadge.mm +9 -7
- package/ios/ViewController/HBDDrawerController.h +10 -0
- package/ios/ViewController/HBDDrawerController.mm +103 -71
- package/ios/ViewController/HBDNavigationController.mm +166 -58
- package/ios/ViewController/HBDReactViewController.h +0 -2
- package/ios/ViewController/HBDReactViewController.mm +13 -102
- package/ios/ViewController/HBDTabBarController.mm +67 -33
- package/ios/ViewController/HBDViewController.h +6 -0
- package/ios/ViewController/HBDViewController.mm +94 -37
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +13 -13
- package/ios/ViewController/UIViewController+HBD.h +23 -1
- package/ios/ViewController/UIViewController+HBD.mm +298 -40
- package/package.json +1 -1
- package/src/DeepLink.ts +39 -19
- package/src/NativeNavigation.ts +17 -5
- package/src/Navigation.ts +49 -170
- package/src/NavigationComponentWrap.tsx +1 -16
- package/src/Navigator.ts +50 -52
- package/src/Options.ts +4 -9
- package/src/Route.ts +37 -19
- package/src/handler/DispatchCommandHandler.ts +42 -20
- package/src/handler/LayoutCommandHandler.ts +15 -3
- package/src/handler/LeaveGuardHandler.ts +224 -329
- package/src/handler/LifecycleEventHandler.ts +131 -37
- package/src/handler/ResultEventHandler.ts +71 -37
- package/src/handler/SceneExitHandler.ts +60 -9
- package/src/hooks.ts +54 -26
- package/src/index.ts +77 -8
- package/src/routeGraph.ts +50 -0
- package/src/router/drawer.ts +21 -10
- package/src/router/helpers.ts +113 -0
- package/src/router/index.ts +187 -112
- package/src/router/screen.ts +35 -8
- package/src/router/stack.ts +40 -53
- package/src/router/tabs.ts +5 -1
- package/src/store.ts +5 -0
- package/dist/sceneCoverage.d.ts +0 -2
- package/dist/sceneCoverage.js +0 -25
- package/src/sceneCoverage.ts +0 -30
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
#import "HBDStackNavigator.h"
|
|
5
5
|
#import "HBDTabNavigator.h"
|
|
6
6
|
#import "HBDDrawerNavigator.h"
|
|
7
|
-
#import "
|
|
8
|
-
#import "HBDTabBarController.h"
|
|
7
|
+
#import "UIViewController+HBD.h"
|
|
9
8
|
|
|
10
9
|
#import <React/RCTLog.h>
|
|
11
10
|
|
|
@@ -15,7 +14,6 @@
|
|
|
15
14
|
@property(nonatomic, strong) NSMutableArray<id <HBDNavigator>> *navigators;
|
|
16
15
|
@property(nonatomic, strong) NSMutableDictionary<NSString *, id <HBDNavigator>> *actionNavigatorPairs;
|
|
17
16
|
@property(nonatomic, strong) NSMutableDictionary<NSString *, id <HBDNavigator>> *layoutNavigatorPairs;
|
|
18
|
-
@property(nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *classLayoutPairs;
|
|
19
17
|
|
|
20
18
|
@end
|
|
21
19
|
|
|
@@ -27,7 +25,6 @@
|
|
|
27
25
|
_navigators = [NSMutableArray new];
|
|
28
26
|
_actionNavigatorPairs = [NSMutableDictionary new];
|
|
29
27
|
_layoutNavigatorPairs = [NSMutableDictionary new];
|
|
30
|
-
_classLayoutPairs = [NSMutableDictionary new];
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
[self registerNavigator:[HBDStackNavigator new]];
|
|
@@ -48,14 +45,17 @@
|
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
NSString *layout = [navigator name];
|
|
51
|
-
[self.layouts
|
|
52
|
-
|
|
48
|
+
if (![self.layouts containsObject:layout]) {
|
|
49
|
+
[self.layouts addObject:layout];
|
|
50
|
+
}
|
|
51
|
+
|
|
53
52
|
id <HBDNavigator> duplicatedLayout = self.layoutNavigatorPairs[layout];
|
|
54
53
|
if (duplicatedLayout) {
|
|
55
54
|
RCTLogError(@"[Navigation] The layout %@ that %@ wants to register has been registered by %@", layout, [navigator class], [duplicatedLayout class]);
|
|
55
|
+
[self.navigators removeObject:duplicatedLayout];
|
|
56
56
|
}
|
|
57
57
|
self.layoutNavigatorPairs[layout] = navigator;
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
[self.navigators addObject:navigator];
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -68,32 +68,29 @@
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
- (NSString *)layoutForViewController:(UIViewController *)vc {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return layout;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
77
|
-
return @"screen";
|
|
78
|
-
}
|
|
79
|
-
if ([vc isKindOfClass:[HBDNavigationController class]]) {
|
|
80
|
-
return @"stack";
|
|
71
|
+
if (!vc) {
|
|
72
|
+
return nil;
|
|
81
73
|
}
|
|
82
|
-
|
|
83
|
-
|
|
74
|
+
NSString *tagged = vc.hbd_layout;
|
|
75
|
+
if (tagged.length > 0 && self.layoutNavigatorPairs[tagged] != nil) {
|
|
76
|
+
return tagged;
|
|
84
77
|
}
|
|
85
|
-
|
|
86
|
-
|
|
78
|
+
|
|
79
|
+
for (NSInteger i = (NSInteger)self.navigators.count - 1; i >= 0; i--) {
|
|
80
|
+
id<HBDNavigator> navigator = self.navigators[(NSUInteger)i];
|
|
81
|
+
if ([navigator respondsToSelector:@selector(handlesViewController:)] && [navigator handlesViewController:vc]) {
|
|
82
|
+
NSString *matched = [navigator name];
|
|
83
|
+
if (matched.length > 0) {
|
|
84
|
+
return matched;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
return nil;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
- (void)setLayout:(NSString *)layout forViewController:(UIViewController *)vc {
|
|
93
|
-
|
|
94
|
-
if (!current || ![current isEqualToString:layout]) {
|
|
95
|
-
self.classLayoutPairs[NSStringFromClass([vc class])] = layout;
|
|
96
|
-
}
|
|
93
|
+
vc.hbd_layout = layout;
|
|
97
94
|
}
|
|
98
95
|
|
|
99
96
|
- (NSArray<NSString *> *)allLayouts {
|
|
@@ -15,7 +15,11 @@
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
- (NSArray<NSString *> *)supportActions {
|
|
18
|
-
return @[@"present", @"
|
|
18
|
+
return @[@"present", @"dismiss", @"showModal", @"close"];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
- (BOOL)handlesViewController:(UIViewController *)vc {
|
|
22
|
+
return [self isMemberOfClass:[HBDScreenNavigator class]] && [vc isKindOfClass:[HBDViewController class]];
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
- (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout {
|
|
@@ -37,7 +41,7 @@
|
|
|
37
41
|
|
|
38
42
|
HBDViewController *screen = (HBDViewController *)vc;
|
|
39
43
|
return @{
|
|
40
|
-
@"layout":
|
|
44
|
+
@"layout": self.name,
|
|
41
45
|
@"sceneId": screen.hbd_sceneId,
|
|
42
46
|
@"moduleName": RCTNullIfNil(screen.moduleName),
|
|
43
47
|
@"mode": [screen hbd_mode],
|
|
@@ -51,6 +55,84 @@
|
|
|
51
55
|
return nil;
|
|
52
56
|
}
|
|
53
57
|
|
|
58
|
+
- (nullable UINavigationController *)popStackForCloseViewController:(UIViewController *)vc {
|
|
59
|
+
for (UIViewController *child = vc; child.parentViewController; child = child.parentViewController) {
|
|
60
|
+
if (![child.parentViewController isKindOfClass:UINavigationController.class]) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
UINavigationController *stack = (UINavigationController *)child.parentViewController;
|
|
64
|
+
if (stack.viewControllers.count > 1) {
|
|
65
|
+
return stack;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return nil;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
- (nullable NSDictionary *)removalPlanWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras {
|
|
72
|
+
if ([action isEqualToString:@"close"]) {
|
|
73
|
+
if ([vc hbd_isCoveredByPresentation] || [vc hbd_isCoveredInContainers]) {
|
|
74
|
+
return HBDRemovalPlan(HBDDispatchCodeCovered, @[], nil, nil);
|
|
75
|
+
}
|
|
76
|
+
UINavigationController *popStack = [self popStackForCloseViewController:vc];
|
|
77
|
+
if (popStack) {
|
|
78
|
+
return HBDRemovalPlan(HBDDispatchCodeOk, [popStack.topViewController hbd_collectLeafSceneIds], @"pop", nil);
|
|
79
|
+
}
|
|
80
|
+
UIViewController *host = [vc hbd_modalHostViewController];
|
|
81
|
+
if (host.presentingViewController != nil) {
|
|
82
|
+
return HBDRemovalPlan(HBDDispatchCodeOk, [host hbd_collectLeafSceneIds], @"dismiss", @"self");
|
|
83
|
+
}
|
|
84
|
+
return HBDRemovalPlan(HBDDispatchCodeInvalidAction, @[], nil, nil);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if ([action isEqualToString:@"dismiss"]) {
|
|
88
|
+
UIViewController *host = [vc hbd_modalHostViewController];
|
|
89
|
+
UIViewController *presented = host.presentedViewController;
|
|
90
|
+
if (presented && (presented.isBeingDismissed || [presented isKindOfClass:[UIAlertController class]])) {
|
|
91
|
+
presented = nil;
|
|
92
|
+
}
|
|
93
|
+
NSString *targetMode = [extras[@"target"] isKindOfClass:[NSString class]] ? extras[@"target"] : nil;
|
|
94
|
+
if ([targetMode isEqualToString:@"self"]) {
|
|
95
|
+
if (presented != nil) {
|
|
96
|
+
return HBDRemovalPlan(HBDDispatchCodeCovered, @[], nil, nil);
|
|
97
|
+
}
|
|
98
|
+
if (host.presentingViewController == nil) {
|
|
99
|
+
return HBDRemovalPlan(HBDDispatchCodeInvalidAction, @[], nil, nil);
|
|
100
|
+
}
|
|
101
|
+
return HBDRemovalPlan(HBDDispatchCodeOk, [host hbd_collectLeafSceneIds], @"dismiss", @"self");
|
|
102
|
+
}
|
|
103
|
+
if ([targetMode isEqualToString:@"presented"] || presented != nil) {
|
|
104
|
+
if (presented == nil) {
|
|
105
|
+
return HBDRemovalPlan(HBDDispatchCodeInvalidAction, @[], nil, nil);
|
|
106
|
+
}
|
|
107
|
+
NSMutableArray<UIViewController *> *chain = [NSMutableArray array];
|
|
108
|
+
UIViewController *cursor = presented;
|
|
109
|
+
while (cursor != nil && !cursor.isBeingDismissed && ![cursor isKindOfClass:[UIAlertController class]] && ![chain containsObject:cursor]) {
|
|
110
|
+
[chain addObject:cursor];
|
|
111
|
+
cursor = cursor.presentedViewController;
|
|
112
|
+
}
|
|
113
|
+
NSMutableArray<NSString *> *sceneIds = [NSMutableArray array];
|
|
114
|
+
for (NSInteger i = (NSInteger)chain.count - 1; i >= 0; i--) {
|
|
115
|
+
[sceneIds addObjectsFromArray:[chain[(NSUInteger)i] hbd_collectLeafSceneIds]];
|
|
116
|
+
}
|
|
117
|
+
return HBDRemovalPlan(HBDDispatchCodeOk, sceneIds, @"dismiss", @"presented");
|
|
118
|
+
}
|
|
119
|
+
if (host.presentingViewController == nil) {
|
|
120
|
+
return HBDRemovalPlan(HBDDispatchCodeInvalidAction, @[], nil, nil);
|
|
121
|
+
}
|
|
122
|
+
return HBDRemovalPlan(HBDDispatchCodeOk, [host hbd_collectLeafSceneIds], @"dismiss", @"self");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return HBDRemovalPlan(@"noop", @[], nil, nil);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
- (nullable UIViewController *)presentedNavigationViewControllerForHost:(UIViewController *)host {
|
|
129
|
+
UIViewController *presented = host.presentedViewController;
|
|
130
|
+
if (presented && [presented isKindOfClass:[UIAlertController class]]) {
|
|
131
|
+
return nil;
|
|
132
|
+
}
|
|
133
|
+
return presented;
|
|
134
|
+
}
|
|
135
|
+
|
|
54
136
|
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
55
137
|
if ([action isEqualToString:@"present"]) {
|
|
56
138
|
[self handlePresentWithViewController:vc extras:extras completion:completion];
|
|
@@ -58,9 +140,22 @@
|
|
|
58
140
|
}
|
|
59
141
|
|
|
60
142
|
BOOL closeSelf = [action isEqualToString:@"close"];
|
|
61
|
-
if (closeSelf || [action isEqualToString:@"dismiss"]
|
|
62
|
-
NSDictionary *result = closeSelf ? extras[@"result"] : nil;
|
|
63
|
-
|
|
143
|
+
if (closeSelf || [action isEqualToString:@"dismiss"]) {
|
|
144
|
+
NSDictionary *result = (closeSelf && [extras[@"result"] isKindOfClass:[NSDictionary class]]) ? extras[@"result"] : nil;
|
|
145
|
+
NSString *targetMode = [extras[@"target"] isKindOfClass:[NSString class]] ? extras[@"target"] : nil;
|
|
146
|
+
BOOL selfOnly = closeSelf || [targetMode isEqualToString:@"self"];
|
|
147
|
+
BOOL explicitPresentedOnly = !closeSelf && [targetMode isEqualToString:@"presented"];
|
|
148
|
+
UIViewController *host = [vc hbd_modalHostViewController];
|
|
149
|
+
UIViewController *presented = [self presentedNavigationViewControllerForHost:host];
|
|
150
|
+
BOOL presentedOnly = explicitPresentedOnly || (!selfOnly && presented != nil);
|
|
151
|
+
[self handleDismissWithViewController:vc
|
|
152
|
+
closeSelf:closeSelf
|
|
153
|
+
selfOnly:selfOnly
|
|
154
|
+
presentedOnly:presentedOnly
|
|
155
|
+
explicitPresentedOnly:explicitPresentedOnly
|
|
156
|
+
result:result
|
|
157
|
+
retryCount:0
|
|
158
|
+
completion:completion];
|
|
64
159
|
return;
|
|
65
160
|
}
|
|
66
161
|
|
|
@@ -69,16 +164,6 @@
|
|
|
69
164
|
return;
|
|
70
165
|
}
|
|
71
166
|
|
|
72
|
-
if ([action isEqualToString:@"presentLayout"]) {
|
|
73
|
-
[self handlePresentLayoutWithViewController:vc extras:extras completion:completion];
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if ([action isEqualToString:@"showModalLayout"]) {
|
|
78
|
-
[self handleShowModalLayoutWithViewController:vc extras:extras completion:completion];
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
167
|
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"Unsupported screen action: %@", action]));
|
|
83
168
|
}
|
|
84
169
|
|
|
@@ -101,13 +186,59 @@
|
|
|
101
186
|
return vc.hbd_sceneId;
|
|
102
187
|
}
|
|
103
188
|
|
|
189
|
+
- (BOOL)preparePresentingViewController:(UIViewController *)presenting
|
|
190
|
+
retryCount:(NSUInteger)retryCount
|
|
191
|
+
retry:(void (^)(NSUInteger nextRetry))retryBlock
|
|
192
|
+
completion:(HBDDispatchCompletion)completion {
|
|
193
|
+
UIViewController *presented = presenting.presentedViewController;
|
|
194
|
+
UIViewController *transitioning = nil;
|
|
195
|
+
if (presenting.isBeingPresented || presenting.isBeingDismissed) {
|
|
196
|
+
transitioning = presenting;
|
|
197
|
+
} else if (presented && presented.isBeingDismissed) {
|
|
198
|
+
transitioning = presented;
|
|
199
|
+
} else if (presented && presented.isBeingPresented) {
|
|
200
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeAlreadyPresenting, @"Target scene is already presenting another scene."));
|
|
201
|
+
return NO;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (transitioning) {
|
|
205
|
+
HBDReactBridgeManager *manager = [HBDReactBridgeManager get];
|
|
206
|
+
[manager waitForTransitionOnViewController:transitioning
|
|
207
|
+
commandId:manager.activeCommandId
|
|
208
|
+
retryCount:retryCount
|
|
209
|
+
action:^{
|
|
210
|
+
retryBlock(retryCount + 1);
|
|
211
|
+
} onTimeout:^{
|
|
212
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeNotReady, @"Presentation transition is still in progress."));
|
|
213
|
+
}];
|
|
214
|
+
return NO;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (![presenting hbd_canPresentViewController]) {
|
|
218
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeAlreadyPresenting, @"Target scene is already presenting another scene."));
|
|
219
|
+
return NO;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (!presenting.viewIfLoaded.window || [presenting hbd_isCoveredInContainers]) {
|
|
223
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeCovered, @"Presenting scene is covered or not attached to a window."));
|
|
224
|
+
return NO;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return YES;
|
|
228
|
+
}
|
|
229
|
+
|
|
104
230
|
- (void)handlePresentWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
231
|
+
[self handlePresentWithViewController:presenting extras:extras retryCount:0 completion:completion];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
- (void)handlePresentWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras retryCount:(NSUInteger)retryCount completion:(HBDDispatchCompletion)completion {
|
|
105
235
|
if ([self isInsideModalViewController:presenting]) {
|
|
106
236
|
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Cannot present a scene on top of a modal."));
|
|
107
237
|
return;
|
|
108
238
|
}
|
|
109
|
-
if (![presenting
|
|
110
|
-
|
|
239
|
+
if (![self preparePresentingViewController:presenting retryCount:retryCount retry:^(NSUInteger nextRetry) {
|
|
240
|
+
[self handlePresentWithViewController:presenting extras:extras retryCount:nextRetry completion:completion];
|
|
241
|
+
} completion:completion]) {
|
|
111
242
|
return;
|
|
112
243
|
}
|
|
113
244
|
|
|
@@ -116,96 +247,92 @@
|
|
|
116
247
|
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create presented screen."));
|
|
117
248
|
return;
|
|
118
249
|
}
|
|
119
|
-
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
250
|
+
NSInteger requestCode = [extras[@"requestCode"] isKindOfClass:[NSNumber class]] ? [extras[@"requestCode"] integerValue] : 0;
|
|
120
251
|
HBDNavigationController *nav = [[HBDNavigationController alloc] initWithRootViewController:vc];
|
|
121
252
|
nav.modalPresentationStyle = UIModalPresentationCurrentContext;
|
|
122
253
|
[nav setHbd_requestCode:requestCode];
|
|
123
254
|
[vc setHbd_requestCode:requestCode];
|
|
124
255
|
[vc setHbd_presentingSceneId:presenting.hbd_sceneId];
|
|
125
256
|
|
|
257
|
+
BOOL animated = YES;
|
|
258
|
+
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
259
|
+
HBDViewController *hbdvc = (HBDViewController *)vc;
|
|
260
|
+
animated = hbdvc.animatedTransition || hbdvc.screenOrientation == HBDScreenOrientationLandscape;
|
|
261
|
+
}
|
|
262
|
+
|
|
126
263
|
NSString *sceneId = [self resolvedSceneIdForViewController:vc];
|
|
127
|
-
[presenting presentViewController:nav animated:
|
|
264
|
+
[presenting presentViewController:nav animated:animated completion:^{
|
|
128
265
|
completion(HBDDispatchResultOkWithSceneId(sceneId));
|
|
129
266
|
}];
|
|
130
267
|
}
|
|
131
268
|
|
|
132
|
-
- (UIViewController *)modalHostViewControllerForViewController:(UIViewController *)vc {
|
|
133
|
-
UIViewController *host = vc;
|
|
134
|
-
while (host.parentViewController != nil) {
|
|
135
|
-
host = host.parentViewController;
|
|
136
|
-
}
|
|
137
|
-
return host;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
269
|
- (void)handleDismissWithViewController:(UIViewController *)vc
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
270
|
+
closeSelf:(BOOL)closeSelf
|
|
271
|
+
selfOnly:(BOOL)selfOnly
|
|
272
|
+
presentedOnly:(BOOL)presentedOnly
|
|
273
|
+
explicitPresentedOnly:(BOOL)explicitPresentedOnly
|
|
274
|
+
result:(NSDictionary *)result
|
|
275
|
+
retryCount:(NSUInteger)retryCount
|
|
276
|
+
completion:(HBDDispatchCompletion)completion {
|
|
277
|
+
UIViewController *host = [vc hbd_modalHostViewController];
|
|
278
|
+
UIViewController *rawPresented = host.presentedViewController;
|
|
279
|
+
UIViewController *presented = [self presentedNavigationViewControllerForHost:host];
|
|
152
280
|
UIViewController *transitioning = nil;
|
|
153
281
|
if (host.isBeingPresented || host.isBeingDismissed) {
|
|
154
282
|
transitioning = host;
|
|
155
|
-
} else if (
|
|
156
|
-
transitioning =
|
|
283
|
+
} else if (rawPresented.isBeingDismissed || (!selfOnly && presented.isBeingPresented)) {
|
|
284
|
+
transitioning = rawPresented;
|
|
157
285
|
}
|
|
158
286
|
if (transitioning) {
|
|
159
287
|
HBDReactBridgeManager *manager = [HBDReactBridgeManager get];
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
} else {
|
|
288
|
+
[manager waitForTransitionOnViewController:transitioning
|
|
289
|
+
commandId:manager.activeCommandId
|
|
290
|
+
retryCount:retryCount
|
|
291
|
+
action:^{
|
|
292
|
+
[self handleDismissWithViewController:vc
|
|
293
|
+
closeSelf:closeSelf
|
|
294
|
+
selfOnly:selfOnly
|
|
295
|
+
presentedOnly:presentedOnly
|
|
296
|
+
explicitPresentedOnly:explicitPresentedOnly
|
|
297
|
+
result:result
|
|
298
|
+
retryCount:retryCount + 1
|
|
299
|
+
completion:completion];
|
|
300
|
+
} onTimeout:^{
|
|
174
301
|
completion(HBDDispatchResultFail(HBDDispatchCodeNotReady, @"Dismiss transition is still in progress."));
|
|
302
|
+
}];
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (selfOnly && presented) {
|
|
306
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeCovered, @"Target scene is covered by a presented scene."));
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (presentedOnly && !presented) {
|
|
310
|
+
if (explicitPresentedOnly && retryCount == 0) {
|
|
311
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"No presented scene to dismiss."));
|
|
312
|
+
} else {
|
|
313
|
+
completion(HBDDispatchResultOk());
|
|
175
314
|
}
|
|
176
315
|
return;
|
|
177
316
|
}
|
|
178
317
|
|
|
179
318
|
if (closeSelf) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
UINavigationController *stack = (UINavigationController *)child.parentViewController;
|
|
186
|
-
if (stack.topViewController != child) {
|
|
187
|
-
completion(HBDDispatchResultFail(HBDDispatchCodeCovered, @"Target scene is covered in its stack."));
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
if (!popStack && stack.viewControllers.count > 1) {
|
|
191
|
-
popStack = stack;
|
|
192
|
-
}
|
|
319
|
+
if ([vc hbd_isCoveredInContainers]) {
|
|
320
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeCovered, @"Target scene is covered in its container."));
|
|
321
|
+
return;
|
|
193
322
|
}
|
|
323
|
+
UINavigationController *popStack = [self popStackForCloseViewController:vc];
|
|
194
324
|
if (popStack) {
|
|
195
|
-
if (popStack.transitionCoordinator) {
|
|
196
|
-
completion(HBDDispatchResultFail(HBDDispatchCodeNotReady, @"Navigation stack is transitioning."));
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
325
|
UIViewController *top = popStack.topViewController;
|
|
326
|
+
BOOL oldHasLocalResult = top.hbd_hasLocalResult;
|
|
200
327
|
NSInteger oldCode = top.hbd_resultCode;
|
|
201
328
|
NSDictionary *oldData = top.hbd_resultData;
|
|
202
|
-
[self applyCloseResult:result toViewController:top];
|
|
329
|
+
BOOL appliedResult = [self applyCloseResult:result toViewController:top];
|
|
203
330
|
[[HBDReactBridgeManager get] handleNavigationWithViewController:top action:@"pop" extras:@{} completion:^(NSDictionary *reply) {
|
|
204
331
|
if ([popStack.viewControllers containsObject:top]) {
|
|
205
|
-
if (
|
|
206
|
-
[top
|
|
332
|
+
if (appliedResult) {
|
|
333
|
+
[top hbd_restoreLocalResult:oldHasLocalResult resultCode:oldCode resultData:oldData];
|
|
207
334
|
}
|
|
208
|
-
completion(HBDDispatchResultFail(HBDDispatchCodeNotReady, @"Target scene was not popped."));
|
|
335
|
+
completion(reply && ![reply[@"ok"] boolValue] ? reply : HBDDispatchResultFail(HBDDispatchCodeNotReady, @"Target scene was not popped."));
|
|
209
336
|
return;
|
|
210
337
|
}
|
|
211
338
|
completion(reply);
|
|
@@ -222,16 +349,33 @@
|
|
|
222
349
|
}
|
|
223
350
|
|
|
224
351
|
BOOL animated = target.modalPresentationStyle != UIModalPresentationOverFullScreen;
|
|
225
|
-
if (animated
|
|
226
|
-
|
|
352
|
+
if (animated) {
|
|
353
|
+
HBDViewController *targetPrimary = (target == host && [vc isKindOfClass:[HBDViewController class]])
|
|
354
|
+
? (HBDViewController *)vc
|
|
355
|
+
: [[HBDReactBridgeManager get] primaryViewControllerInHierarchy:target];
|
|
356
|
+
if (targetPrimary) {
|
|
357
|
+
animated = targetPrimary.animatedTransition;
|
|
358
|
+
}
|
|
227
359
|
}
|
|
360
|
+
|
|
361
|
+
BOOL oldHasLocalResult = target.hbd_hasLocalResult;
|
|
362
|
+
NSInteger oldCode = target.hbd_resultCode;
|
|
363
|
+
NSDictionary *oldData = target.hbd_resultData;
|
|
364
|
+
BOOL appliedResult = [self applyCloseResult:result toViewController:target];
|
|
365
|
+
if (!appliedResult && target == host && vc != target && !target.hbd_hasLocalResult && vc.hbd_hasLocalResult) {
|
|
366
|
+
[target hbd_setLocalResultCode:vc.hbd_resultCode resultData:vc.hbd_resultData];
|
|
367
|
+
appliedResult = YES;
|
|
368
|
+
}
|
|
369
|
+
|
|
228
370
|
[presenter dismissViewControllerAnimated:animated completion:^{
|
|
229
371
|
if (target.presentingViewController != nil) {
|
|
372
|
+
if (appliedResult) {
|
|
373
|
+
[target hbd_restoreLocalResult:oldHasLocalResult resultCode:oldCode resultData:oldData];
|
|
374
|
+
}
|
|
230
375
|
completion(HBDDispatchResultFail(HBDDispatchCodeNotReady, @"Target scene was not dismissed."));
|
|
231
376
|
return;
|
|
232
377
|
}
|
|
233
|
-
[
|
|
234
|
-
HBDViewController *revealed = [[HBDReactBridgeManager get] primaryViewControllerWithViewController:presenter];
|
|
378
|
+
HBDViewController *revealed = [[HBDReactBridgeManager get] primaryViewControllerInHierarchy:presenter];
|
|
235
379
|
if (revealed != nil) {
|
|
236
380
|
[[HBDOrientationCoordinator shared] applyOrientationForViewController:revealed];
|
|
237
381
|
}
|
|
@@ -239,16 +383,23 @@
|
|
|
239
383
|
}];
|
|
240
384
|
}
|
|
241
385
|
|
|
242
|
-
- (
|
|
386
|
+
- (BOOL)applyCloseResult:(NSDictionary *)result toViewController:(UIViewController *)vc {
|
|
243
387
|
if ([result[@"code"] isKindOfClass:NSNumber.class]) {
|
|
244
388
|
NSDictionary *data = result[@"data"];
|
|
245
389
|
[vc hbd_setLocalResultCode:[result[@"code"] integerValue] resultData:[data isKindOfClass:NSDictionary.class] ? data : nil];
|
|
390
|
+
return YES;
|
|
246
391
|
}
|
|
392
|
+
return NO;
|
|
247
393
|
}
|
|
248
394
|
|
|
249
395
|
- (void)handleShowModalWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
250
|
-
|
|
251
|
-
|
|
396
|
+
[self handleShowModalWithViewController:presenting extras:extras retryCount:0 completion:completion];
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
- (void)handleShowModalWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras retryCount:(NSUInteger)retryCount completion:(HBDDispatchCompletion)completion {
|
|
400
|
+
if (![self preparePresentingViewController:presenting retryCount:retryCount retry:^(NSUInteger nextRetry) {
|
|
401
|
+
[self handleShowModalWithViewController:presenting extras:extras retryCount:nextRetry completion:completion];
|
|
402
|
+
} completion:completion]) {
|
|
252
403
|
return;
|
|
253
404
|
}
|
|
254
405
|
|
|
@@ -257,60 +408,12 @@
|
|
|
257
408
|
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create modal screen."));
|
|
258
409
|
return;
|
|
259
410
|
}
|
|
260
|
-
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
411
|
+
NSInteger requestCode = [extras[@"requestCode"] isKindOfClass:[NSNumber class]] ? [extras[@"requestCode"] integerValue] : 0;
|
|
261
412
|
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
262
413
|
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
|
|
263
|
-
[vc
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
NSString *sceneId = [self resolvedSceneIdForViewController:vc];
|
|
267
|
-
[presenting presentViewController:vc animated:NO completion:^{
|
|
268
|
-
completion(HBDDispatchResultOkWithSceneId(sceneId));
|
|
269
|
-
}];
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
- (void)handlePresentLayoutWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
273
|
-
if ([self isInsideModalViewController:presenting]) {
|
|
274
|
-
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Cannot present a scene on top of a modal."));
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
if (![presenting hbd_canPresentViewController]) {
|
|
278
|
-
completion(HBDDispatchResultFail(HBDDispatchCodeAlreadyPresenting, @"Target scene is already presenting another scene."));
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
NSDictionary *layout = extras[@"layout"];
|
|
283
|
-
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
284
|
-
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
|
|
285
|
-
if (!vc) {
|
|
286
|
-
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create presented layout."));
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
[vc setHbd_requestCode:requestCode];
|
|
290
|
-
[vc setHbd_presentingSceneId:presenting.hbd_sceneId];
|
|
291
|
-
vc.modalPresentationStyle = UIModalPresentationCurrentContext;
|
|
292
|
-
|
|
293
|
-
NSString *sceneId = [self resolvedSceneIdForViewController:vc];
|
|
294
|
-
[presenting presentViewController:vc animated:YES completion:^{
|
|
295
|
-
completion(HBDDispatchResultOkWithSceneId(sceneId));
|
|
296
|
-
}];
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
- (void)handleShowModalLayoutWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
300
|
-
if (![presenting hbd_canPresentViewController]) {
|
|
301
|
-
completion(HBDDispatchResultFail(HBDDispatchCodeAlreadyPresenting, @"Target scene is already presenting another scene."));
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
306
|
-
NSDictionary *layout = extras[@"layout"];
|
|
307
|
-
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
|
|
308
|
-
if (!vc) {
|
|
309
|
-
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create modal layout."));
|
|
310
|
-
return;
|
|
414
|
+
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
415
|
+
[(HBDViewController *)vc syncModalStatusBarCapture];
|
|
311
416
|
}
|
|
312
|
-
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
313
|
-
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
|
|
314
417
|
[vc setHbd_requestCode:requestCode];
|
|
315
418
|
[vc setHbd_presentingSceneId:presenting.hbd_sceneId];
|
|
316
419
|
|
|
@@ -321,12 +424,12 @@
|
|
|
321
424
|
}
|
|
322
425
|
|
|
323
426
|
- (UIViewController *)viewControllerWithExtras:(NSDictionary *)extras {
|
|
324
|
-
NSString *moduleName = extras[@"moduleName"];
|
|
325
|
-
if (
|
|
427
|
+
NSString *moduleName = [extras[@"moduleName"] isKindOfClass:[NSString class]] ? extras[@"moduleName"] : nil;
|
|
428
|
+
if (moduleName.length == 0) {
|
|
326
429
|
return nil;
|
|
327
430
|
}
|
|
328
|
-
NSDictionary *props = extras[@"props"];
|
|
329
|
-
NSDictionary *options = extras[@"options"];
|
|
431
|
+
NSDictionary *props = [extras[@"props"] isKindOfClass:[NSDictionary class]] ? extras[@"props"] : nil;
|
|
432
|
+
NSDictionary *options = [extras[@"options"] isKindOfClass:[NSDictionary class]] ? extras[@"options"] : nil;
|
|
330
433
|
return [[HBDReactBridgeManager get] viewControllerWithModuleName:moduleName props:props options:options];
|
|
331
434
|
}
|
|
332
435
|
|