hybrid-navigation 5.0.0 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +2 -4
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +48 -2
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +7 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +2 -4
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +3 -0
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +50 -0
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +4 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +16 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +19 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +17 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +66 -7
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +116 -18
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +8 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +376 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +72 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +26 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +134 -12
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +35 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +29 -4
- package/dist/NativeEvent.d.ts +15 -0
- package/dist/NativeNavigation.d.ts +8 -0
- package/dist/Navigation.d.ts +14 -1
- package/dist/Navigation.js +153 -12
- package/dist/NavigationComponentWrap.d.ts +3 -2
- package/dist/Navigator.d.ts +3 -2
- package/dist/Navigator.js +28 -9
- package/dist/Options.d.ts +12 -2
- package/dist/Route.d.ts +70 -5
- package/dist/defineRoutes.d.ts +19 -0
- package/dist/defineRoutes.js +6 -0
- package/dist/handler/DispatchCommandHandler.d.ts +16 -1
- package/dist/handler/DispatchCommandHandler.js +63 -5
- package/dist/handler/LayoutCommandHandler.d.ts +1 -0
- package/dist/handler/LayoutCommandHandler.js +3 -0
- package/dist/handler/LeaveGuardHandler.d.ts +17 -0
- package/dist/handler/LeaveGuardHandler.js +350 -0
- package/dist/handler/LifecycleEventHandler.d.ts +7 -3
- package/dist/handler/LifecycleEventHandler.js +36 -3
- package/dist/handler/PresentationCoordinator.d.ts +24 -0
- package/dist/handler/PresentationCoordinator.js +456 -0
- package/dist/handler/ResultEventHandler.d.ts +7 -0
- package/dist/handler/ResultEventHandler.js +13 -5
- package/dist/handler/TabEventHandler.d.ts +8 -0
- package/dist/handler/TabEventHandler.js +25 -0
- package/dist/hooks.d.ts +3 -1
- package/dist/hooks.js +20 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +3 -0
- package/dist/reveal.d.ts +46 -0
- package/dist/reveal.js +431 -0
- package/dist/routeGraph.d.ts +12 -0
- package/dist/routeGraph.js +68 -0
- package/dist/router/index.js +5 -41
- package/dist/router/tabs.d.ts +1 -0
- package/dist/store.d.ts +2 -0
- package/dist/store.js +4 -0
- package/dist/testing.d.ts +79 -0
- package/dist/testing.js +251 -0
- package/ios/HBDGlobalStyle.h +3 -0
- package/ios/HBDGlobalStyle.mm +13 -0
- package/ios/HybridNavigation.h +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +250 -11
- package/ios/Navigator/HBDStackNavigator.mm +50 -7
- package/ios/Navigator/HBDTabNavigator.mm +33 -5
- package/ios/React/HBDNativeNavigation.mm +73 -12
- package/ios/React/HBDNavigator.h +8 -0
- package/ios/React/HBDOrientationCoordinator.h +2 -0
- package/ios/React/HBDOrientationCoordinator.mm +27 -0
- package/ios/React/HBDReactBridgeManager.h +10 -0
- package/ios/React/HBDReactBridgeManager.mm +48 -2
- package/ios/ViewController/HBDNavigationController.mm +14 -0
- package/ios/ViewController/HBDReactViewController.h +6 -0
- package/ios/ViewController/HBDReactViewController.mm +177 -1
- package/ios/ViewController/HBDTabBarController.h +11 -0
- package/ios/ViewController/HBDTabBarController.mm +170 -3
- package/ios/ViewController/HBDTabBarRenderer.h +28 -0
- package/ios/ViewController/HBDViewController.h +1 -0
- package/ios/ViewController/HBDViewController.mm +57 -9
- package/ios/ViewController/UIViewController+HBD.h +1 -0
- package/ios/ViewController/UIViewController+HBD.mm +17 -4
- package/package.json +3 -1
- package/src/NativeEvent.ts +17 -0
- package/src/NativeNavigation.ts +9 -0
- package/src/Navigation.ts +228 -12
- package/src/NavigationComponentWrap.tsx +11 -2
- package/src/Navigator.ts +38 -9
- package/src/Options.ts +9 -2
- package/src/Route.ts +102 -6
- package/src/defineRoutes.ts +46 -0
- package/src/handler/DispatchCommandHandler.ts +110 -11
- package/src/handler/LayoutCommandHandler.ts +4 -0
- package/src/handler/LeaveGuardHandler.ts +436 -0
- package/src/handler/LifecycleEventHandler.ts +85 -38
- package/src/handler/PresentationCoordinator.ts +566 -0
- package/src/handler/ResultEventHandler.ts +23 -9
- package/src/handler/TabEventHandler.ts +31 -0
- package/src/hooks.ts +37 -1
- package/src/index.ts +11 -0
- package/src/reveal.ts +565 -0
- package/src/routeGraph.ts +87 -0
- package/src/router/index.ts +5 -40
- package/src/router/tabs.ts +1 -0
- package/src/store.ts +5 -0
- package/src/testing.ts +395 -0
- package/testing.d.ts +1 -0
- package/testing.js +3 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#import "HBDReactViewController.h"
|
|
2
2
|
|
|
3
|
+
#import "HBDDrawerController.h"
|
|
3
4
|
#import "HBDGlobalStyle.h"
|
|
4
5
|
#import "HBDNativeEvent.h"
|
|
6
|
+
#import "HBDOrientationCoordinator.h"
|
|
5
7
|
#import "HBDReactBridgeManager.h"
|
|
6
8
|
#import "HBDRootView.h"
|
|
7
9
|
#import "HBDUtils.h"
|
|
@@ -11,6 +13,8 @@
|
|
|
11
13
|
@interface HBDReactViewController ()
|
|
12
14
|
|
|
13
15
|
@property(nonatomic, strong, readwrite) HBDRootView *rootView;
|
|
16
|
+
@property(nonatomic, copy, nullable) dispatch_block_t pushPrewarmCompletion;
|
|
17
|
+
@property(nonatomic, assign) NSUInteger pushPrewarmGeneration;
|
|
14
18
|
|
|
15
19
|
@end
|
|
16
20
|
|
|
@@ -26,6 +30,7 @@
|
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
- (void)dealloc {
|
|
33
|
+
[[HBDReactBridgeManager get] unregisterPrewarmingViewController:self];
|
|
29
34
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:HBDReactBridgeWillReloadNotification object:nil];
|
|
30
35
|
RCTLogInfo(@"[Navigation] 销毁页面 %@", self.moduleName);
|
|
31
36
|
}
|
|
@@ -58,12 +63,13 @@
|
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
- (void)handleReload {
|
|
66
|
+
[self cancelPushPrewarm];
|
|
61
67
|
[self.lifecycleStateMachine handleReload];
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
- (void)loadView {
|
|
65
71
|
RCTHost *rctHost = [HBDReactBridgeManager get].rctHost;
|
|
66
|
-
RCTFabricSurface *surface = [rctHost createSurfaceWithModuleName:self.moduleName initialProperties:[self
|
|
72
|
+
RCTFabricSurface *surface = [rctHost createSurfaceWithModuleName:self.moduleName initialProperties:[self initialPropertiesForSurface]];
|
|
67
73
|
HBDRootView *rootView = [[HBDRootView alloc] initWithSurface:(id)surface];
|
|
68
74
|
self.rootView = rootView;
|
|
69
75
|
rootView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
@@ -115,6 +121,104 @@
|
|
|
115
121
|
return props;
|
|
116
122
|
}
|
|
117
123
|
|
|
124
|
+
- (NSDictionary *)initialPropertiesForSurface {
|
|
125
|
+
NSMutableDictionary *props = [[self propsWithSceneId] mutableCopy];
|
|
126
|
+
if (props[@"initialMetrics"] == nil && [self hbd_globalStyle].injectInitialMetrics) {
|
|
127
|
+
NSDictionary *initialMetrics = [self buildInitialMetrics];
|
|
128
|
+
if (initialMetrics) {
|
|
129
|
+
props[@"initialMetrics"] = initialMetrics;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return props;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
- (BOOL)isInsideDrawerMenu {
|
|
136
|
+
HBDDrawerController *drawer = [self hbd_drawerController];
|
|
137
|
+
if (!drawer || !drawer.menuController) {
|
|
138
|
+
return NO;
|
|
139
|
+
}
|
|
140
|
+
UIViewController *current = self;
|
|
141
|
+
while (current != nil) {
|
|
142
|
+
if (current == drawer.menuController) {
|
|
143
|
+
return YES;
|
|
144
|
+
}
|
|
145
|
+
current = current.parentViewController;
|
|
146
|
+
}
|
|
147
|
+
return NO;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
- (BOOL)isFullscreenModalPresentationStyle:(UIModalPresentationStyle)style {
|
|
151
|
+
return style == UIModalPresentationFullScreen ||
|
|
152
|
+
style == UIModalPresentationOverFullScreen ||
|
|
153
|
+
style == UIModalPresentationCurrentContext ||
|
|
154
|
+
style == UIModalPresentationOverCurrentContext;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
- (BOOL)canUseCurrentWindowGeometry {
|
|
158
|
+
// Tab 根页与 Drawer 侧栏容器不按全屏窗口几何预热或注入,避免与 TabBar / 非全屏尺寸产生首帧偏差。
|
|
159
|
+
if (self.tabBarController != nil || self.options[@"tabItem"] != nil || [self isInsideDrawerMenu]) {
|
|
160
|
+
return NO;
|
|
161
|
+
}
|
|
162
|
+
BOOL isPresentedScene = self.presentingViewController != nil ||
|
|
163
|
+
self.navigationController.presentingViewController != nil ||
|
|
164
|
+
self.hbd_presentingSceneId.length > 0 ||
|
|
165
|
+
self.navigationController.hbd_presentingSceneId.length > 0;
|
|
166
|
+
if (isPresentedScene) {
|
|
167
|
+
UIViewController *host = self.navigationController ?: self;
|
|
168
|
+
if (![self isFullscreenModalPresentationStyle:host.modalPresentationStyle] &&
|
|
169
|
+
![self isFullscreenModalPresentationStyle:self.modalPresentationStyle]) {
|
|
170
|
+
return NO;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
HBDOrientationCoordinator *coordinator = [HBDOrientationCoordinator shared];
|
|
175
|
+
UIWindow *window = [coordinator windowForViewController:self];
|
|
176
|
+
if (!window || ![coordinator isWindowOrientationCompatibleForViewController:self window:window]) {
|
|
177
|
+
return NO;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
UIWindowScene *windowScene = window.windowScene;
|
|
181
|
+
if (!windowScene) {
|
|
182
|
+
return NO;
|
|
183
|
+
}
|
|
184
|
+
BOOL currentStatusHidden = windowScene.statusBarManager.statusBarHidden;
|
|
185
|
+
BOOL inheritsStatusBar = (self.modalPresentationStyle == UIModalPresentationOverFullScreen &&
|
|
186
|
+
self.options[@"statusBarHidden"] == nil);
|
|
187
|
+
if (!inheritsStatusBar && currentStatusHidden != [self prefersStatusBarHidden]) {
|
|
188
|
+
return NO;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return YES;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
- (nullable NSDictionary *)buildInitialMetrics {
|
|
195
|
+
if (![self canUseCurrentWindowGeometry]) {
|
|
196
|
+
return nil;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
UIWindow *window = [[HBDOrientationCoordinator shared] windowForViewController:self];
|
|
200
|
+
if (!window) {
|
|
201
|
+
return nil;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
UIEdgeInsets insets = window.safeAreaInsets;
|
|
205
|
+
CGRect frame = window.bounds;
|
|
206
|
+
return @{
|
|
207
|
+
@"insets": @{
|
|
208
|
+
@"top": @(insets.top),
|
|
209
|
+
@"right": @(insets.right),
|
|
210
|
+
@"bottom": @(insets.bottom),
|
|
211
|
+
@"left": @(insets.left),
|
|
212
|
+
},
|
|
213
|
+
@"frame": @{
|
|
214
|
+
@"x": @(frame.origin.x),
|
|
215
|
+
@"y": @(frame.origin.y),
|
|
216
|
+
@"width": @(frame.size.width),
|
|
217
|
+
@"height": @(frame.size.height),
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
118
222
|
- (void)setAppProperties:(NSDictionary *)props {
|
|
119
223
|
[super setAppProperties:props];
|
|
120
224
|
if ([HBDReactBridgeManager get].isReactModuleRegisterCompleted) {
|
|
@@ -122,8 +226,80 @@
|
|
|
122
226
|
}
|
|
123
227
|
}
|
|
124
228
|
|
|
229
|
+
- (BOOL)prepareForAnimatedPushWithBounds:(CGRect)bounds timeout:(NSTimeInterval)timeout completion:(dispatch_block_t)completion {
|
|
230
|
+
if (![self hbd_globalStyle].prewarmPush || !completion || CGRectIsEmpty(bounds) || ![self canUseCurrentWindowGeometry]) {
|
|
231
|
+
return NO;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
self.pushPrewarmGeneration += 1;
|
|
235
|
+
NSUInteger generation = self.pushPrewarmGeneration;
|
|
236
|
+
self.pushPrewarmCompletion = [completion copy];
|
|
237
|
+
|
|
238
|
+
[[HBDReactBridgeManager get] registerPrewarmingViewController:self];
|
|
239
|
+
|
|
240
|
+
// 提前加载并给 HBDRootView 真实尺寸,让 Fabric 在离屏阶段完成首帧挂载,避免右滑入场前半段空白。
|
|
241
|
+
[self loadViewIfNeeded];
|
|
242
|
+
self.view.frame = bounds;
|
|
243
|
+
[self updateReactViewFrame];
|
|
244
|
+
[self.view layoutIfNeeded];
|
|
245
|
+
[self.rootView layoutIfNeeded];
|
|
246
|
+
|
|
247
|
+
if (self.lifecycleStateMachine.isFirstRendered) {
|
|
248
|
+
__weak HBDReactViewController *weakSelf = self;
|
|
249
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
250
|
+
HBDReactViewController *strongSelf = weakSelf;
|
|
251
|
+
if (strongSelf && strongSelf.pushPrewarmGeneration == generation) {
|
|
252
|
+
[strongSelf finishPushPrewarmWait];
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
return YES;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
NSTimeInterval safeTimeout = timeout > 0 ? timeout : 0.18;
|
|
259
|
+
__weak HBDReactViewController *weakSelf = self;
|
|
260
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(safeTimeout * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
261
|
+
HBDReactViewController *strongSelf = weakSelf;
|
|
262
|
+
if (strongSelf && strongSelf.pushPrewarmGeneration == generation) {
|
|
263
|
+
[strongSelf finishPushPrewarmWait];
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
return YES;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
- (void)finishPushPrewarmWait {
|
|
270
|
+
dispatch_block_t completion = self.pushPrewarmCompletion;
|
|
271
|
+
if (!completion) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
self.pushPrewarmCompletion = nil;
|
|
275
|
+
self.pushPrewarmGeneration += 1;
|
|
276
|
+
[[HBDReactBridgeManager get] unregisterPrewarmingViewController:self];
|
|
277
|
+
if (self.isViewLoaded && self.rootView) {
|
|
278
|
+
[self.view layoutIfNeeded];
|
|
279
|
+
[self.rootView layoutIfNeeded];
|
|
280
|
+
}
|
|
281
|
+
completion();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
- (void)cancelPushPrewarm {
|
|
285
|
+
self.pushPrewarmCompletion = nil;
|
|
286
|
+
self.pushPrewarmGeneration += 1;
|
|
287
|
+
[[HBDReactBridgeManager get] unregisterPrewarmingViewController:self];
|
|
288
|
+
}
|
|
289
|
+
|
|
125
290
|
- (void)signalFirstRenderComplete {
|
|
126
291
|
[self.lifecycleStateMachine markFirstRenderComplete];
|
|
292
|
+
if (self.pushPrewarmCompletion) {
|
|
293
|
+
NSUInteger generation = self.pushPrewarmGeneration;
|
|
294
|
+
__weak HBDReactViewController *weakSelf = self;
|
|
295
|
+
// 等待当前主队列上的 Fabric 挂载与 HBDRootView surfaceView 挂载完成,再启动 push 动画。
|
|
296
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
297
|
+
HBDReactViewController *strongSelf = weakSelf;
|
|
298
|
+
if (strongSelf && strongSelf.pushPrewarmGeneration == generation) {
|
|
299
|
+
[strongSelf finishPushPrewarmWait];
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}
|
|
127
303
|
}
|
|
128
304
|
|
|
129
305
|
- (void)updateOptions:(NSDictionary *)options {
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
#import <UIKit/UIKit.h>
|
|
2
|
+
#import "HBDTabBarRenderer.h"
|
|
2
3
|
|
|
3
4
|
@class HBDGlobalStyle;
|
|
4
5
|
|
|
6
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
7
|
+
|
|
5
8
|
@interface HBDTabBarController : UITabBarController
|
|
6
9
|
|
|
10
|
+
@property(nonatomic, strong, nullable) id<HBDTabBarRenderer> tabBarRenderer;
|
|
11
|
+
|
|
7
12
|
- (void)applyGlobalStyle:(HBDGlobalStyle *)style;
|
|
8
13
|
|
|
9
14
|
- (void)updateTabBar:(NSDictionary *)options;
|
|
10
15
|
|
|
11
16
|
- (void)setTabItem:(NSArray<NSDictionary *> *)options;
|
|
12
17
|
|
|
18
|
+
- (NSArray<NSString *> *)tabKeys;
|
|
19
|
+
|
|
20
|
+
- (NSInteger)indexForTabKey:(NSString *)tabKey;
|
|
21
|
+
|
|
13
22
|
@end
|
|
23
|
+
|
|
24
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
#import "HBDFadeAnimation.h"
|
|
4
4
|
#import "HBDGlobalStyle.h"
|
|
5
|
+
#import "HBDNativeEvent.h"
|
|
6
|
+
#import "HBDReactBridgeManager.h"
|
|
5
7
|
#import "HBDReactViewController.h"
|
|
6
8
|
#import "HBDUtils.h"
|
|
7
9
|
#import "UIViewController+HBD.h"
|
|
@@ -10,6 +12,9 @@
|
|
|
10
12
|
|
|
11
13
|
@interface HBDTabBarController () <UITabBarControllerDelegate>
|
|
12
14
|
|
|
15
|
+
@property(nonatomic, assign) BOOL rendererAttached;
|
|
16
|
+
@property(nonatomic, assign) NSUInteger pendingPreviousSelectedIndex;
|
|
17
|
+
|
|
13
18
|
@end
|
|
14
19
|
|
|
15
20
|
@implementation HBDTabBarController
|
|
@@ -31,6 +36,124 @@
|
|
|
31
36
|
self.definesPresentationContext = NO;
|
|
32
37
|
self.delegate = self;
|
|
33
38
|
[self applyGlobalStyle:[self hbd_globalStyle]];
|
|
39
|
+
[self attachRendererIfNeeded];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
- (void)attachRendererIfNeeded {
|
|
43
|
+
if (!self.tabBarRenderer || self.rendererAttached || !self.isViewLoaded) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
self.rendererAttached = YES;
|
|
47
|
+
if (@available(iOS 18.0, *)) {
|
|
48
|
+
[self setTabBarHidden:YES animated:NO];
|
|
49
|
+
} else {
|
|
50
|
+
self.tabBar.hidden = YES;
|
|
51
|
+
}
|
|
52
|
+
self.additionalSafeAreaInsets = UIEdgeInsetsMake(0, 0, self.tabBarRenderer.contentHeight, 0);
|
|
53
|
+
__weak HBDTabBarController *weakSelf = self;
|
|
54
|
+
[self.tabBarRenderer attachToTabBarController:self onSelectTabAtIndex:^(NSUInteger index) {
|
|
55
|
+
HBDTabBarController *strongSelf = weakSelf;
|
|
56
|
+
if (strongSelf && index < strongSelf.viewControllers.count) {
|
|
57
|
+
NSUInteger previousIndex = strongSelf.selectedIndex;
|
|
58
|
+
[strongSelf selectTabAtIndex:index animated:YES];
|
|
59
|
+
[strongSelf emitTabPressAtIndex:index previousIndex:previousIndex];
|
|
60
|
+
}
|
|
61
|
+
}];
|
|
62
|
+
UIView *barView = self.tabBarRenderer.barView;
|
|
63
|
+
if (barView && barView.superview != self.view) {
|
|
64
|
+
[self.view addSubview:barView];
|
|
65
|
+
}
|
|
66
|
+
[self reloadRendererAnimated:NO];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
- (void)setTabBarRenderer:(id<HBDTabBarRenderer>)tabBarRenderer {
|
|
70
|
+
if (_tabBarRenderer == tabBarRenderer) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (_tabBarRenderer.barView.superview == self.view) {
|
|
74
|
+
[_tabBarRenderer.barView removeFromSuperview];
|
|
75
|
+
}
|
|
76
|
+
_tabBarRenderer = tabBarRenderer;
|
|
77
|
+
self.rendererAttached = NO;
|
|
78
|
+
if (self.isViewLoaded) {
|
|
79
|
+
if (tabBarRenderer) {
|
|
80
|
+
[self attachRendererIfNeeded];
|
|
81
|
+
} else {
|
|
82
|
+
self.additionalSafeAreaInsets = UIEdgeInsetsZero;
|
|
83
|
+
if (@available(iOS 18.0, *)) {
|
|
84
|
+
[self setTabBarHidden:NO animated:NO];
|
|
85
|
+
} else {
|
|
86
|
+
self.tabBar.hidden = NO;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
- (void)setViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers animated:(BOOL)animated {
|
|
93
|
+
[super setViewControllers:viewControllers animated:animated];
|
|
94
|
+
[self reloadRendererAnimated:NO];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
- (void)selectTabAtIndex:(NSUInteger)index animated:(BOOL)animated {
|
|
98
|
+
if (index >= self.viewControllers.count) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
BOOL changed = self.selectedIndex != index;
|
|
102
|
+
[super setSelectedViewController:self.viewControllers[index]];
|
|
103
|
+
[self reloadRendererAnimated:animated && changed];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
- (void)reloadRendererAnimated:(BOOL)animated {
|
|
107
|
+
if (!self.tabBarRenderer || !self.rendererAttached) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
NSMutableArray<UITabBarItem *> *items = [NSMutableArray arrayWithCapacity:self.viewControllers.count];
|
|
111
|
+
for (UIViewController *vc in self.viewControllers) {
|
|
112
|
+
[items addObject:vc.tabBarItem ?: [UITabBarItem new]];
|
|
113
|
+
}
|
|
114
|
+
[self.tabBarRenderer reloadItems:items tabKeys:[self tabKeys] selectedIndex:self.selectedIndex animated:animated];
|
|
115
|
+
[self.view setNeedsLayout];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
- (void)viewDidLayoutSubviews {
|
|
119
|
+
[super viewDidLayoutSubviews];
|
|
120
|
+
if (!self.tabBarRenderer || !self.rendererAttached) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
UIView *barView = self.tabBarRenderer.barView;
|
|
124
|
+
if (barView) {
|
|
125
|
+
[self.view bringSubviewToFront:barView];
|
|
126
|
+
}
|
|
127
|
+
if ([self.tabBarRenderer respondsToSelector:@selector(layoutInContainerView:safeAreaFrame:)]) {
|
|
128
|
+
[self.tabBarRenderer layoutInContainerView:self.view safeAreaFrame:self.view.safeAreaLayoutGuide.layoutFrame];
|
|
129
|
+
} else if (barView) {
|
|
130
|
+
CGRect bounds = self.view.bounds;
|
|
131
|
+
CGRect safe = self.view.safeAreaLayoutGuide.layoutFrame;
|
|
132
|
+
CGFloat top = CGRectGetMaxY(safe);
|
|
133
|
+
barView.frame = CGRectMake(0, top, CGRectGetWidth(bounds), CGRectGetMaxY(bounds) - top);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
- (NSArray<NSString *> *)tabKeys {
|
|
138
|
+
NSMutableArray<NSString *> *keys = [NSMutableArray arrayWithCapacity:self.viewControllers.count];
|
|
139
|
+
for (UIViewController *vc in self.viewControllers) {
|
|
140
|
+
HBDViewController *hbdvc = [self tabViewController:vc];
|
|
141
|
+
[keys addObject:hbdvc.tabKey ?: @""];
|
|
142
|
+
}
|
|
143
|
+
return [keys copy];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
- (NSInteger)indexForTabKey:(NSString *)tabKey {
|
|
147
|
+
if (![tabKey isKindOfClass:[NSString class]] || tabKey.length == 0) {
|
|
148
|
+
return NSNotFound;
|
|
149
|
+
}
|
|
150
|
+
NSArray<NSString *> *keys = [self tabKeys];
|
|
151
|
+
for (NSUInteger i = 0; i < keys.count; i++) {
|
|
152
|
+
if ([keys[i] isEqualToString:tabKey]) {
|
|
153
|
+
return (NSInteger)i;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return NSNotFound;
|
|
34
157
|
}
|
|
35
158
|
|
|
36
159
|
- (void)applyGlobalStyle:(HBDGlobalStyle *)style {
|
|
@@ -42,18 +165,25 @@
|
|
|
42
165
|
HBDViewController *hbdvc = [self tabViewController:tab];
|
|
43
166
|
[hbdvc applyTabBarOptions:hbdvc.options];
|
|
44
167
|
}
|
|
168
|
+
[self reloadRendererAnimated:NO];
|
|
45
169
|
}
|
|
46
170
|
|
|
47
171
|
- (void)setTabItem:(NSArray<NSDictionary *> *)options {
|
|
48
172
|
for (NSDictionary *option in options) {
|
|
49
|
-
|
|
50
|
-
if (index
|
|
173
|
+
NSInteger resolvedIndex = NSNotFound;
|
|
174
|
+
if ([option[@"index"] isKindOfClass:[NSNumber class]]) {
|
|
175
|
+
resolvedIndex = [option[@"index"] integerValue];
|
|
176
|
+
} else if ([option[@"key"] isKindOfClass:[NSString class]]) {
|
|
177
|
+
resolvedIndex = [self indexForTabKey:option[@"key"]];
|
|
178
|
+
}
|
|
179
|
+
if (resolvedIndex < 0 || (NSUInteger)resolvedIndex >= self.viewControllers.count) {
|
|
51
180
|
continue;
|
|
52
181
|
}
|
|
53
|
-
UIViewController *tab = self.viewControllers[
|
|
182
|
+
UIViewController *tab = self.viewControllers[(NSUInteger)resolvedIndex];
|
|
54
183
|
HBDViewController *hbdvc = [self tabViewController:tab];
|
|
55
184
|
[hbdvc updateTabBarItem:option];
|
|
56
185
|
}
|
|
186
|
+
[self reloadRendererAnimated:NO];
|
|
57
187
|
}
|
|
58
188
|
|
|
59
189
|
- (HBDViewController *)tabViewController:(UIViewController *)vc {
|
|
@@ -116,6 +246,10 @@
|
|
|
116
246
|
HBDViewController *hbdvc = [self tabViewController:tab];
|
|
117
247
|
[hbdvc applyTabBarOptions:hbdvc.options];
|
|
118
248
|
}
|
|
249
|
+
if ([self.tabBarRenderer respondsToSelector:@selector(updateTabBarStyle:)]) {
|
|
250
|
+
[self.tabBarRenderer updateTabBarStyle:options];
|
|
251
|
+
}
|
|
252
|
+
[self reloadRendererAnimated:NO];
|
|
119
253
|
}
|
|
120
254
|
|
|
121
255
|
- (void)hbd_didReceiveResultCode:(NSInteger)resultCode resultData:(NSDictionary *)data requestCode:(NSInteger)requestCode {
|
|
@@ -128,10 +262,43 @@
|
|
|
128
262
|
}
|
|
129
263
|
}
|
|
130
264
|
|
|
265
|
+
- (void)setSelectedViewController:(__kindof UIViewController *)selectedViewController {
|
|
266
|
+
[super setSelectedViewController:selectedViewController];
|
|
267
|
+
[self reloadRendererAnimated:NO];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
- (void)emitTabPressAtIndex:(NSUInteger)index previousIndex:(NSUInteger)previousIndex {
|
|
271
|
+
if (![HBDReactBridgeManager get].isReactModuleRegisterCompleted) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
NSArray<NSString *> *keys = [self tabKeys];
|
|
275
|
+
NSString *tabKey = (index < keys.count) ? keys[index] : @"";
|
|
276
|
+
NSMutableDictionary *payload = [@{
|
|
277
|
+
@"index": @(index),
|
|
278
|
+
@"previousIndex": @(previousIndex),
|
|
279
|
+
@"reselected": @(index == previousIndex),
|
|
280
|
+
} mutableCopy];
|
|
281
|
+
if (tabKey.length > 0) {
|
|
282
|
+
payload[@"tabKey"] = tabKey;
|
|
283
|
+
}
|
|
284
|
+
HBDNativeEvent *event = [HBDNativeEvent getInstance];
|
|
285
|
+
if (event) {
|
|
286
|
+
[event emitOnTabPress:[payload copy]];
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
131
290
|
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
|
|
291
|
+
self.pendingPreviousSelectedIndex = self.selectedIndex;
|
|
132
292
|
return YES;
|
|
133
293
|
}
|
|
134
294
|
|
|
295
|
+
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
|
|
296
|
+
NSUInteger index = [self.viewControllers indexOfObject:viewController];
|
|
297
|
+
if (index != NSNotFound) {
|
|
298
|
+
[self emitTabPressAtIndex:index previousIndex:self.pendingPreviousSelectedIndex];
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
135
302
|
- (id<UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController animationControllerForTransitionFromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC {
|
|
136
303
|
if (toVC.viewLoaded) {
|
|
137
304
|
return nil;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
|
|
3
|
+
@class HBDTabBarController;
|
|
4
|
+
|
|
5
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
6
|
+
|
|
7
|
+
@protocol HBDTabBarRenderer <NSObject>
|
|
8
|
+
|
|
9
|
+
@property(nonatomic, strong, readonly) UIView *barView;
|
|
10
|
+
@property(nonatomic, assign, readonly) CGFloat contentHeight;
|
|
11
|
+
|
|
12
|
+
- (void)attachToTabBarController:(HBDTabBarController *)tabBarController
|
|
13
|
+
onSelectTabAtIndex:(void (^)(NSUInteger index))onSelectTabAtIndex;
|
|
14
|
+
|
|
15
|
+
- (void)reloadItems:(NSArray<UITabBarItem *> *)items
|
|
16
|
+
tabKeys:(NSArray<NSString *> *)tabKeys
|
|
17
|
+
selectedIndex:(NSUInteger)selectedIndex
|
|
18
|
+
animated:(BOOL)animated;
|
|
19
|
+
|
|
20
|
+
@optional
|
|
21
|
+
- (void)updateTabBarStyle:(NSDictionary *)options;
|
|
22
|
+
- (void)layoutInContainerView:(UIView *)containerView safeAreaFrame:(CGRect)safeAreaFrame;
|
|
23
|
+
|
|
24
|
+
@end
|
|
25
|
+
|
|
26
|
+
typedef id<HBDTabBarRenderer> _Nonnull (^HBDTabBarRendererFactory)(void);
|
|
27
|
+
|
|
28
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
@property(nonatomic, copy, readonly) NSDictionary *options;
|
|
12
12
|
@property(nonatomic, assign, readonly) BOOL animatedTransition;
|
|
13
13
|
@property(nonatomic, assign, readonly) HBDScreenOrientation screenOrientation;
|
|
14
|
+
@property(nonatomic, copy, readonly) NSString *tabKey;
|
|
14
15
|
@property(nonatomic, strong, readonly) HBDSceneLifecycleStateMachine *lifecycleStateMachine;
|
|
15
16
|
|
|
16
17
|
- (instancetype)initWithModuleName:(NSString *)moduleName props:(NSDictionary *)props options:(NSDictionary *)options NS_DESIGNATED_INITIALIZER;
|
|
@@ -9,19 +9,45 @@
|
|
|
9
9
|
|
|
10
10
|
#import <React/RCTLog.h>
|
|
11
11
|
|
|
12
|
-
static
|
|
12
|
+
static NSString * _Nullable HBDResolvePresentingSceneId(UIViewController *vc) {
|
|
13
|
+
for (UIViewController *current = vc; current != nil; current = current.parentViewController) {
|
|
14
|
+
if (current.hbd_presentingSceneId.length > 0) {
|
|
15
|
+
return current.hbd_presentingSceneId;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return nil;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static void HBDEmitSceneStateChange(
|
|
22
|
+
NSString *sceneId,
|
|
23
|
+
HBDSceneLifecycleState prevState,
|
|
24
|
+
HBDSceneLifecycleState newState,
|
|
25
|
+
NSString * _Nullable moduleName,
|
|
26
|
+
NSString * _Nullable mode,
|
|
27
|
+
NSString * _Nullable presentingId
|
|
28
|
+
) {
|
|
13
29
|
if (sceneId.length == 0) {
|
|
14
30
|
return;
|
|
15
31
|
}
|
|
16
|
-
|
|
32
|
+
NSMutableDictionary *payload = [@{
|
|
17
33
|
@"sceneId": sceneId,
|
|
18
34
|
@"state": HBDSceneLifecycleStateToString(newState),
|
|
19
35
|
@"prevState": HBDSceneLifecycleStateToString(prevState),
|
|
20
|
-
};
|
|
36
|
+
} mutableCopy];
|
|
37
|
+
if (moduleName.length > 0) {
|
|
38
|
+
payload[@"moduleName"] = moduleName;
|
|
39
|
+
}
|
|
40
|
+
if (mode.length > 0) {
|
|
41
|
+
payload[@"mode"] = mode;
|
|
42
|
+
}
|
|
43
|
+
if (presentingId.length > 0) {
|
|
44
|
+
payload[@"presentingId"] = presentingId;
|
|
45
|
+
}
|
|
46
|
+
NSDictionary *immutablePayload = [payload copy];
|
|
21
47
|
dispatch_block_t emitBlock = ^{
|
|
22
48
|
HBDNativeEvent *event = [HBDNativeEvent getInstance];
|
|
23
49
|
if (event) {
|
|
24
|
-
[event emitOnSceneStateChange:
|
|
50
|
+
[event emitOnSceneStateChange:immutablePayload];
|
|
25
51
|
}
|
|
26
52
|
};
|
|
27
53
|
if ([NSThread isMainThread]) {
|
|
@@ -46,11 +72,14 @@ static void HBDEmitSceneStateChange(NSString *sceneId, HBDSceneLifecycleState pr
|
|
|
46
72
|
HBDSceneLifecycleState prevState = self.lifecycleStateMachine.state;
|
|
47
73
|
if (prevState != HBDSceneLifecycleStateDestroyed) {
|
|
48
74
|
NSString *sceneId = self.hbd_sceneId;
|
|
75
|
+
NSString *moduleName = self.moduleName;
|
|
76
|
+
NSString *mode = [self hbd_mode];
|
|
77
|
+
NSString *presentingId = HBDResolvePresentingSceneId(self);
|
|
49
78
|
if (prevState == HBDSceneLifecycleStateVisible) {
|
|
50
|
-
HBDEmitSceneStateChange(sceneId, HBDSceneLifecycleStateVisible, HBDSceneLifecycleStateInvisible);
|
|
79
|
+
HBDEmitSceneStateChange(sceneId, HBDSceneLifecycleStateVisible, HBDSceneLifecycleStateInvisible, moduleName, mode, presentingId);
|
|
51
80
|
prevState = HBDSceneLifecycleStateInvisible;
|
|
52
81
|
}
|
|
53
|
-
HBDEmitSceneStateChange(sceneId, prevState, HBDSceneLifecycleStateDestroyed);
|
|
82
|
+
HBDEmitSceneStateChange(sceneId, prevState, HBDSceneLifecycleStateDestroyed, moduleName, mode, presentingId);
|
|
54
83
|
[self.lifecycleStateMachine markDestroyed];
|
|
55
84
|
}
|
|
56
85
|
}
|
|
@@ -92,13 +121,31 @@ static void HBDEmitSceneStateChange(NSString *sceneId, HBDSceneLifecycleState pr
|
|
|
92
121
|
return HBDScreenOrientationFromString(self.options[@"orientation"]);
|
|
93
122
|
}
|
|
94
123
|
|
|
124
|
+
- (nullable NSString *)tabKey {
|
|
125
|
+
NSDictionary *tabItem = self.options[@"tabItem"];
|
|
126
|
+
if ([tabItem isKindOfClass:[NSDictionary class]]) {
|
|
127
|
+
NSString *key = tabItem[@"key"];
|
|
128
|
+
if ([key isKindOfClass:[NSString class]] && key.length > 0) {
|
|
129
|
+
return key;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return nil;
|
|
133
|
+
}
|
|
134
|
+
|
|
95
135
|
- (BOOL)isNativeManagedLifecycle {
|
|
96
136
|
return YES;
|
|
97
137
|
}
|
|
98
138
|
|
|
99
139
|
- (void)sceneLifecycleDidChangeFromState:(HBDSceneLifecycleState)prevState toState:(HBDSceneLifecycleState)newState {
|
|
100
140
|
if ([HBDReactBridgeManager get].isReactModuleRegisterCompleted || newState == HBDSceneLifecycleStateDestroyed) {
|
|
101
|
-
HBDEmitSceneStateChange(
|
|
141
|
+
HBDEmitSceneStateChange(
|
|
142
|
+
self.hbd_sceneId,
|
|
143
|
+
prevState,
|
|
144
|
+
newState,
|
|
145
|
+
self.moduleName,
|
|
146
|
+
[self hbd_mode],
|
|
147
|
+
HBDResolvePresentingSceneId(self)
|
|
148
|
+
);
|
|
102
149
|
}
|
|
103
150
|
}
|
|
104
151
|
|
|
@@ -138,7 +185,8 @@ static void HBDEmitSceneStateChange(NSString *sceneId, HBDSceneLifecycleState pr
|
|
|
138
185
|
|
|
139
186
|
- (void)viewWillDisappear:(BOOL)animated {
|
|
140
187
|
[super viewWillDisappear:animated];
|
|
141
|
-
|
|
188
|
+
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator ?: self.navigationController.transitionCoordinator;
|
|
189
|
+
BOOL interactive = coordinator.interactive;
|
|
142
190
|
[self.lifecycleStateMachine viewWillDisappearWithInteractiveTransition:interactive];
|
|
143
191
|
}
|
|
144
192
|
|
|
@@ -176,7 +224,7 @@ static void HBDEmitSceneStateChange(NSString *sceneId, HBDSceneLifecycleState pr
|
|
|
176
224
|
}
|
|
177
225
|
|
|
178
226
|
- (void)setModalBackgroundColor {
|
|
179
|
-
self.view.backgroundColor = UIColor.clearColor;
|
|
227
|
+
self.view.backgroundColor = [self hbd_globalStyle].modalBackgroundColor ?: UIColor.clearColor;
|
|
180
228
|
|
|
181
229
|
NSString *screenColor = self.options[@"screenBackgroundColor"];
|
|
182
230
|
|
|
@@ -10,6 +10,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
10
10
|
|
|
11
11
|
@property(nonatomic, assign) UIBarStyle hbd_barStyle;
|
|
12
12
|
@property(nonatomic, assign) BOOL hbd_backInteractive;
|
|
13
|
+
@property(nonatomic, assign) BOOL hbd_beforeRemoveEnabled;
|
|
13
14
|
@property(nonatomic, assign) BOOL hbd_statusBarHidden;
|
|
14
15
|
|
|
15
16
|
@property(nonatomic, copy, readonly) NSString *hbd_sceneId;
|
|
@@ -75,6 +75,14 @@ static BOOL HBDIsManagedViewController(UIViewController * _Nullable vc) {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
[self hbd_dismissViewControllerAnimated:animated completion:^{
|
|
78
|
+
if (completion) {
|
|
79
|
+
completion();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (presented.presentingViewController != nil) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
78
86
|
BOOL consumed = presented.hbd_presentingSceneId.length > 0 &&
|
|
79
87
|
[UIViewController hbd_dispatchResult:presenting presented:presented sceneId:presented.hbd_presentingSceneId];
|
|
80
88
|
if (!consumed) {
|
|
@@ -82,10 +90,6 @@ static BOOL HBDIsManagedViewController(UIViewController * _Nullable vc) {
|
|
|
82
90
|
resultData:presented.hbd_resultData
|
|
83
91
|
requestCode:presented.hbd_requestCode];
|
|
84
92
|
}
|
|
85
|
-
|
|
86
|
-
if (completion) {
|
|
87
|
-
completion();
|
|
88
|
-
}
|
|
89
93
|
}];
|
|
90
94
|
}
|
|
91
95
|
|
|
@@ -147,6 +151,15 @@ static BOOL HBDIsManagedViewController(UIViewController * _Nullable vc) {
|
|
|
147
151
|
objc_setAssociatedObject(self, @selector(hbd_backInteractive), @(interactive), OBJC_ASSOCIATION_COPY_NONATOMIC);
|
|
148
152
|
}
|
|
149
153
|
|
|
154
|
+
- (BOOL)hbd_beforeRemoveEnabled {
|
|
155
|
+
id obj = objc_getAssociatedObject(self, _cmd);
|
|
156
|
+
return obj ? [obj boolValue] : NO;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
- (void)setHbd_beforeRemoveEnabled:(BOOL)enabled {
|
|
160
|
+
objc_setAssociatedObject(self, @selector(hbd_beforeRemoveEnabled), @(enabled), OBJC_ASSOCIATION_COPY_NONATOMIC);
|
|
161
|
+
}
|
|
162
|
+
|
|
150
163
|
- (void)setHbd_resultCode:(NSInteger)resultCode {
|
|
151
164
|
UIViewController *presenting = self.presentingViewController;
|
|
152
165
|
if (presenting) {
|