hybrid-navigation 3.1.1 → 3.1.2
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/ios/GlobalStyle.h +0 -6
- package/ios/HBDUtils.mm +24 -0
- package/ios/Navigator/HBDScreenNavigator.mm +2 -0
- package/ios/View/UIImage+WithBadge.mm +29 -3
- package/ios/ViewController/HBDNavigationController.mm +110 -3
- package/ios/ViewController/HBDReactViewController.mm +12 -1
- package/ios/ViewController/HBDViewController.mm +29 -22
- package/ios/ViewController/UINavigationController+HBD.mm +12 -0
- package/ios/ViewController/UIViewController+HBD.mm +8 -1
- package/package.json +1 -1
package/ios/GlobalStyle.h
CHANGED
|
@@ -14,12 +14,6 @@
|
|
|
14
14
|
|
|
15
15
|
- (instancetype)initWithOptions:(NSDictionary *)options;
|
|
16
16
|
|
|
17
|
-
- (void)inflateNavigationBar:(UINavigationBar *)navigationBar;
|
|
18
|
-
|
|
19
|
-
- (void)inflateBarButtonItem:(UIBarButtonItem *)barButtonItem;
|
|
20
|
-
|
|
21
|
-
- (void)inflateTabBar:(UITabBar *)tabBar;
|
|
22
|
-
|
|
23
17
|
- (UIColor *)titleTextColorWithBarStyle:(UIBarStyle)barStyle;
|
|
24
18
|
|
|
25
19
|
- (UIColor *)tintColorWithBarStyle:(UIBarStyle)barStyle;
|
package/ios/HBDUtils.mm
CHANGED
|
@@ -2,8 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
#import <React/RCTConvert.h>
|
|
4
4
|
|
|
5
|
+
@implementation UIScrollView (HBDEdgeEffect)
|
|
6
|
+
|
|
7
|
+
- (void)hbd_didMoveToWindow {
|
|
8
|
+
[self hbd_didMoveToWindow];
|
|
9
|
+
|
|
10
|
+
if (@available(iOS 26.0, *)) {
|
|
11
|
+
self.topEdgeEffect.hidden = YES;
|
|
12
|
+
self.leftEdgeEffect.hidden = YES;
|
|
13
|
+
self.bottomEdgeEffect.hidden = YES;
|
|
14
|
+
self.rightEdgeEffect.hidden = YES;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@end
|
|
19
|
+
|
|
5
20
|
@implementation HBDUtils
|
|
6
21
|
|
|
22
|
+
+ (void)load {
|
|
23
|
+
if (@available(iOS 26.0, *)) {
|
|
24
|
+
static dispatch_once_t onceToken;
|
|
25
|
+
dispatch_once(&onceToken, ^{
|
|
26
|
+
hbd_exchangeImplementations([UIScrollView class], @selector(didMoveToWindow), @selector(hbd_didMoveToWindow));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
7
31
|
+ (NSDictionary *)mergeItem:(NSDictionary *)item withTarget:(NSDictionary *)target {
|
|
8
32
|
NSMutableDictionary *mutableTarget = [target mutableCopy];
|
|
9
33
|
for (NSString *key in [item allKeys]) {
|
|
@@ -140,6 +140,7 @@
|
|
|
140
140
|
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
141
141
|
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
|
|
142
142
|
[vc setRequestCode:requestCode];
|
|
143
|
+
[vc setPresentingSceneId:presenting.sceneId];
|
|
143
144
|
vc.modalPresentationStyle = UIModalPresentationCurrentContext;
|
|
144
145
|
|
|
145
146
|
[presenting presentViewController:vc animated:YES completion:^{
|
|
@@ -154,6 +155,7 @@
|
|
|
154
155
|
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
155
156
|
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
|
|
156
157
|
[vc setRequestCode:requestCode];
|
|
158
|
+
[vc setPresentingSceneId:presenting.sceneId];
|
|
157
159
|
|
|
158
160
|
[presenting presentViewController:vc animated:YES completion:^{
|
|
159
161
|
callback(@[NSNull.null, @YES]);
|
|
@@ -4,20 +4,46 @@
|
|
|
4
4
|
|
|
5
5
|
- (UIImage *)withIconColor:(UIColor *)iconColor badgeColor:(UIColor *)badgeColor {
|
|
6
6
|
CGSize imageSize = self.size;
|
|
7
|
+
if (badgeColor == nil || CGColorGetAlpha(badgeColor.CGColor) <= 0.0) {
|
|
8
|
+
UIGraphicsImageRenderer *render = [[UIGraphicsImageRenderer alloc] initWithSize:imageSize];
|
|
9
|
+
UIImage *resultImage = [render imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
|
|
10
|
+
UIImage *iconTintedImage = [self imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
|
11
|
+
[iconColor set];
|
|
12
|
+
[iconTintedImage drawAtPoint:CGPointZero];
|
|
13
|
+
}];
|
|
14
|
+
return [resultImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static CGFloat const HBDTabBarBadgeHorizontalPadding = 8.0;
|
|
18
|
+
static CGFloat const HBDTabBarBadgeVerticalPadding = 2.0;
|
|
19
|
+
static CGFloat const HBDTabBarBadgeOffsetX = 0.0;
|
|
20
|
+
static CGFloat const HBDTabBarBadgeOffsetY = 0.0;
|
|
21
|
+
CGSize canvasSize = CGSizeMake(
|
|
22
|
+
imageSize.width + HBDTabBarBadgeHorizontalPadding * 2,
|
|
23
|
+
imageSize.height + HBDTabBarBadgeVerticalPadding * 2
|
|
24
|
+
);
|
|
7
25
|
|
|
8
|
-
UIGraphicsImageRenderer *render = [[UIGraphicsImageRenderer alloc] initWithSize:
|
|
26
|
+
UIGraphicsImageRenderer *render = [[UIGraphicsImageRenderer alloc] initWithSize:canvasSize];
|
|
9
27
|
|
|
10
28
|
UIImage *resultImage = [render imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
|
|
11
29
|
// 创建 tint 后的图标图片
|
|
12
30
|
UIImage *iconTintedImage = [self imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
|
31
|
+
CGPoint iconOrigin = CGPointMake(
|
|
32
|
+
(canvasSize.width - imageSize.width) / 2.0,
|
|
33
|
+
(canvasSize.height - imageSize.height) / 2.0
|
|
34
|
+
);
|
|
35
|
+
CGRect iconFrame = CGRectMake(iconOrigin.x, iconOrigin.y, imageSize.width, imageSize.height);
|
|
13
36
|
|
|
14
37
|
// 设置图标颜色并绘制
|
|
15
38
|
[iconColor set];
|
|
16
|
-
[iconTintedImage drawAtPoint:
|
|
39
|
+
[iconTintedImage drawAtPoint:iconOrigin];
|
|
17
40
|
|
|
18
41
|
// 创建徽章
|
|
19
42
|
CGSize badgeSize = CGSizeMake(8, 8);
|
|
20
|
-
CGPoint badgeOrigin = CGPointMake(
|
|
43
|
+
CGPoint badgeOrigin = CGPointMake(
|
|
44
|
+
CGRectGetMaxX(iconFrame) + HBDTabBarBadgeOffsetX,
|
|
45
|
+
HBDTabBarBadgeOffsetY
|
|
46
|
+
);
|
|
21
47
|
CGRect badgeRect = CGRectMake(badgeOrigin.x, badgeOrigin.y, badgeSize.width, badgeSize.height);
|
|
22
48
|
|
|
23
49
|
UIBezierPath *badgePath = [UIBezierPath bezierPathWithOvalInRect:badgeRect];
|
|
@@ -25,6 +25,14 @@
|
|
|
25
25
|
- (instancetype)initWithNavigationController:(HBDNavigationController *)navigationController;
|
|
26
26
|
- (void)hbd_compensateSafeAreaForViewController:(UIViewController *)vc expectedTopInset:(CGFloat)expectedTopInset isToVC:(BOOL)isToVC;
|
|
27
27
|
- (void)hbd_restoreCompensatedSafeAreaForFrom:(UIViewController *)from to:(UIViewController *)to viewController:(UIViewController *)viewController;
|
|
28
|
+
- (BOOL)shouldAnimateTabBarFrom:(UIViewController *)from to:(UIViewController *)to;
|
|
29
|
+
- (void)prepareTabBarForTransitionFrom:(UIViewController *)from to:(UIViewController *)to;
|
|
30
|
+
- (void)animateTabBarForTransitionFrom:(UIViewController *)from to:(UIViewController *)to;
|
|
31
|
+
- (void)completeTabBarTransitionFrom:(UIViewController *)from
|
|
32
|
+
to:(UIViewController *)to
|
|
33
|
+
cancelled:(BOOL)cancelled;
|
|
34
|
+
- (BOOL)shouldUseFadeAnimationFrom:(UIViewController *)from to:(UIViewController *)to;
|
|
35
|
+
- (BOOL)shouldHandleInteractiveTransitionWithNavigationController:(HBDNavigationController *)nav;
|
|
28
36
|
|
|
29
37
|
@end
|
|
30
38
|
|
|
@@ -99,9 +107,12 @@
|
|
|
99
107
|
HBDNavigationController *nav = self.nav;
|
|
100
108
|
|
|
101
109
|
id <UIViewControllerTransitionCoordinator> coordinator = nav.transitionCoordinator;
|
|
110
|
+
BOOL shouldHandleInteractiveTransition =
|
|
111
|
+
[self shouldBetterTransitionWithViewController:nav.topViewController] ||
|
|
112
|
+
[self shouldHandleInteractiveTransitionWithNavigationController:nav];
|
|
102
113
|
|
|
103
114
|
if (![self.proxyDelegate respondsToSelector:@selector(navigationController:interactionControllerForAnimationController:)]) {
|
|
104
|
-
if (self.interactiveTransition || (!coordinator &&
|
|
115
|
+
if (self.interactiveTransition || (!coordinator && shouldHandleInteractiveTransition)) {
|
|
105
116
|
CGFloat process = [pan translationInView:nav.view].x / nav.view.bounds.size.width;
|
|
106
117
|
process = MIN(1.0, (MAX(0.0, process)));
|
|
107
118
|
if (pan.state == UIGestureRecognizerStateBegan) {
|
|
@@ -173,13 +184,20 @@
|
|
|
173
184
|
if (self.proxyDelegate && [self.proxyDelegate respondsToSelector:@selector(navigationControllerSupportedInterfaceOrientations:)]) {
|
|
174
185
|
return [self.proxyDelegate navigationControllerSupportedInterfaceOrientations:navigationController];
|
|
175
186
|
}
|
|
176
|
-
return
|
|
187
|
+
return [GlobalStyle globalStyle].interfaceOrientation;
|
|
177
188
|
}
|
|
178
189
|
|
|
179
190
|
- (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController {
|
|
180
191
|
if (self.proxyDelegate && [self.proxyDelegate respondsToSelector:@selector(navigationControllerPreferredInterfaceOrientationForPresentation:)]) {
|
|
181
192
|
return [self.proxyDelegate navigationControllerPreferredInterfaceOrientationForPresentation:navigationController];
|
|
182
193
|
}
|
|
194
|
+
UIInterfaceOrientationMask mask = [GlobalStyle globalStyle].interfaceOrientation;
|
|
195
|
+
if (mask & UIInterfaceOrientationMaskLandscapeRight) {
|
|
196
|
+
return UIInterfaceOrientationLandscapeRight;
|
|
197
|
+
}
|
|
198
|
+
if (mask & UIInterfaceOrientationMaskLandscapeLeft) {
|
|
199
|
+
return UIInterfaceOrientationLandscapeLeft;
|
|
200
|
+
}
|
|
183
201
|
return UIInterfaceOrientationPortrait;
|
|
184
202
|
}
|
|
185
203
|
|
|
@@ -189,7 +207,8 @@
|
|
|
189
207
|
return [self.proxyDelegate navigationController:navigationController interactionControllerForAnimationController:animationController];
|
|
190
208
|
}
|
|
191
209
|
|
|
192
|
-
if ([animationController isKindOfClass:[HBDPopAnimation class]]
|
|
210
|
+
if ([animationController isKindOfClass:[HBDPopAnimation class]] ||
|
|
211
|
+
[animationController isKindOfClass:[HBDFadeAnimation class]]) {
|
|
193
212
|
return self.interactiveTransition;
|
|
194
213
|
}
|
|
195
214
|
|
|
@@ -250,6 +269,34 @@
|
|
|
250
269
|
return shouldBetter;
|
|
251
270
|
}
|
|
252
271
|
|
|
272
|
+
- (BOOL)shouldUseFadeAnimationFrom:(UIViewController *)from to:(UIViewController *)to {
|
|
273
|
+
if ([from isKindOfClass:[HBDViewController class]]) {
|
|
274
|
+
HBDViewController *hbdFromVC = (HBDViewController *)from;
|
|
275
|
+
if (hbdFromVC.forceScreenLandscape) {
|
|
276
|
+
return YES;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if ([to isKindOfClass:[HBDViewController class]]) {
|
|
281
|
+
HBDViewController *hbdToVC = (HBDViewController *)to;
|
|
282
|
+
if (hbdToVC.forceScreenLandscape) {
|
|
283
|
+
return YES;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return NO;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
- (BOOL)shouldHandleInteractiveTransitionWithNavigationController:(HBDNavigationController *)nav {
|
|
291
|
+
if (nav.viewControllers.count < 2) {
|
|
292
|
+
return NO;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
UIViewController *from = nav.topViewController;
|
|
296
|
+
UIViewController *to = nav.viewControllers[nav.viewControllers.count - 2];
|
|
297
|
+
return [self shouldUseFadeAnimationFrom:from to:to];
|
|
298
|
+
}
|
|
299
|
+
|
|
253
300
|
- (void)hbd_compensateSafeAreaForViewController:(UIViewController *)vc expectedTopInset:(CGFloat)expectedTopInset isToVC:(BOOL)isToVC {
|
|
254
301
|
if (vc.isViewLoaded) {
|
|
255
302
|
[vc.view layoutIfNeeded];
|
|
@@ -304,6 +351,11 @@
|
|
|
304
351
|
|
|
305
352
|
[self.nav updateNavigationBarStyleForViewController:viewController];
|
|
306
353
|
|
|
354
|
+
BOOL shouldAnimateTabBar = [self shouldAnimateTabBarFrom:from to:to];
|
|
355
|
+
if (shouldAnimateTabBar) {
|
|
356
|
+
[self prepareTabBarForTransitionFrom:from to:to];
|
|
357
|
+
}
|
|
358
|
+
|
|
307
359
|
[coordinator animateAlongsideTransition:^(id <UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
308
360
|
BOOL shouldFake = [self shouldShowFakeBarFrom:from to:to viewController:viewController];
|
|
309
361
|
if (shouldFake) {
|
|
@@ -326,6 +378,10 @@
|
|
|
326
378
|
}
|
|
327
379
|
}
|
|
328
380
|
}
|
|
381
|
+
|
|
382
|
+
if (shouldAnimateTabBar) {
|
|
383
|
+
[self animateTabBarForTransitionFrom:from to:to];
|
|
384
|
+
}
|
|
329
385
|
} completion:^(id <UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
330
386
|
self.nav.poppingViewController = nil;
|
|
331
387
|
[self hbd_restoreCompensatedSafeAreaForFrom:from to:to viewController:viewController];
|
|
@@ -348,12 +404,63 @@
|
|
|
348
404
|
self.nav.navigationBar.standardAppearance.backgroundColor = UIColor.clearColor;
|
|
349
405
|
}
|
|
350
406
|
|
|
407
|
+
if (shouldAnimateTabBar) {
|
|
408
|
+
[self completeTabBarTransitionFrom:from to:to cancelled:context.isCancelled];
|
|
409
|
+
}
|
|
410
|
+
|
|
351
411
|
if (to == viewController) {
|
|
352
412
|
[self.nav clearFake];
|
|
353
413
|
}
|
|
354
414
|
}];
|
|
355
415
|
}
|
|
356
416
|
|
|
417
|
+
- (BOOL)shouldAnimateTabBarFrom:(UIViewController *)from to:(UIViewController *)to {
|
|
418
|
+
UITabBarController *tabBarController = self.nav.tabBarController;
|
|
419
|
+
if (!tabBarController) {
|
|
420
|
+
return NO;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return from.hidesBottomBarWhenPushed != to.hidesBottomBarWhenPushed;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
- (void)prepareTabBarForTransitionFrom:(UIViewController *)from to:(UIViewController *)to {
|
|
427
|
+
UITabBar *tabBar = self.nav.tabBarController.tabBar;
|
|
428
|
+
[tabBar.layer removeAllAnimations];
|
|
429
|
+
tabBar.hidden = NO;
|
|
430
|
+
|
|
431
|
+
if (from.hidesBottomBarWhenPushed && !to.hidesBottomBarWhenPushed) {
|
|
432
|
+
// iOS 26 首次交互返回时,系统会过早让 TabBar 现身;先把初始 alpha 固定住,交给 coordinator 渐变。
|
|
433
|
+
tabBar.alpha = 0.0;
|
|
434
|
+
} else if (!from.hidesBottomBarWhenPushed && to.hidesBottomBarWhenPushed) {
|
|
435
|
+
tabBar.alpha = 1.0;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
- (void)animateTabBarForTransitionFrom:(UIViewController *)from to:(UIViewController *)to {
|
|
440
|
+
UITabBar *tabBar = self.nav.tabBarController.tabBar;
|
|
441
|
+
if (from.hidesBottomBarWhenPushed && !to.hidesBottomBarWhenPushed) {
|
|
442
|
+
tabBar.alpha = 1.0;
|
|
443
|
+
} else if (!from.hidesBottomBarWhenPushed && to.hidesBottomBarWhenPushed) {
|
|
444
|
+
tabBar.alpha = 0.0;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
- (void)completeTabBarTransitionFrom:(UIViewController *)from
|
|
449
|
+
to:(UIViewController *)to
|
|
450
|
+
cancelled:(BOOL)cancelled {
|
|
451
|
+
UITabBar *tabBar = self.nav.tabBarController.tabBar;
|
|
452
|
+
[tabBar.layer removeAllAnimations];
|
|
453
|
+
|
|
454
|
+
UIViewController *visibleViewController = cancelled ? from : to;
|
|
455
|
+
if (visibleViewController.hidesBottomBarWhenPushed) {
|
|
456
|
+
tabBar.alpha = 1.0;
|
|
457
|
+
tabBar.hidden = YES;
|
|
458
|
+
} else {
|
|
459
|
+
tabBar.hidden = NO;
|
|
460
|
+
tabBar.alpha = 1.0;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
357
464
|
- (void)resetButtonLabelInNavBar:(UINavigationBar *)navBar {
|
|
358
465
|
if (@available(iOS 12.0, *)) {
|
|
359
466
|
for (UIView *view in navBar.subviews) {
|
|
@@ -22,6 +22,15 @@
|
|
|
22
22
|
NSArray *_reactViewConstraints;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
- (void)syncRootViewBackgroundColor {
|
|
26
|
+
if (!self.rootView) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
UIColor *backgroundColor = self.view.backgroundColor ?: UIColor.clearColor;
|
|
31
|
+
self.rootView.backgroundColor = backgroundColor;
|
|
32
|
+
}
|
|
33
|
+
|
|
25
34
|
- (void)dealloc {
|
|
26
35
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTBridgeWillReloadNotification object:nil];
|
|
27
36
|
RCTLogInfo(@"[Navigation] 销毁页面 %@", self.moduleName);
|
|
@@ -47,16 +56,18 @@
|
|
|
47
56
|
|
|
48
57
|
BOOL passThroughTouches = [self.options[@"passThroughTouches"] boolValue];
|
|
49
58
|
rootView.passThroughTouches = passThroughTouches;
|
|
50
|
-
rootView.backgroundColor = UIColor.clearColor;
|
|
51
59
|
rootView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
52
60
|
self.view = [[UIView alloc] init];
|
|
61
|
+
self.view.backgroundColor = [GlobalStyle globalStyle].screenBackgroundColor;
|
|
53
62
|
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
63
|
+
[self syncRootViewBackgroundColor];
|
|
54
64
|
[self.view addSubview:rootView];
|
|
55
65
|
RCTLogInfo(@"[Navigation] 加载页面 %@", self.moduleName);
|
|
56
66
|
}
|
|
57
67
|
|
|
58
68
|
- (void)viewDidLoad {
|
|
59
69
|
[super viewDidLoad];
|
|
70
|
+
[self syncRootViewBackgroundColor];
|
|
60
71
|
[self updateReactViewConstraints];
|
|
61
72
|
|
|
62
73
|
NSDictionary *titleItem = self.options[@"titleItem"];
|
|
@@ -94,15 +94,17 @@
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
- (void)adjustScreenOrientation {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
UIWindowScene *windowScene = nil;
|
|
98
|
+
if (@available(iOS 13.0, *)) {
|
|
99
|
+
windowScene = [self getWindowScene];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!self.forceScreenLandscape && windowScene != nil && windowScene.interfaceOrientation != UIInterfaceOrientationPortrait && ![[self hbd_mode] isEqual:@"modal"]) {
|
|
103
|
+
[self setScreenOrientation:UIInterfaceOrientationPortrait usingMask:UIInterfaceOrientationMaskPortrait];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (self.forceScreenLandscape) {
|
|
107
|
+
[self setScreenOrientation:UIInterfaceOrientationLandscapeRight usingMask:UIInterfaceOrientationMaskLandscape];
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
|
|
@@ -130,11 +132,19 @@
|
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
- (UIWindowScene *)getWindowScene API_AVAILABLE(ios(13.0)){
|
|
135
|
+
UIWindow *window = self.view.window ?: self.navigationController.view.window;
|
|
136
|
+
if ([window.windowScene isKindOfClass:[UIWindowScene class]]) {
|
|
137
|
+
return window.windowScene;
|
|
138
|
+
}
|
|
139
|
+
|
|
133
140
|
NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
|
|
134
141
|
for (id connectedScene in array) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
142
|
+
if ([connectedScene isKindOfClass:[UIWindowScene class]]) {
|
|
143
|
+
UIWindowScene *scene = (UIWindowScene *)connectedScene;
|
|
144
|
+
if (scene.activationState == UISceneActivationStateForegroundActive) {
|
|
145
|
+
return scene;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
138
148
|
}
|
|
139
149
|
return nil;
|
|
140
150
|
}
|
|
@@ -181,7 +191,7 @@
|
|
|
181
191
|
- (void)applyTabBarOptions:(NSDictionary *)options {
|
|
182
192
|
NSDictionary *tabItem = options[@"tabItem"];
|
|
183
193
|
if (tabItem) {
|
|
184
|
-
UITabBarItem *tabBarItem = self.tabBarItem;
|
|
194
|
+
UITabBarItem *tabBarItem = self.navigationController ? self.navigationController.tabBarItem : self.tabBarItem;
|
|
185
195
|
// title
|
|
186
196
|
tabBarItem.title = tabItem[@"title"];
|
|
187
197
|
|
|
@@ -192,19 +202,20 @@
|
|
|
192
202
|
|
|
193
203
|
NSDictionary *unselectedIcon = tabItem[@"unselectedIcon"];
|
|
194
204
|
NSDictionary *icon = tabItem[@"icon"];
|
|
195
|
-
UITabBar *appearance = [UITabBar appearance];
|
|
205
|
+
UITabBar *appearance = self.tabBarController.tabBar ?: [UITabBar appearance];
|
|
196
206
|
BOOL dot = [self showDotBadge:badge];
|
|
197
207
|
|
|
198
208
|
UITabBarItemAppearance *itemAppearance = appearance.standardAppearance.stackedLayoutAppearance;
|
|
199
209
|
if (unselectedIcon) {
|
|
200
|
-
tabBarItem.selectedImage = [[HBDUtils UIImage:icon] withIconColor:itemAppearance.selected.iconColor badgeColor:dot ? tabBarItem.badgeColor : UIColor.clearColor];
|
|
201
210
|
tabBarItem.image = [[HBDUtils UIImage:unselectedIcon] withIconColor:itemAppearance.normal.iconColor badgeColor:dot ? tabBarItem.badgeColor : UIColor.clearColor];
|
|
202
|
-
} else {
|
|
203
211
|
tabBarItem.selectedImage = [[HBDUtils UIImage:icon] withIconColor:itemAppearance.selected.iconColor badgeColor:dot ? tabBarItem.badgeColor : UIColor.clearColor];
|
|
212
|
+
} else {
|
|
204
213
|
tabBarItem.image = [[HBDUtils UIImage:icon] withIconColor:itemAppearance.normal.iconColor badgeColor:dot ? tabBarItem.badgeColor : UIColor.clearColor];
|
|
214
|
+
tabBarItem.selectedImage = [[HBDUtils UIImage:icon] withIconColor:itemAppearance.selected.iconColor badgeColor:dot ? tabBarItem.badgeColor : UIColor.clearColor];
|
|
215
|
+
}
|
|
216
|
+
if (!self.navigationController) {
|
|
217
|
+
self.tabBarItem = tabBarItem;
|
|
205
218
|
}
|
|
206
|
-
|
|
207
|
-
self.tabBarItem = tabBarItem;
|
|
208
219
|
}
|
|
209
220
|
}
|
|
210
221
|
|
|
@@ -229,10 +240,6 @@
|
|
|
229
240
|
}
|
|
230
241
|
|
|
231
242
|
[self applyTabBarOptions:self.options];
|
|
232
|
-
|
|
233
|
-
if (self.navigationController) {
|
|
234
|
-
self.navigationController.tabBarItem = self.tabBarItem;
|
|
235
|
-
}
|
|
236
243
|
}
|
|
237
244
|
|
|
238
245
|
- (BOOL)showDotBadge:(NSDictionary *)badge {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#import "UINavigationController+HBD.h"
|
|
2
2
|
|
|
3
|
+
#import <React/RCTLog.h>
|
|
4
|
+
|
|
3
5
|
@implementation UINavigationController (HBD)
|
|
4
6
|
|
|
5
7
|
- (void)redirectToViewController:(UIViewController *)controller animated:(BOOL)animated {
|
|
@@ -9,6 +11,16 @@
|
|
|
9
11
|
- (void)redirectToViewController:(UIViewController *)controller target:(UIViewController *)target animated:(BOOL)animated {
|
|
10
12
|
NSMutableArray *children = [self.childViewControllers mutableCopy];
|
|
11
13
|
NSUInteger index = [children indexOfObject:target];
|
|
14
|
+
if (index == NSNotFound) {
|
|
15
|
+
RCTLogWarn(@"[Navigation] redirectTo target is no longer in the navigation stack. Fallback to topViewController.");
|
|
16
|
+
index = [children indexOfObject:self.topViewController];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (index == NSNotFound) {
|
|
20
|
+
RCTLogWarn(@"[Navigation] redirectTo failed because the navigation stack is empty.");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
12
24
|
NSUInteger count = self.childViewControllers.count;
|
|
13
25
|
[children removeObjectsInRange:NSMakeRange(index, count - index)];
|
|
14
26
|
[children addObject:controller];
|
|
@@ -49,6 +49,14 @@
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
[self hbd_dismissViewControllerAnimated:animated completion:^{
|
|
52
|
+
if (!presented || !presenting) {
|
|
53
|
+
RCTLogWarn(@"[Navigation] dismiss completed without a valid presenting/presented controller pair.");
|
|
54
|
+
if (completion) {
|
|
55
|
+
completion();
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
52
60
|
if (![presented isKindOfClass:[UIAlertController class]]) {
|
|
53
61
|
BOOL consumed = presented.presentingSceneId && [UIViewController dispatchResult:presenting presented:presented sceneId:presented.presentingSceneId];
|
|
54
62
|
if (!consumed) {
|
|
@@ -355,4 +363,3 @@
|
|
|
355
363
|
}
|
|
356
364
|
|
|
357
365
|
@end
|
|
358
|
-
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hybrid-navigation",
|
|
3
3
|
"description": "React Native Navigation that supports seamless navigation between Native and React.",
|
|
4
|
-
"version": "3.1.
|
|
4
|
+
"version": "3.1.2",
|
|
5
5
|
"main": "./dist/index",
|
|
6
6
|
"module": "./dist/index",
|
|
7
7
|
"types": "./dist/index.d.ts",
|