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,9 @@
|
|
|
1
1
|
#import "HBDNativeNavigation.h"
|
|
2
2
|
|
|
3
|
+
#import "HBDGlobalStyle.h"
|
|
3
4
|
#import "HBDReactBridgeManager.h"
|
|
4
5
|
#import "HBDReactViewController.h"
|
|
6
|
+
#import "HBDTabBarController.h"
|
|
5
7
|
|
|
6
8
|
#import <React/RCTLog.h>
|
|
7
9
|
#import <ReactCommon/RCTTurboModule.h>
|
|
@@ -49,11 +51,10 @@
|
|
|
49
51
|
|
|
50
52
|
- (nonnull facebook::react::ModuleConstants<JS::NativeNavigation::Constants::Builder>)constantsToExport {
|
|
51
53
|
JS::NativeNavigation::Constants::Builder::Input input = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
HBDResultOK,
|
|
55
|
+
HBDResultCancel,
|
|
56
|
+
HBDResultBlock
|
|
55
57
|
};
|
|
56
|
-
// 这里用 typedConstants 工厂函数来生成 ModuleConstants
|
|
57
58
|
return facebook::react::typedConstants<JS::NativeNavigation::Constants::Builder>(std::move(input));
|
|
58
59
|
}
|
|
59
60
|
|
|
@@ -80,57 +81,132 @@
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
- (void)currentTab:(nonnull NSString *)sceneId
|
|
84
|
+
- (void)currentTab:(nonnull NSString *)sceneId resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
84
85
|
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
85
86
|
UITabBarController *tabs = vc.tabBarController;
|
|
86
87
|
if (tabs) {
|
|
87
|
-
|
|
88
|
+
resolve(@(tabs.selectedIndex));
|
|
88
89
|
} else {
|
|
89
|
-
|
|
90
|
+
resolve(@(-1));
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
- (
|
|
94
|
-
|
|
94
|
+
- (nullable NSString *)resolvedPresentingSceneIdForViewController:(UIViewController *)vc {
|
|
95
|
+
for (UIViewController *current = vc; current != nil; current = current.parentViewController) {
|
|
96
|
+
if (current.hbd_presentingSceneId.length > 0) {
|
|
97
|
+
return current.hbd_presentingSceneId;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return nil;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
- (NSInteger)resolvedRequestCodeForViewController:(UIViewController *)vc {
|
|
104
|
+
for (UIViewController *current = vc; current != nil; current = current.parentViewController) {
|
|
105
|
+
if (current.hbd_requestCode != 0) {
|
|
106
|
+
return current.hbd_requestCode;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
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
|
+
|
|
125
|
+
- (void)currentRoute:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
126
|
+
[self.bridgeManager runWhenViewHierarchyReady:^{
|
|
127
|
+
HBDViewController *current = [self.bridgeManager primaryViewController];
|
|
128
|
+
NSDictionary *route = [self routeDictionaryForViewController:current];
|
|
129
|
+
if (route) {
|
|
130
|
+
resolve(route);
|
|
131
|
+
} else {
|
|
132
|
+
RCTLogWarn(@"[Navigation] Can't find primaryViewController for currentRoute.");
|
|
133
|
+
resolve(nil);
|
|
134
|
+
}
|
|
135
|
+
} onCancelled:^{
|
|
136
|
+
resolve(nil);
|
|
137
|
+
}];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
- (void)routeGraph:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
141
|
+
[self.bridgeManager runWhenViewHierarchyReady:^{
|
|
142
|
+
NSArray *root = [self.bridgeManager routeGraph];
|
|
143
|
+
resolve(root ?: @[]);
|
|
144
|
+
} onCancelled:^{
|
|
145
|
+
resolve(@[]);
|
|
146
|
+
}];
|
|
95
147
|
}
|
|
96
148
|
|
|
97
|
-
- (void)
|
|
98
|
-
[self
|
|
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
|
+
}];
|
|
99
166
|
}
|
|
100
167
|
|
|
101
|
-
- (void)findSceneIdByModuleName:(nonnull NSString *)moduleName
|
|
102
|
-
[self
|
|
103
|
-
|
|
104
|
-
|
|
168
|
+
- (void)findSceneIdByModuleName:(nonnull NSString *)moduleName resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
169
|
+
[self.bridgeManager runWhenViewHierarchyReady:^{
|
|
170
|
+
NSString *sceneId = [self.bridgeManager findSceneIdByModuleName:moduleName];
|
|
171
|
+
if (sceneId == nil) {
|
|
172
|
+
RCTLogInfo(@"[Navigation] Can't find sceneId by : %@", moduleName);
|
|
173
|
+
resolve(nil);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
RCTLogInfo(@"[Navigation] The sceneId found by %@ : %@", moduleName, sceneId);
|
|
178
|
+
resolve(sceneId);
|
|
179
|
+
} onCancelled:^{
|
|
180
|
+
resolve(nil);
|
|
105
181
|
}];
|
|
106
182
|
}
|
|
107
183
|
|
|
108
|
-
- (void)isStackRoot:(nonnull NSString *)sceneId
|
|
184
|
+
- (void)isStackRoot:(nonnull NSString *)sceneId resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
109
185
|
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
110
186
|
if (!vc) {
|
|
111
|
-
|
|
187
|
+
resolve(@NO);
|
|
112
188
|
return;
|
|
113
189
|
}
|
|
114
190
|
|
|
115
191
|
UINavigationController *nav = vc.navigationController;
|
|
116
192
|
if (!nav) {
|
|
117
|
-
|
|
193
|
+
resolve(@NO);
|
|
118
194
|
return;
|
|
119
195
|
}
|
|
120
196
|
|
|
121
197
|
NSArray *children = nav.childViewControllers;
|
|
122
198
|
if (children.count == 0) {
|
|
123
|
-
|
|
199
|
+
resolve(@NO);
|
|
124
200
|
return;
|
|
125
201
|
}
|
|
126
202
|
|
|
127
203
|
UIViewController *root = children[0];
|
|
128
204
|
if ([self viewController:vc hasAncestorOrSelf:root]) {
|
|
129
|
-
|
|
205
|
+
resolve(@YES);
|
|
130
206
|
return;
|
|
131
207
|
}
|
|
132
208
|
|
|
133
|
-
|
|
209
|
+
resolve(@NO);
|
|
134
210
|
}
|
|
135
211
|
|
|
136
212
|
- (BOOL)viewController:(UIViewController *)viewController hasAncestorOrSelf:(UIViewController *)ancestor {
|
|
@@ -149,136 +225,99 @@
|
|
|
149
225
|
return NO;
|
|
150
226
|
}
|
|
151
227
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
228
|
+
static HBDDispatchCompletion HBDOnceDispatchResolve(RCTPromiseResolveBlock resolve) {
|
|
229
|
+
__block BOOL settled = NO;
|
|
230
|
+
return ^(NSDictionary *result) {
|
|
231
|
+
if (settled) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
settled = YES;
|
|
235
|
+
resolve(result ?: HBDDispatchResultFail(HBDDispatchCodeInvalidAction, nil));
|
|
236
|
+
};
|
|
161
237
|
}
|
|
162
238
|
|
|
163
|
-
- (void)
|
|
164
|
-
self.bridgeManager
|
|
165
|
-
|
|
166
|
-
if (!vc) {
|
|
167
|
-
@throw [[NSException alloc] initWithName:@"IllegalArgumentsException" reason:@"无法创建 ViewController" userInfo:@{ @"layout": layout }];
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (self.bridgeManager.didSetRoot) {
|
|
171
|
-
self.bridgeManager.didSetRoot(@[NSNull.null, @NO]);
|
|
172
|
-
}
|
|
173
|
-
self.bridgeManager.didSetRoot = callback;
|
|
174
|
-
self.bridgeManager.hasRootLayout = YES;
|
|
239
|
+
- (void)dispatch:(nonnull NSString *)sceneId action:(nonnull NSString *)action params:(nonnull NSDictionary *)params resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
240
|
+
[self.bridgeManager enqueueNavigationWithSceneId:sceneId action:action extras:params completion:HBDOnceDispatchResolve(resolve)];
|
|
241
|
+
}
|
|
175
242
|
|
|
176
|
-
|
|
243
|
+
- (void)setRoot:(nonnull NSDictionary *)layout sticky:(BOOL)sticky resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
244
|
+
[self.bridgeManager enqueueSetRootWithLayout:layout completion:HBDOnceDispatchResolve(resolve)];
|
|
177
245
|
}
|
|
178
246
|
|
|
179
|
-
- (void)setResult:(nonnull NSString *)sceneId resultCode:(double)resultCode data:(
|
|
247
|
+
- (void)setResult:(nonnull NSString *)sceneId resultCode:(double)resultCode data:(NSDictionary * _Nullable)data {
|
|
180
248
|
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
181
|
-
[vc
|
|
249
|
+
[vc hbd_setResultCode:resultCode resultData:data];
|
|
182
250
|
}
|
|
183
251
|
|
|
184
|
-
- (void)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
NSString *moduleName = params[@"moduleName"];
|
|
191
|
-
RCTResponseSenderBlock callback = params[@"callback"];
|
|
252
|
+
- (void)setDefaultOptions:(nonnull NSDictionary *)options {
|
|
253
|
+
[HBDGlobalStyle createWithOptions:options];
|
|
254
|
+
}
|
|
192
255
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
256
|
+
- (void)updateOptions:(nonnull NSString *)sceneId options:(nonnull NSDictionary *)options {
|
|
257
|
+
RCTLogInfo(@"[Navigation] updateOptions: %@", options);
|
|
258
|
+
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
259
|
+
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
260
|
+
[(HBDViewController *)vc updateOptions:options];
|
|
198
261
|
}
|
|
199
|
-
|
|
200
|
-
RCTLogInfo(@"[Navigation] The sceneId found by %@ : %@", moduleName, sceneId);
|
|
201
|
-
callback(@[[NSNull null], sceneId]);
|
|
202
262
|
}
|
|
203
263
|
|
|
204
|
-
- (
|
|
205
|
-
|
|
206
|
-
if (
|
|
207
|
-
|
|
208
|
-
if (sceneId != nil) {
|
|
209
|
-
RCTLogInfo(@"[Navigation] The sceneId found by %@ : %@", moduleName, sceneId);
|
|
210
|
-
return sceneId;
|
|
211
|
-
}
|
|
264
|
+
- (void)setBeforeRemoveEnabled:(nonnull NSString *)sceneId enabled:(BOOL)enabled {
|
|
265
|
+
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
266
|
+
if (vc) {
|
|
267
|
+
vc.hbd_beforeRemoveEnabled = enabled;
|
|
212
268
|
}
|
|
269
|
+
}
|
|
213
270
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
271
|
+
- (void)updateTabBar:(nonnull NSString *)sceneId item:(nonnull NSDictionary *)item {
|
|
272
|
+
RCTLogInfo(@"[Navigation] updateTabBar: %@", item);
|
|
273
|
+
UITabBarController *tabBarVC = [self resolveTabBarControllerForSceneId:sceneId];
|
|
274
|
+
if ([tabBarVC isKindOfClass:[HBDTabBarController class]]) {
|
|
275
|
+
[(HBDTabBarController *)tabBarVC updateTabBar:item];
|
|
276
|
+
}
|
|
217
277
|
}
|
|
218
278
|
|
|
219
|
-
- (
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
279
|
+
- (void)setTabItem:(nonnull NSString *)sceneId items:(nonnull NSArray *)items {
|
|
280
|
+
RCTLogInfo(@"[Navigation] setTabItem: %@", items);
|
|
281
|
+
UITabBarController *tabBarVC = [self resolveTabBarControllerForSceneId:sceneId];
|
|
282
|
+
if ([tabBarVC isKindOfClass:[HBDTabBarController class]]) {
|
|
283
|
+
[(HBDTabBarController *)tabBarVC setTabItem:items];
|
|
225
284
|
}
|
|
285
|
+
}
|
|
226
286
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
287
|
+
- (nullable UITabBarController *)resolveTabBarControllerForSceneId:(NSString *)sceneId {
|
|
288
|
+
if (sceneId.length > 0) {
|
|
289
|
+
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
290
|
+
return [self tabBarControllerWithViewController:vc];
|
|
232
291
|
}
|
|
292
|
+
UIViewController *root = [self.bridgeManager mainWindow].rootViewController;
|
|
293
|
+
return [self findTabBarControllerInViewController:root];
|
|
294
|
+
}
|
|
233
295
|
|
|
234
|
-
|
|
235
|
-
if (
|
|
296
|
+
- (nullable UITabBarController *)findTabBarControllerInViewController:(nullable UIViewController *)vc {
|
|
297
|
+
if (!vc) {
|
|
236
298
|
return nil;
|
|
237
299
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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;
|
|
243
307
|
}
|
|
244
308
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
- (void)currentRouteWithCallback:(RCTResponseSenderBlock)callback {
|
|
250
|
-
if (!self.bridgeManager.isViewHierarchyReady) {
|
|
251
|
-
[self performSelector:@selector(currentRouteWithCallback:) withObject:callback afterDelay:0.016];
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
HBDViewController *current = [self.bridgeManager primaryViewController];
|
|
256
|
-
|
|
257
|
-
if (current) {
|
|
258
|
-
callback(@[[NSNull null], @{
|
|
259
|
-
@"moduleName": RCTNullIfNil(current.moduleName),
|
|
260
|
-
@"sceneId": current.sceneId,
|
|
261
|
-
@"presentingId": RCTNullIfNil(current.presentingSceneId),
|
|
262
|
-
@"mode": [current hbd_mode],
|
|
263
|
-
@"requestCode": @(current.requestCode),
|
|
264
|
-
}]);
|
|
265
|
-
} else {
|
|
266
|
-
[self performSelector:@selector(currentRouteWithCallback:) withObject:callback afterDelay:0.016];
|
|
309
|
+
UIViewController *presented = vc.presentedViewController;
|
|
310
|
+
if (presented && presented != vc && !presented.isBeingDismissed) {
|
|
311
|
+
return [self findTabBarControllerInViewController:presented];
|
|
267
312
|
}
|
|
313
|
+
return nil;
|
|
268
314
|
}
|
|
269
315
|
|
|
270
|
-
- (
|
|
271
|
-
if (
|
|
272
|
-
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
NSArray *root = [self.bridgeManager routeGraph];
|
|
277
|
-
if (root.count > 0) {
|
|
278
|
-
callback(@[[NSNull null], root]);
|
|
279
|
-
} else {
|
|
280
|
-
[self performSelector:@selector(routeGraphWithCallback:) withObject:callback afterDelay:0.016];
|
|
316
|
+
- (UITabBarController *)tabBarControllerWithViewController:(UIViewController *)vc {
|
|
317
|
+
if ([vc isKindOfClass:[UITabBarController class]]) {
|
|
318
|
+
return (UITabBarController *)vc;
|
|
281
319
|
}
|
|
320
|
+
return vc.tabBarController;
|
|
282
321
|
}
|
|
283
322
|
|
|
284
323
|
@end
|
package/ios/React/HBDNavigator.h
CHANGED
|
@@ -1,20 +1,52 @@
|
|
|
1
1
|
#import "HBDViewController.h"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
+
|
|
5
|
+
typedef void (^HBDDispatchCompletion)(NSDictionary *result);
|
|
6
|
+
|
|
7
|
+
static NSString *const HBDDispatchCodeOk = @"ok";
|
|
8
|
+
static NSString *const HBDDispatchCodeIntercepted = @"intercepted";
|
|
9
|
+
static NSString *const HBDDispatchCodeSceneNotFound = @"scene_not_found";
|
|
10
|
+
static NSString *const HBDDispatchCodeAlreadyPresenting = @"already_presenting";
|
|
11
|
+
static NSString *const HBDDispatchCodeCovered = @"covered";
|
|
12
|
+
static NSString *const HBDDispatchCodeNotReady = @"not_ready";
|
|
13
|
+
static NSString *const HBDDispatchCodeSuperseded = @"superseded";
|
|
14
|
+
static NSString *const HBDDispatchCodeInvalidAction = @"invalid_action";
|
|
15
|
+
static NSString *const HBDDispatchCodeHostUnavailable = @"host_unavailable";
|
|
16
|
+
|
|
17
|
+
static inline NSDictionary *HBDDispatchResultOk(void) {
|
|
18
|
+
return @{ @"ok": @YES, @"code": HBDDispatchCodeOk };
|
|
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
|
+
|
|
28
|
+
static inline NSDictionary *HBDDispatchResultFail(NSString *code, NSString * _Nullable message) {
|
|
29
|
+
if (message.length > 0) {
|
|
30
|
+
return @{ @"ok": @NO, @"code": code ?: HBDDispatchCodeInvalidAction, @"message": message };
|
|
31
|
+
}
|
|
32
|
+
return @{ @"ok": @NO, @"code": code ?: HBDDispatchCodeInvalidAction };
|
|
33
|
+
}
|
|
4
34
|
|
|
5
35
|
@protocol HBDNavigator <NSObject>
|
|
6
36
|
|
|
7
37
|
@property(nonatomic, copy, readonly) NSString *name;
|
|
8
38
|
@property(nonatomic, copy, readonly) NSArray<NSString *> *supportActions;
|
|
9
39
|
|
|
10
|
-
- (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout;
|
|
40
|
+
- (nullable UIViewController *)viewControllerWithLayout:(NSDictionary *)layout;
|
|
11
41
|
|
|
12
|
-
- (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc;
|
|
42
|
+
- (nullable NSDictionary *)routeGraphWithViewController:(UIViewController *)vc;
|
|
13
43
|
|
|
14
|
-
- (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc;
|
|
44
|
+
- (nullable HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc;
|
|
15
45
|
|
|
16
|
-
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras
|
|
46
|
+
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion;
|
|
17
47
|
|
|
18
48
|
- (void)invalidate;
|
|
19
49
|
|
|
20
50
|
@end
|
|
51
|
+
|
|
52
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
|
|
3
|
+
@class HBDViewController;
|
|
4
|
+
|
|
5
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
6
|
+
|
|
7
|
+
typedef NS_ENUM(NSInteger, HBDScreenOrientation) {
|
|
8
|
+
HBDScreenOrientationUnspecified = 0,
|
|
9
|
+
HBDScreenOrientationPortrait,
|
|
10
|
+
HBDScreenOrientationLandscape,
|
|
11
|
+
HBDScreenOrientationAuto,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
FOUNDATION_EXPORT HBDScreenOrientation HBDScreenOrientationFromString(NSString * _Nullable value);
|
|
15
|
+
|
|
16
|
+
@interface HBDOrientationCoordinator : NSObject
|
|
17
|
+
|
|
18
|
+
+ (instancetype)shared;
|
|
19
|
+
|
|
20
|
+
- (UIInterfaceOrientationMask)supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window;
|
|
21
|
+
- (HBDScreenOrientation)resolvedOrientationForViewController:(HBDViewController *)viewController;
|
|
22
|
+
- (nullable UIWindow *)windowForViewController:(UIViewController *)viewController;
|
|
23
|
+
- (BOOL)isWindowOrientationCompatibleForViewController:(HBDViewController *)viewController window:(UIWindow *)window;
|
|
24
|
+
- (void)applyOrientationForViewController:(HBDViewController *)viewController;
|
|
25
|
+
- (void)sceneOptionsDidUpdate:(HBDViewController *)viewController;
|
|
26
|
+
|
|
27
|
+
@end
|
|
28
|
+
|
|
29
|
+
NS_ASSUME_NONNULL_END
|