hybrid-navigation 5.1.1 → 5.3.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.
Files changed (101) hide show
  1. package/README.md +9 -20
  2. package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +5 -13
  3. package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
  4. package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +0 -50
  5. package/android/src/main/java/com/navigation/androidx/TabBarItem.java +0 -4
  6. package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +0 -7
  7. package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +7 -43
  8. package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +5 -39
  9. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +62 -135
  10. package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +0 -20
  11. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +10 -21
  12. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +39 -87
  13. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +2 -16
  14. package/dist/NativeEvent.d.ts +1 -11
  15. package/dist/NativeNavigation.d.ts +7 -6
  16. package/dist/Navigation.d.ts +8 -20
  17. package/dist/Navigation.js +32 -163
  18. package/dist/NavigationComponentWrap.d.ts +3 -3
  19. package/dist/Navigator.d.ts +4 -5
  20. package/dist/Navigator.js +13 -36
  21. package/dist/Options.d.ts +2 -2
  22. package/dist/Route.d.ts +12 -33
  23. package/dist/handler/DispatchCommandHandler.d.ts +3 -17
  24. package/dist/handler/DispatchCommandHandler.js +17 -62
  25. package/dist/handler/LayoutCommandHandler.d.ts +2 -3
  26. package/dist/handler/LayoutCommandHandler.js +0 -3
  27. package/dist/handler/LeaveGuardHandler.d.ts +2 -2
  28. package/dist/handler/LeaveGuardHandler.js +88 -46
  29. package/dist/handler/LifecycleEventHandler.d.ts +2 -14
  30. package/dist/handler/LifecycleEventHandler.js +2 -79
  31. package/dist/handler/ResultEventHandler.d.ts +0 -1
  32. package/dist/handler/ResultEventHandler.js +0 -3
  33. package/dist/handler/SceneExitHandler.d.ts +3 -0
  34. package/dist/handler/SceneExitHandler.js +76 -0
  35. package/dist/hooks.d.ts +2 -2
  36. package/dist/hooks.js +39 -22
  37. package/dist/index.d.ts +1 -12
  38. package/dist/index.js +0 -3
  39. package/dist/router/index.d.ts +0 -1
  40. package/dist/router/index.js +43 -11
  41. package/dist/sceneCoverage.d.ts +2 -0
  42. package/dist/sceneCoverage.js +25 -0
  43. package/dist/store.d.ts +0 -2
  44. package/dist/store.js +0 -4
  45. package/ios/HBDGlobalStyle.h +0 -1
  46. package/ios/HBDGlobalStyle.mm +0 -7
  47. package/ios/HybridNavigation.h +0 -1
  48. package/ios/Navigator/HBDScreenNavigator.mm +89 -237
  49. package/ios/Navigator/HBDStackNavigator.mm +1 -1
  50. package/ios/Navigator/HBDTabNavigator.mm +15 -30
  51. package/ios/React/HBDNativeNavigation.mm +4 -31
  52. package/ios/React/HBDReactBridgeManager.h +0 -5
  53. package/ios/React/HBDReactBridgeManager.mm +0 -17
  54. package/ios/ViewController/HBDReactViewController.h +1 -1
  55. package/ios/ViewController/HBDReactViewController.mm +34 -9
  56. package/ios/ViewController/HBDTabBarController.h +2 -11
  57. package/ios/ViewController/HBDTabBarController.mm +14 -170
  58. package/ios/ViewController/HBDViewController.h +0 -1
  59. package/ios/ViewController/HBDViewController.mm +9 -57
  60. package/ios/ViewController/UIViewController+HBD.h +2 -0
  61. package/ios/ViewController/UIViewController+HBD.mm +5 -0
  62. package/package.json +1 -3
  63. package/src/NativeEvent.ts +1 -12
  64. package/src/NativeNavigation.ts +8 -7
  65. package/src/Navigation.ts +49 -257
  66. package/src/NavigationComponentWrap.tsx +3 -11
  67. package/src/Navigator.ts +15 -45
  68. package/src/Options.ts +2 -3
  69. package/src/Route.ts +17 -54
  70. package/src/handler/DispatchCommandHandler.ts +29 -109
  71. package/src/handler/LayoutCommandHandler.ts +2 -6
  72. package/src/handler/LeaveGuardHandler.ts +97 -46
  73. package/src/handler/LifecycleEventHandler.ts +22 -122
  74. package/src/handler/ResultEventHandler.ts +0 -6
  75. package/src/handler/SceneExitHandler.ts +86 -0
  76. package/src/hooks.ts +39 -22
  77. package/src/index.ts +0 -14
  78. package/src/router/index.ts +45 -12
  79. package/src/sceneCoverage.ts +30 -0
  80. package/src/store.ts +0 -5
  81. package/dist/defineRoutes.d.ts +0 -19
  82. package/dist/defineRoutes.js +0 -6
  83. package/dist/handler/PresentationCoordinator.d.ts +0 -24
  84. package/dist/handler/PresentationCoordinator.js +0 -456
  85. package/dist/handler/TabEventHandler.d.ts +0 -8
  86. package/dist/handler/TabEventHandler.js +0 -25
  87. package/dist/reveal.d.ts +0 -46
  88. package/dist/reveal.js +0 -431
  89. package/dist/routeGraph.d.ts +0 -12
  90. package/dist/routeGraph.js +0 -68
  91. package/dist/testing.d.ts +0 -79
  92. package/dist/testing.js +0 -251
  93. package/ios/ViewController/HBDTabBarRenderer.h +0 -28
  94. package/src/defineRoutes.ts +0 -46
  95. package/src/handler/PresentationCoordinator.ts +0 -566
  96. package/src/handler/TabEventHandler.ts +0 -31
  97. package/src/reveal.ts +0 -565
  98. package/src/routeGraph.ts +0 -87
  99. package/src/testing.ts +0 -395
  100. package/testing.d.ts +0 -1
  101. package/testing.js +0 -3
@@ -15,6 +15,7 @@
15
15
  @property(nonatomic, strong, readwrite) HBDRootView *rootView;
16
16
  @property(nonatomic, copy, nullable) dispatch_block_t pushPrewarmCompletion;
17
17
  @property(nonatomic, assign) NSUInteger pushPrewarmGeneration;
18
+ @property(nonatomic, assign) BOOL hostingPrewarmedRoot;
18
19
 
19
20
  @end
20
21
 
@@ -30,6 +31,9 @@
30
31
  }
31
32
 
32
33
  - (void)dealloc {
34
+ if (_hostingPrewarmedRoot) {
35
+ [_rootView removeFromSuperview];
36
+ }
33
37
  [[HBDReactBridgeManager get] unregisterPrewarmingViewController:self];
34
38
  [[NSNotificationCenter defaultCenter] removeObserver:self name:HBDReactBridgeWillReloadNotification object:nil];
35
39
  RCTLogInfo(@"[Navigation] 销毁页面 %@", self.moduleName);
@@ -82,6 +86,21 @@
82
86
  RCTLogInfo(@"[Navigation] 加载页面 %@", self.moduleName);
83
87
  }
84
88
 
89
+ - (void)viewIsAppearing:(BOOL)animated {
90
+ [super viewIsAppearing:animated];
91
+ [self restorePrewarmedRoot];
92
+ }
93
+
94
+ - (void)restorePrewarmedRoot {
95
+ if (!self.hostingPrewarmedRoot) {
96
+ return;
97
+ }
98
+ self.hostingPrewarmedRoot = NO;
99
+ [self.view addSubview:self.rootView];
100
+ self.rootView.frame = self.view.bounds;
101
+ self.rootView.hidden = NO;
102
+ }
103
+
85
104
  - (void)viewDidLoad {
86
105
  [super viewDidLoad];
87
106
  [self syncRootViewBackgroundColor];
@@ -103,14 +122,14 @@
103
122
 
104
123
  - (void)updateReactViewFrame {
105
124
  if (self.isViewLoaded && self.rootView) {
106
- CGRect targetFrame = self.view.bounds;
125
+ CGRect targetFrame = self.rootView.superview.bounds;
107
126
  if (!CGRectEqualToRect(self.rootView.frame, targetFrame)) {
108
127
  [self.rootView setFrame:targetFrame];
109
128
  }
110
129
  }
111
130
  }
112
131
 
113
- - (NSDictionary *)propsWithSceneId {
132
+ - (NSMutableDictionary *)propsWithSceneId {
114
133
  NSMutableDictionary *props;
115
134
  if (self.props) {
116
135
  props = [self.props mutableCopy];
@@ -122,7 +141,7 @@
122
141
  }
123
142
 
124
143
  - (NSDictionary *)initialPropertiesForSurface {
125
- NSMutableDictionary *props = [[self propsWithSceneId] mutableCopy];
144
+ NSMutableDictionary *props = [self propsWithSceneId];
126
145
  if (props[@"initialMetrics"] == nil && [self hbd_globalStyle].injectInitialMetrics) {
127
146
  NSDictionary *initialMetrics = [self buildInitialMetrics];
128
147
  if (initialMetrics) {
@@ -155,7 +174,7 @@
155
174
  }
156
175
 
157
176
  - (BOOL)canUseCurrentWindowGeometry {
158
- // Tab 根页与 Drawer 侧栏容器不按全屏窗口几何预热或注入,避免与 TabBar / 非全屏尺寸产生首帧偏差。
177
+ // Tab 根页与 Drawer 侧栏容器不按全屏窗口几何预热,避免与 TabBar / 非全屏尺寸产生首帧偏差。
159
178
  if (self.tabBarController != nil || self.options[@"tabItem"] != nil || [self isInsideDrawerMenu]) {
160
179
  return NO;
161
180
  }
@@ -197,7 +216,9 @@
197
216
  }
198
217
 
199
218
  UIWindow *window = [[HBDOrientationCoordinator shared] windowForViewController:self];
200
- if (!window) {
219
+ UIView *container = self.parentViewController.viewIfLoaded;
220
+ if (!window || CGRectIsEmpty(window.bounds) || window.hidden ||
221
+ (container && (container.window != window || !CGRectEqualToRect([container convertRect:container.bounds toView:window], window.bounds)))) {
201
222
  return nil;
202
223
  }
203
224
 
@@ -226,8 +247,8 @@
226
247
  }
227
248
  }
228
249
 
229
- - (BOOL)prepareForAnimatedPushWithBounds:(CGRect)bounds timeout:(NSTimeInterval)timeout completion:(dispatch_block_t)completion {
230
- if (![self hbd_globalStyle].prewarmPush || !completion || CGRectIsEmpty(bounds) || ![self canUseCurrentWindowGeometry]) {
250
+ - (BOOL)prepareForAnimatedPushInView:(UIView *)hostView timeout:(NSTimeInterval)timeout completion:(dispatch_block_t)completion {
251
+ if (![self hbd_globalStyle].prewarmPush || !completion || !hostView.window || CGRectIsEmpty(hostView.bounds) || ![self canUseCurrentWindowGeometry]) {
231
252
  return NO;
232
253
  }
233
254
 
@@ -237,9 +258,12 @@
237
258
 
238
259
  [[HBDReactBridgeManager get] registerPrewarmingViewController:self];
239
260
 
240
- // 提前加载并给 HBDRootView 真实尺寸,让 Fabric 在离屏阶段完成首帧挂载,避免右滑入场前半段空白。
261
+ // Keep UIKit's window geometry available to Fabric descendants during prewarm.
262
+ // The controller itself enters the hierarchy only when UIKit performs the push.
241
263
  [self loadViewIfNeeded];
242
- self.view.frame = bounds;
264
+ self.hostingPrewarmedRoot = YES;
265
+ self.rootView.hidden = YES;
266
+ [hostView insertSubview:self.rootView atIndex:0];
243
267
  [self updateReactViewFrame];
244
268
  [self.view layoutIfNeeded];
245
269
  [self.rootView layoutIfNeeded];
@@ -282,6 +306,7 @@
282
306
  }
283
307
 
284
308
  - (void)cancelPushPrewarm {
309
+ [self restorePrewarmedRoot];
285
310
  self.pushPrewarmCompletion = nil;
286
311
  self.pushPrewarmGeneration += 1;
287
312
  [[HBDReactBridgeManager get] unregisterPrewarmingViewController:self];
@@ -1,24 +1,15 @@
1
1
  #import <UIKit/UIKit.h>
2
- #import "HBDTabBarRenderer.h"
3
2
 
4
3
  @class HBDGlobalStyle;
5
4
 
6
- NS_ASSUME_NONNULL_BEGIN
7
-
8
5
  @interface HBDTabBarController : UITabBarController
9
6
 
10
- @property(nonatomic, strong, nullable) id<HBDTabBarRenderer> tabBarRenderer;
11
-
12
7
  - (void)applyGlobalStyle:(HBDGlobalStyle *)style;
13
8
 
14
9
  - (void)updateTabBar:(NSDictionary *)options;
15
10
 
16
- - (void)setTabItem:(NSArray<NSDictionary *> *)options;
17
-
18
- - (NSArray<NSString *> *)tabKeys;
11
+ - (NSArray *)tabKeys;
19
12
 
20
- - (NSInteger)indexForTabKey:(NSString *)tabKey;
13
+ - (void)setTabItem:(NSArray<NSDictionary *> *)options;
21
14
 
22
15
  @end
23
-
24
- NS_ASSUME_NONNULL_END
@@ -2,8 +2,6 @@
2
2
 
3
3
  #import "HBDFadeAnimation.h"
4
4
  #import "HBDGlobalStyle.h"
5
- #import "HBDNativeEvent.h"
6
- #import "HBDReactBridgeManager.h"
7
5
  #import "HBDReactViewController.h"
8
6
  #import "HBDUtils.h"
9
7
  #import "UIViewController+HBD.h"
@@ -12,9 +10,6 @@
12
10
 
13
11
  @interface HBDTabBarController () <UITabBarControllerDelegate>
14
12
 
15
- @property(nonatomic, assign) BOOL rendererAttached;
16
- @property(nonatomic, assign) NSUInteger pendingPreviousSelectedIndex;
17
-
18
13
  @end
19
14
 
20
15
  @implementation HBDTabBarController
@@ -36,124 +31,6 @@
36
31
  self.definesPresentationContext = NO;
37
32
  self.delegate = self;
38
33
  [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;
157
34
  }
158
35
 
159
36
  - (void)applyGlobalStyle:(HBDGlobalStyle *)style {
@@ -165,25 +42,29 @@
165
42
  HBDViewController *hbdvc = [self tabViewController:tab];
166
43
  [hbdvc applyTabBarOptions:hbdvc.options];
167
44
  }
168
- [self reloadRendererAnimated:NO];
45
+ }
46
+
47
+ - (NSArray *)tabKeys {
48
+ NSMutableArray *keys = [NSMutableArray arrayWithCapacity:self.viewControllers.count];
49
+ for (UIViewController *tab in self.viewControllers) {
50
+ NSDictionary *item = [self tabViewController:tab].options[@"tabItem"];
51
+ NSString *key = [item isKindOfClass:NSDictionary.class] ? item[@"key"] : nil;
52
+ [keys addObject:([key isKindOfClass:NSString.class] && key.length) ? key : NSNull.null];
53
+ }
54
+ return keys;
169
55
  }
170
56
 
171
57
  - (void)setTabItem:(NSArray<NSDictionary *> *)options {
172
58
  for (NSDictionary *option in options) {
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) {
59
+ NSUInteger index = [option[@"index"] isKindOfClass:NSNumber.class]
60
+ ? [option[@"index"] unsignedIntegerValue] : [[self tabKeys] indexOfObject:option[@"key"] ?: @""];
61
+ if (index >= self.viewControllers.count) {
180
62
  continue;
181
63
  }
182
- UIViewController *tab = self.viewControllers[(NSUInteger)resolvedIndex];
64
+ UIViewController *tab = self.viewControllers[index];
183
65
  HBDViewController *hbdvc = [self tabViewController:tab];
184
66
  [hbdvc updateTabBarItem:option];
185
67
  }
186
- [self reloadRendererAnimated:NO];
187
68
  }
188
69
 
189
70
  - (HBDViewController *)tabViewController:(UIViewController *)vc {
@@ -246,10 +127,6 @@
246
127
  HBDViewController *hbdvc = [self tabViewController:tab];
247
128
  [hbdvc applyTabBarOptions:hbdvc.options];
248
129
  }
249
- if ([self.tabBarRenderer respondsToSelector:@selector(updateTabBarStyle:)]) {
250
- [self.tabBarRenderer updateTabBarStyle:options];
251
- }
252
- [self reloadRendererAnimated:NO];
253
130
  }
254
131
 
255
132
  - (void)hbd_didReceiveResultCode:(NSInteger)resultCode resultData:(NSDictionary *)data requestCode:(NSInteger)requestCode {
@@ -262,43 +139,10 @@
262
139
  }
263
140
  }
264
141
 
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
-
290
142
  - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
291
- self.pendingPreviousSelectedIndex = self.selectedIndex;
292
143
  return YES;
293
144
  }
294
145
 
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
-
302
146
  - (id<UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController animationControllerForTransitionFromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC {
303
147
  if (toVC.viewLoaded) {
304
148
  return nil;
@@ -11,7 +11,6 @@
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;
15
14
  @property(nonatomic, strong, readonly) HBDSceneLifecycleStateMachine *lifecycleStateMachine;
16
15
 
17
16
  - (instancetype)initWithModuleName:(NSString *)moduleName props:(NSDictionary *)props options:(NSDictionary *)options NS_DESIGNATED_INITIALIZER;
@@ -9,45 +9,19 @@
9
9
 
10
10
  #import <React/RCTLog.h>
11
11
 
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
- ) {
12
+ static void HBDEmitSceneStateChange(NSString *sceneId, HBDSceneLifecycleState prevState, HBDSceneLifecycleState newState) {
29
13
  if (sceneId.length == 0) {
30
14
  return;
31
15
  }
32
- NSMutableDictionary *payload = [@{
16
+ NSDictionary *payload = @{
33
17
  @"sceneId": sceneId,
34
18
  @"state": HBDSceneLifecycleStateToString(newState),
35
19
  @"prevState": HBDSceneLifecycleStateToString(prevState),
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];
20
+ };
47
21
  dispatch_block_t emitBlock = ^{
48
22
  HBDNativeEvent *event = [HBDNativeEvent getInstance];
49
23
  if (event) {
50
- [event emitOnSceneStateChange:immutablePayload];
24
+ [event emitOnSceneStateChange:payload];
51
25
  }
52
26
  };
53
27
  if ([NSThread isMainThread]) {
@@ -72,14 +46,11 @@ static void HBDEmitSceneStateChange(
72
46
  HBDSceneLifecycleState prevState = self.lifecycleStateMachine.state;
73
47
  if (prevState != HBDSceneLifecycleStateDestroyed) {
74
48
  NSString *sceneId = self.hbd_sceneId;
75
- NSString *moduleName = self.moduleName;
76
- NSString *mode = [self hbd_mode];
77
- NSString *presentingId = HBDResolvePresentingSceneId(self);
78
49
  if (prevState == HBDSceneLifecycleStateVisible) {
79
- HBDEmitSceneStateChange(sceneId, HBDSceneLifecycleStateVisible, HBDSceneLifecycleStateInvisible, moduleName, mode, presentingId);
50
+ HBDEmitSceneStateChange(sceneId, HBDSceneLifecycleStateVisible, HBDSceneLifecycleStateInvisible);
80
51
  prevState = HBDSceneLifecycleStateInvisible;
81
52
  }
82
- HBDEmitSceneStateChange(sceneId, prevState, HBDSceneLifecycleStateDestroyed, moduleName, mode, presentingId);
53
+ HBDEmitSceneStateChange(sceneId, prevState, HBDSceneLifecycleStateDestroyed);
83
54
  [self.lifecycleStateMachine markDestroyed];
84
55
  }
85
56
  }
@@ -121,31 +92,13 @@ static void HBDEmitSceneStateChange(
121
92
  return HBDScreenOrientationFromString(self.options[@"orientation"]);
122
93
  }
123
94
 
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
-
135
95
  - (BOOL)isNativeManagedLifecycle {
136
96
  return YES;
137
97
  }
138
98
 
139
99
  - (void)sceneLifecycleDidChangeFromState:(HBDSceneLifecycleState)prevState toState:(HBDSceneLifecycleState)newState {
140
100
  if ([HBDReactBridgeManager get].isReactModuleRegisterCompleted || newState == HBDSceneLifecycleStateDestroyed) {
141
- HBDEmitSceneStateChange(
142
- self.hbd_sceneId,
143
- prevState,
144
- newState,
145
- self.moduleName,
146
- [self hbd_mode],
147
- HBDResolvePresentingSceneId(self)
148
- );
101
+ HBDEmitSceneStateChange(self.hbd_sceneId, prevState, newState);
149
102
  }
150
103
  }
151
104
 
@@ -185,8 +138,7 @@ static void HBDEmitSceneStateChange(
185
138
 
186
139
  - (void)viewWillDisappear:(BOOL)animated {
187
140
  [super viewWillDisappear:animated];
188
- id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator ?: self.navigationController.transitionCoordinator;
189
- BOOL interactive = coordinator.interactive;
141
+ BOOL interactive = self.transitionCoordinator.interactive || self.navigationController.transitionCoordinator.interactive;
190
142
  [self.lifecycleStateMachine viewWillDisappearWithInteractiveTransition:interactive];
191
143
  }
192
144
 
@@ -224,7 +176,7 @@ static void HBDEmitSceneStateChange(
224
176
  }
225
177
 
226
178
  - (void)setModalBackgroundColor {
227
- self.view.backgroundColor = [self hbd_globalStyle].modalBackgroundColor ?: UIColor.clearColor;
179
+ self.view.backgroundColor = UIColor.clearColor;
228
180
 
229
181
  NSString *screenColor = self.options[@"screenBackgroundColor"];
230
182
 
@@ -21,6 +21,8 @@ NS_ASSUME_NONNULL_BEGIN
21
21
 
22
22
  - (BOOL)hbd_canPresentViewController;
23
23
 
24
+ - (void)hbd_setLocalResultCode:(NSInteger)resultCode resultData:(nullable NSDictionary *)data;
25
+
24
26
  - (void)hbd_setResultCode:(NSInteger)resultCode resultData:(nullable NSDictionary *)data;
25
27
 
26
28
  - (void)hbd_didReceiveResultCode:(NSInteger)resultCode resultData:(nullable NSDictionary *)data requestCode:(NSInteger)requestCode;
@@ -194,6 +194,11 @@ static BOOL HBDIsManagedViewController(UIViewController * _Nullable vc) {
194
194
  return [code integerValue];
195
195
  }
196
196
 
197
+ - (void)hbd_setLocalResultCode:(NSInteger)resultCode resultData:(NSDictionary *)data {
198
+ objc_setAssociatedObject(self, @selector(hbd_resultCode), @(resultCode), OBJC_ASSOCIATION_COPY_NONATOMIC);
199
+ objc_setAssociatedObject(self, @selector(hbd_resultData), data, OBJC_ASSOCIATION_COPY_NONATOMIC);
200
+ }
201
+
197
202
  - (void)hbd_setResultCode:(NSInteger)resultCode resultData:(NSDictionary *)data {
198
203
  self.hbd_resultCode = resultCode;
199
204
  self.hbd_resultData = data;
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": "5.1.1",
4
+ "version": "5.3.0",
5
5
  "main": "./dist/index",
6
6
  "module": "./dist/index",
7
7
  "types": "./dist/index.d.ts",
@@ -11,8 +11,6 @@
11
11
  "files": [
12
12
  "src",
13
13
  "dist",
14
- "testing.js",
15
- "testing.d.ts",
16
14
  "android",
17
15
  "ios",
18
16
  "HybridNavigation.podspec",
@@ -5,9 +5,6 @@ export type SceneStateChangeEvent = {
5
5
  sceneId: string;
6
6
  state: string;
7
7
  prevState: string;
8
- moduleName?: string;
9
- mode?: string;
10
- presentingId?: string;
11
8
  };
12
9
 
13
10
  export type ResultEvent = {
@@ -22,20 +19,12 @@ export type BeforeRemoveRequestEvent = {
22
19
  action: string;
23
20
  };
24
21
 
25
- export type TabPressEventWire = {
26
- index: number;
27
- tabKey?: string;
28
- previousIndex: number;
29
- reselected: boolean;
30
- };
31
-
32
22
  export interface Spec extends TurboModule {
23
+ readonly onBeforeRemoveRequest: CodegenTypes.EventEmitter<BeforeRemoveRequestEvent>;
33
24
  readonly onResult: CodegenTypes.EventEmitter<ResultEvent>;
34
25
  readonly willSetRoot: CodegenTypes.EventEmitter<void>;
35
26
  readonly didSetRoot: CodegenTypes.EventEmitter<void>;
36
27
  readonly onSceneStateChange: CodegenTypes.EventEmitter<SceneStateChangeEvent>;
37
- readonly onBeforeRemoveRequest: CodegenTypes.EventEmitter<BeforeRemoveRequestEvent>;
38
- readonly onTabPress: CodegenTypes.EventEmitter<TabPressEventWire>;
39
28
  }
40
29
 
41
30
  export default TurboModuleRegistry.getEnforcing<Spec>('HBDNativeEvent');
@@ -18,6 +18,12 @@ export interface Route {
18
18
  requestCode: number;
19
19
  }
20
20
 
21
+ export interface NavigationSnapshot {
22
+ rootGeneration: number;
23
+ currentRoute: Route | null;
24
+ layers: RouteGraph[];
25
+ }
26
+
21
27
  export interface RouteGraph {
22
28
  layout: string;
23
29
  sceneId: string;
@@ -25,12 +31,6 @@ export interface RouteGraph {
25
31
  children?: RouteGraph[];
26
32
  }
27
33
 
28
- export interface NavigationSnapshot {
29
- rootGeneration: number;
30
- currentRoute: Route | null;
31
- layers: RouteGraph[];
32
- }
33
-
34
34
  export interface Spec extends TurboModule {
35
35
  getConstants: () => {
36
36
  RESULT_OK: number;
@@ -57,12 +57,13 @@ export interface Spec extends TurboModule {
57
57
  isStackRoot: (sceneId: string) => Promise<boolean>;
58
58
  findSceneIdByModuleName: (moduleName: string) => Promise<string | null>;
59
59
  currentRoute: () => Promise<Route | null>;
60
+ /** @deprecated Use navigationSnapshot() and read its layers. */
60
61
  routeGraph: () => Promise<RouteGraph[]>;
61
62
  navigationSnapshot: () => Promise<NavigationSnapshot>;
62
63
 
64
+ setBeforeRemoveEnabled: (sceneId: string, enabled: boolean) => void;
63
65
  setDefaultOptions: (options: CodegenTypes.UnsafeObject) => void;
64
66
  updateOptions: (sceneId: string, options: CodegenTypes.UnsafeObject) => void;
65
- setBeforeRemoveEnabled: (sceneId: string, enabled: boolean) => void;
66
67
  updateTabBar: (sceneId: string, item: CodegenTypes.UnsafeObject) => void;
67
68
  setTabItem: (sceneId: string, items: Array<CodegenTypes.UnsafeObject>) => void;
68
69
  }