hybrid-navigation 4.1.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/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 +116 -27
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +162 -13
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- 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 +18 -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 +10 -7
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +29 -9
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +31 -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 +74 -7
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +4 -0
- package/android/src/main/java/com/navigation/androidx/TabView.java +11 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +71 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +18 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +34 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +20 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +179 -13
- 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 +283 -183
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +507 -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 +421 -92
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +227 -78
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +26 -0
- 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 +188 -26
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +67 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +42 -14
- package/dist/DeepLink.d.ts +3 -2
- package/dist/DeepLink.js +37 -14
- package/dist/NativeEvent.d.ts +17 -10
- package/dist/NativeNavigation.d.ts +24 -18
- package/dist/Navigation.d.ts +34 -19
- package/dist/Navigation.js +225 -90
- package/dist/NavigationComponentWrap.d.ts +5 -3
- package/dist/NavigationComponentWrap.js +3 -6
- package/dist/Navigator.d.ts +32 -42
- package/dist/Navigator.js +117 -91
- package/dist/Options.d.ts +15 -3
- package/dist/Route.d.ts +149 -17
- package/dist/defineRoutes.d.ts +19 -0
- package/dist/defineRoutes.js +6 -0
- package/dist/handler/DispatchCommandHandler.d.ts +25 -6
- package/dist/handler/DispatchCommandHandler.js +99 -17
- package/dist/handler/LayoutCommandHandler.d.ts +8 -7
- package/dist/handler/LayoutCommandHandler.js +24 -15
- package/dist/handler/LeaveGuardHandler.d.ts +17 -0
- package/dist/handler/LeaveGuardHandler.js +350 -0
- package/dist/handler/LifecycleEventHandler.d.ts +30 -0
- package/dist/handler/LifecycleEventHandler.js +169 -0
- package/dist/handler/PresentationCoordinator.d.ts +24 -0
- package/dist/handler/PresentationCoordinator.js +449 -0
- package/dist/handler/ResultEventHandler.d.ts +21 -9
- package/dist/handler/ResultEventHandler.js +96 -13
- package/dist/handler/TabEventHandler.d.ts +8 -0
- package/dist/handler/TabEventHandler.js +25 -0
- package/dist/hooks.d.ts +7 -2
- package/dist/hooks.js +46 -4
- package/dist/index.d.ts +24 -0
- package/dist/index.js +3 -2
- package/dist/reveal.d.ts +46 -0
- package/dist/reveal.js +431 -0
- package/dist/routeConfigRegistry.d.ts +6 -0
- package/dist/routeConfigRegistry.js +19 -0
- package/dist/routeGraph.d.ts +12 -0
- package/dist/routeGraph.js +68 -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 +106 -58
- 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 +3 -2
- package/dist/router/tabs.js +4 -1
- package/dist/store.d.ts +4 -2
- package/dist/store.js +4 -0
- package/dist/testing.d.ts +79 -0
- package/dist/testing.js +251 -0
- package/ios/HBDGlobalStyle.h +29 -0
- package/ios/{GlobalStyle.mm → HBDGlobalStyle.mm} +43 -29
- package/ios/HybridNavigation.h +5 -1
- package/ios/Navigator/HBDDrawerNavigator.mm +24 -8
- package/ios/Navigator/HBDNavigatorRegistry.mm +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +278 -58
- package/ios/Navigator/HBDStackNavigator.mm +152 -61
- package/ios/Navigator/HBDTabNavigator.mm +60 -14
- package/ios/React/HBDNativeNavigation.mm +162 -123
- package/ios/React/HBDNavigator.h +37 -5
- package/ios/React/HBDOrientationCoordinator.h +29 -0
- package/ios/React/HBDOrientationCoordinator.mm +309 -0
- package/ios/React/HBDReactBridgeManager.h +46 -20
- package/ios/React/HBDReactBridgeManager.mm +496 -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 +31 -4
- package/ios/ViewController/HBDReactViewController.h +6 -0
- package/ios/ViewController/HBDReactViewController.mm +220 -106
- package/ios/ViewController/HBDTabBarController.h +15 -0
- package/ios/ViewController/HBDTabBarController.mm +227 -45
- package/ios/ViewController/HBDTabBarRenderer.h +28 -0
- package/ios/ViewController/HBDViewController.h +11 -3
- package/ios/ViewController/HBDViewController.mm +209 -159
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +3 -3
- package/ios/ViewController/UIViewController+HBD.h +18 -10
- package/ios/ViewController/UIViewController+HBD.mm +90 -65
- package/package.json +3 -1
- package/src/DeepLink.ts +41 -14
- package/src/NativeEvent.ts +18 -11
- package/src/NativeNavigation.ts +29 -31
- package/src/Navigation.ts +377 -120
- package/src/NavigationComponentWrap.tsx +18 -9
- package/src/Navigator.ts +219 -152
- package/src/Options.ts +12 -3
- package/src/Route.ts +228 -17
- package/src/defineRoutes.ts +46 -0
- package/src/handler/DispatchCommandHandler.ts +154 -21
- package/src/handler/LayoutCommandHandler.ts +40 -17
- package/src/handler/LeaveGuardHandler.ts +436 -0
- package/src/handler/LifecycleEventHandler.ts +219 -0
- package/src/handler/PresentationCoordinator.ts +560 -0
- package/src/handler/ResultEventHandler.ts +126 -19
- package/src/handler/TabEventHandler.ts +31 -0
- package/src/hooks.ts +75 -7
- package/src/index.ts +37 -2
- package/src/reveal.ts +565 -0
- package/src/routeConfigRegistry.ts +26 -0
- package/src/routeGraph.ts +87 -0
- package/src/router/drawer.ts +8 -5
- package/src/router/index.ts +139 -63
- package/src/router/screen.ts +3 -3
- package/src/router/stack.ts +80 -29
- package/src/router/tabs.ts +16 -7
- package/src/store.ts +6 -1
- package/src/testing.ts +395 -0
- package/testing.d.ts +1 -0
- package/testing.js +3 -0
- 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,7 +1,8 @@
|
|
|
1
1
|
#import "HBDScreenNavigator.h"
|
|
2
2
|
|
|
3
|
-
#import "HBDReactBridgeManager.h"
|
|
4
3
|
#import "HBDNavigationController.h"
|
|
4
|
+
#import "HBDOrientationCoordinator.h"
|
|
5
|
+
#import "HBDReactBridgeManager.h"
|
|
5
6
|
#import "HBDViewController.h"
|
|
6
7
|
#import "UIViewController+HBD.h"
|
|
7
8
|
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
- (NSArray<NSString *> *)supportActions {
|
|
17
|
-
return @[@"present", @"presentLayout", @"dismiss", @"showModal", @"showModalLayout", @"hideModal"];
|
|
18
|
+
return @[@"present", @"presentLayout", @"dismiss", @"showModal", @"showModalLayout", @"hideModal", @"close"];
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
- (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout {
|
|
@@ -34,10 +35,10 @@
|
|
|
34
35
|
return nil;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
HBDViewController *screen = (HBDViewController *)
|
|
38
|
+
HBDViewController *screen = (HBDViewController *)vc;
|
|
38
39
|
return @{
|
|
39
40
|
@"layout": @"screen",
|
|
40
|
-
@"sceneId": screen.
|
|
41
|
+
@"sceneId": screen.hbd_sceneId,
|
|
41
42
|
@"moduleName": RCTNullIfNil(screen.moduleName),
|
|
42
43
|
@"mode": [screen hbd_mode],
|
|
43
44
|
};
|
|
@@ -45,133 +46,352 @@
|
|
|
45
46
|
|
|
46
47
|
- (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc {
|
|
47
48
|
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
48
|
-
return (HBDViewController *)
|
|
49
|
+
return (HBDViewController *)vc;
|
|
49
50
|
}
|
|
50
51
|
return nil;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras
|
|
54
|
+
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
54
55
|
if ([action isEqualToString:@"present"]) {
|
|
55
|
-
[self handlePresentWithViewController:vc extras:extras
|
|
56
|
+
[self handlePresentWithViewController:vc extras:extras completion:completion];
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
if ([action isEqualToString:@"dismiss"]) {
|
|
60
|
-
[self handleDismissWithViewController:vc
|
|
61
|
+
[self handleDismissWithViewController:vc extras:extras completion:completion];
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
if ([action isEqualToString:@"showModal"]) {
|
|
65
|
-
[self handleShowModalWithViewController:vc extras:extras
|
|
66
|
+
[self handleShowModalWithViewController:vc extras:extras completion:completion];
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
if ([action isEqualToString:@"hideModal"]) {
|
|
70
|
-
[self handleDismissWithViewController:vc
|
|
71
|
+
[self handleDismissWithViewController:vc extras:extras completion:completion];
|
|
71
72
|
return;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
if ([action isEqualToString:@"presentLayout"]) {
|
|
75
|
-
[self handlePresentLayoutWithViewController:vc extras:extras
|
|
76
|
+
[self handlePresentLayoutWithViewController:vc extras:extras completion:completion];
|
|
76
77
|
return;
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
if ([action isEqualToString:@"showModalLayout"]) {
|
|
80
|
-
[self handleShowModalLayoutWithViewController:vc extras:extras
|
|
81
|
+
[self handleShowModalLayoutWithViewController:vc extras:extras completion:completion];
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if ([action isEqualToString:@"close"]) {
|
|
86
|
+
[self handleCloseWithViewController:vc extras:extras completion:completion];
|
|
81
87
|
return;
|
|
82
88
|
}
|
|
89
|
+
|
|
90
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"Unsupported screen action: %@", action]));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
- (BOOL)isInsideModalViewController:(UIViewController *)vc {
|
|
94
|
+
UIViewController *current = vc;
|
|
95
|
+
while (current != nil) {
|
|
96
|
+
if (current.modalPresentationStyle == UIModalPresentationOverFullScreen) {
|
|
97
|
+
return YES;
|
|
98
|
+
}
|
|
99
|
+
current = current.parentViewController;
|
|
100
|
+
}
|
|
101
|
+
return NO;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
- (NSString *)resolvedSceneIdForViewController:(UIViewController *)vc {
|
|
105
|
+
HBDViewController *primary = [[HBDReactBridgeManager get] primaryViewControllerWithViewController:vc];
|
|
106
|
+
if (primary.hbd_sceneId.length > 0) {
|
|
107
|
+
return primary.hbd_sceneId;
|
|
108
|
+
}
|
|
109
|
+
return vc.hbd_sceneId;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
- (BOOL)waitForDismissalIfNeededForViewController:(UIViewController *)presenting retry:(dispatch_block_t)retry {
|
|
113
|
+
UIViewController *presented = presenting.presentedViewController;
|
|
114
|
+
if (!presented || !presented.isBeingDismissed) {
|
|
115
|
+
return NO;
|
|
116
|
+
}
|
|
117
|
+
HBDReactBridgeManager *manager = [HBDReactBridgeManager get];
|
|
118
|
+
NSUInteger commandId = manager.activeCommandId;
|
|
119
|
+
id<UIViewControllerTransitionCoordinator> coordinator = presented.transitionCoordinator;
|
|
120
|
+
if (coordinator) {
|
|
121
|
+
[coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
122
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
123
|
+
if (commandId != 0 && manager.activeCommandId != commandId) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
retry();
|
|
127
|
+
});
|
|
128
|
+
}];
|
|
129
|
+
} else {
|
|
130
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
131
|
+
if (commandId != 0 && manager.activeCommandId != commandId) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
retry();
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return YES;
|
|
83
138
|
}
|
|
84
139
|
|
|
85
|
-
- (void)handlePresentWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras
|
|
86
|
-
if (
|
|
87
|
-
|
|
140
|
+
- (void)handlePresentWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
141
|
+
if ([self isInsideModalViewController:presenting]) {
|
|
142
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Cannot present a scene on top of a modal."));
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if ([self waitForDismissalIfNeededForViewController:presenting retry:^{
|
|
146
|
+
[self handlePresentWithViewController:presenting extras:extras completion:completion];
|
|
147
|
+
}]) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (![presenting hbd_canPresentViewController]) {
|
|
151
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeAlreadyPresenting, @"Target scene is already presenting another scene."));
|
|
88
152
|
return;
|
|
89
153
|
}
|
|
90
154
|
|
|
91
155
|
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
156
|
+
if (!vc) {
|
|
157
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create presented screen."));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
92
160
|
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
93
161
|
HBDNavigationController *nav = [[HBDNavigationController alloc] initWithRootViewController:vc];
|
|
94
162
|
nav.modalPresentationStyle = UIModalPresentationCurrentContext;
|
|
95
|
-
[nav
|
|
96
|
-
[vc
|
|
97
|
-
[vc
|
|
163
|
+
[nav setHbd_requestCode:requestCode];
|
|
164
|
+
[vc setHbd_requestCode:requestCode];
|
|
165
|
+
[vc setHbd_presentingSceneId:presenting.hbd_sceneId];
|
|
98
166
|
|
|
167
|
+
NSString *sceneId = [self resolvedSceneIdForViewController:vc];
|
|
99
168
|
[presenting presentViewController:nav animated:YES completion:^{
|
|
100
|
-
|
|
169
|
+
completion(HBDDispatchResultOkWithSceneId(sceneId));
|
|
101
170
|
}];
|
|
102
171
|
}
|
|
103
172
|
|
|
104
173
|
- (UIViewController *)modalHostViewControllerForViewController:(UIViewController *)vc {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
- (void)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
[
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
174
|
+
UIViewController *host = vc;
|
|
175
|
+
while (host.parentViewController != nil) {
|
|
176
|
+
host = host.parentViewController;
|
|
177
|
+
}
|
|
178
|
+
return host;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
- (void)applyPendingResultIfPresentToViewController:(UIViewController *)vc extras:(NSDictionary *)extras {
|
|
182
|
+
NSDictionary *pendingResult = [extras[@"result"] isKindOfClass:[NSDictionary class]] ? extras[@"result"] : nil;
|
|
183
|
+
if (!pendingResult) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
id codeObj = pendingResult[@"code"];
|
|
187
|
+
if (![codeObj isKindOfClass:[NSNumber class]]) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
NSInteger resultCode = [codeObj integerValue];
|
|
191
|
+
id rawData = pendingResult[@"data"];
|
|
192
|
+
NSDictionary *resultData = [rawData isKindOfClass:[NSDictionary class]] ? rawData : nil;
|
|
193
|
+
[vc hbd_setResultCode:resultCode resultData:resultData];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
- (BOOL)viewController:(UIViewController *)viewController hasAncestorOrSelf:(nullable UIViewController *)ancestor {
|
|
197
|
+
if (!viewController || !ancestor) {
|
|
198
|
+
return NO;
|
|
199
|
+
}
|
|
200
|
+
for (UIViewController *current = viewController; current != nil; current = current.parentViewController) {
|
|
201
|
+
if (current == ancestor) {
|
|
202
|
+
return YES;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return NO;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
- (void)handleCloseWithViewController:(UIViewController *)vc extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
209
|
+
UIViewController *modalHost = [self modalHostViewControllerForViewController:vc];
|
|
210
|
+
if ([self waitForDismissalIfNeededForViewController:modalHost retry:^{
|
|
211
|
+
[self handleCloseWithViewController:vc extras:extras completion:completion];
|
|
212
|
+
}]) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
UIViewController *presented = modalHost.presentedViewController;
|
|
217
|
+
if (presented != nil) {
|
|
218
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeCovered, @"Target scene is covered by another presented scene."));
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
UINavigationController *nav = vc.navigationController;
|
|
223
|
+
if (nav != nil && nav.viewControllers.count > 1) {
|
|
224
|
+
UIViewController *topVC = nav.topViewController;
|
|
225
|
+
if (![self viewController:vc hasAncestorOrSelf:topVC]) {
|
|
226
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeCovered, @"Target scene is covered by another screen in the stack."));
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
UIViewController *stackRoot = nav.viewControllers.firstObject;
|
|
230
|
+
if (![self viewController:vc hasAncestorOrSelf:stackRoot]) {
|
|
231
|
+
UIViewController *resultTarget = topVC ?: vc;
|
|
232
|
+
[self applyPendingResultIfPresentToViewController:resultTarget extras:extras];
|
|
233
|
+
[[HBDReactBridgeManager get] handleNavigationWithViewController:vc action:@"pop" extras:extras completion:completion];
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (modalHost.presentingViewController != nil) {
|
|
239
|
+
NSMutableDictionary *dismissExtras = extras ? [extras mutableCopy] : [NSMutableDictionary dictionary];
|
|
240
|
+
dismissExtras[@"target"] = @"self";
|
|
241
|
+
[self handleDismissWithViewController:vc extras:[dismissExtras copy] completion:completion];
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Target scene cannot be closed."));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
- (void)handleDismissWithViewController:(UIViewController *)vc extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
249
|
+
UIViewController *modalHost = [self modalHostViewControllerForViewController:vc];
|
|
250
|
+
if ([self waitForDismissalIfNeededForViewController:modalHost retry:^{
|
|
251
|
+
[self handleDismissWithViewController:vc extras:extras completion:completion];
|
|
252
|
+
}]) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
BOOL isModal = modalHost.modalPresentationStyle == UIModalPresentationOverFullScreen;
|
|
256
|
+
BOOL animated = !isModal;
|
|
257
|
+
if (!isModal && [vc isKindOfClass:[HBDViewController class]]) {
|
|
258
|
+
HBDViewController *hbdvc = (HBDViewController *)vc;
|
|
259
|
+
animated = hbdvc.animatedTransition;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
UIViewController *presenting = modalHost.presentingViewController;
|
|
263
|
+
UIViewController *presented = modalHost.presentedViewController;
|
|
264
|
+
BOOL hasActivePresented = presented != nil && !presented.isBeingDismissed;
|
|
265
|
+
NSString *target = [extras[@"target"] isKindOfClass:[NSString class]] ? extras[@"target"] : nil;
|
|
266
|
+
|
|
267
|
+
if ([target isEqualToString:@"self"]) {
|
|
268
|
+
if (hasActivePresented) {
|
|
269
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeCovered, @"Target scene is covered by another presented scene."));
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (!presenting) {
|
|
273
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Target scene is not presented."));
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
} else if ([target isEqualToString:@"presented"]) {
|
|
277
|
+
if (!hasActivePresented) {
|
|
278
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"No presented scene to dismiss."));
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (!presenting && !modalHost.presentedViewController) {
|
|
284
|
+
RCTLogInfo(@"[Navigation] Nothing to dismiss for sceneId: %@", vc.hbd_sceneId);
|
|
285
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Nothing to dismiss."));
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
UIViewController *dismissReceiver = [target isEqualToString:@"presented"] ? presented : modalHost;
|
|
290
|
+
UIViewController *revealed = [target isEqualToString:@"presented"] ? modalHost : presenting;
|
|
291
|
+
BOOL receiverIsModal = dismissReceiver.modalPresentationStyle == UIModalPresentationOverFullScreen;
|
|
292
|
+
BOOL dismissAnimated = [target isEqualToString:@"presented"] ? !receiverIsModal : animated;
|
|
293
|
+
|
|
294
|
+
if (![target isEqualToString:@"presented"] && !hasActivePresented) {
|
|
295
|
+
[self applyPendingResultIfPresentToViewController:vc extras:extras];
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
[dismissReceiver dismissViewControllerAnimated:dismissAnimated completion:^{
|
|
299
|
+
if (revealed != nil) {
|
|
300
|
+
HBDViewController *hbdvc = [[HBDReactBridgeManager get] primaryViewControllerWithViewController:revealed];
|
|
301
|
+
if (hbdvc != nil) {
|
|
302
|
+
[[HBDOrientationCoordinator shared] applyOrientationForViewController:hbdvc];
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
completion(HBDDispatchResultOk());
|
|
131
306
|
}];
|
|
132
307
|
}
|
|
133
308
|
|
|
134
|
-
- (void)handleShowModalWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras
|
|
135
|
-
if (
|
|
136
|
-
|
|
309
|
+
- (void)handleShowModalWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
310
|
+
if ([self waitForDismissalIfNeededForViewController:presenting retry:^{
|
|
311
|
+
[self handleShowModalWithViewController:presenting extras:extras completion:completion];
|
|
312
|
+
}]) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
if (![presenting hbd_canPresentViewController]) {
|
|
316
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeAlreadyPresenting, @"Target scene is already presenting another scene."));
|
|
137
317
|
return;
|
|
138
318
|
}
|
|
139
319
|
|
|
140
320
|
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
321
|
+
if (!vc) {
|
|
322
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create modal screen."));
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
141
325
|
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
142
326
|
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
143
327
|
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
|
|
144
|
-
[vc
|
|
328
|
+
[vc setHbd_requestCode:requestCode];
|
|
329
|
+
[vc setHbd_presentingSceneId:presenting.hbd_sceneId];
|
|
145
330
|
|
|
331
|
+
NSString *sceneId = [self resolvedSceneIdForViewController:vc];
|
|
146
332
|
[presenting presentViewController:vc animated:NO completion:^{
|
|
147
|
-
|
|
333
|
+
completion(HBDDispatchResultOkWithSceneId(sceneId));
|
|
148
334
|
}];
|
|
149
335
|
}
|
|
150
336
|
|
|
151
|
-
- (void)handlePresentLayoutWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras
|
|
337
|
+
- (void)handlePresentLayoutWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
338
|
+
if ([self isInsideModalViewController:presenting]) {
|
|
339
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Cannot present a scene on top of a modal."));
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
if ([self waitForDismissalIfNeededForViewController:presenting retry:^{
|
|
343
|
+
[self handlePresentLayoutWithViewController:presenting extras:extras completion:completion];
|
|
344
|
+
}]) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if (![presenting hbd_canPresentViewController]) {
|
|
348
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeAlreadyPresenting, @"Target scene is already presenting another scene."));
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
|
|
152
352
|
NSDictionary *layout = extras[@"layout"];
|
|
153
353
|
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
154
354
|
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
|
|
155
|
-
|
|
156
|
-
|
|
355
|
+
if (!vc) {
|
|
356
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create presented layout."));
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
[vc setHbd_requestCode:requestCode];
|
|
360
|
+
[vc setHbd_presentingSceneId:presenting.hbd_sceneId];
|
|
157
361
|
vc.modalPresentationStyle = UIModalPresentationCurrentContext;
|
|
158
362
|
|
|
363
|
+
NSString *sceneId = [self resolvedSceneIdForViewController:vc];
|
|
159
364
|
[presenting presentViewController:vc animated:YES completion:^{
|
|
160
|
-
|
|
365
|
+
completion(HBDDispatchResultOkWithSceneId(sceneId));
|
|
161
366
|
}];
|
|
162
367
|
}
|
|
163
368
|
|
|
164
|
-
- (void)handleShowModalLayoutWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras
|
|
369
|
+
- (void)handleShowModalLayoutWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
370
|
+
if ([self waitForDismissalIfNeededForViewController:presenting retry:^{
|
|
371
|
+
[self handleShowModalLayoutWithViewController:presenting extras:extras completion:completion];
|
|
372
|
+
}]) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (![presenting hbd_canPresentViewController]) {
|
|
376
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeAlreadyPresenting, @"Target scene is already presenting another scene."));
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
|
|
165
380
|
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
166
381
|
NSDictionary *layout = extras[@"layout"];
|
|
167
382
|
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
|
|
383
|
+
if (!vc) {
|
|
384
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create modal layout."));
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
168
387
|
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
169
388
|
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
|
|
170
|
-
[vc
|
|
171
|
-
[vc
|
|
389
|
+
[vc setHbd_requestCode:requestCode];
|
|
390
|
+
[vc setHbd_presentingSceneId:presenting.hbd_sceneId];
|
|
172
391
|
|
|
392
|
+
NSString *sceneId = [self resolvedSceneIdForViewController:vc];
|
|
173
393
|
[presenting presentViewController:vc animated:NO completion:^{
|
|
174
|
-
|
|
394
|
+
completion(HBDDispatchResultOkWithSceneId(sceneId));
|
|
175
395
|
}];
|
|
176
396
|
}
|
|
177
397
|
|