hybrid-navigation 2.13.1 → 2.13.4

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 (48) hide show
  1. package/README.md +4 -4
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +1 -1
  4. package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +1 -1
  5. package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +1 -1
  6. package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +1 -1
  7. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +10 -11
  8. package/android/src/main/java/com/reactnative/hybridnavigation/NavigatorRegistry.java +0 -2
  9. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +32 -64
  10. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +1 -1
  11. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +8 -8
  12. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +1 -1
  13. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFrameLayout.java +1 -1
  14. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +1 -1
  15. package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +1 -1
  16. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +1 -2
  17. package/ios/HybridNavigation/HBDUtils.m +3 -3
  18. package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +2 -2
  19. package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +5 -5
  20. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +8 -8
  21. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +22 -15
  22. package/ios/HybridNavigation/ReactBridge/HBDReactBridgeManager.h +2 -3
  23. package/ios/HybridNavigation/ReactBridge/HBDReactBridgeManager.m +35 -29
  24. package/ios/HybridNavigation/ViewController/HBDNavigationController.m +2 -2
  25. package/ios/HybridNavigation/ViewController/HBDViewController.m +1 -1
  26. package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +1 -1
  27. package/lib/Event.d.ts +0 -2
  28. package/lib/Event.js +0 -9
  29. package/lib/GardenModule.d.ts +4 -0
  30. package/lib/GardenModule.js +19 -1
  31. package/lib/Navigation.d.ts +1 -1
  32. package/lib/NavigationModule.d.ts +1 -1
  33. package/lib/NavigationModule.js +6 -2
  34. package/lib/Navigator.js +10 -8
  35. package/lib/handler/LayoutCommandHandler.d.ts +1 -3
  36. package/lib/handler/LayoutCommandHandler.js +2 -19
  37. package/lib/index.d.ts +2 -5
  38. package/lib/index.js +3 -22
  39. package/package.json +1 -1
  40. package/src/Event.ts +0 -11
  41. package/src/GardenModule.ts +27 -1
  42. package/src/NavigationComponentWrap.tsx +0 -2
  43. package/src/NavigationModule.ts +7 -3
  44. package/src/Navigator.ts +10 -8
  45. package/src/handler/LayoutCommandHandler.ts +2 -22
  46. package/src/hooks.ts +0 -1
  47. package/src/index.ts +3 -31
  48. package/src/router/index.ts +0 -2
@@ -28,7 +28,7 @@ RCT_EXPORT_MODULE(NavigationModule)
28
28
  }
29
29
 
30
30
  - (void)invalidate {
31
- RCTLogInfo(@"[Navigator] NavigationModule#invalidate");
31
+ RCTLogInfo(@"[Navigation] NavigationModule#invalidate");
32
32
  [NSObject cancelPreviousPerformRequestsWithTarget:self];
33
33
  [[HBDAnimationObserver sharedObserver] invalidate];
34
34
  [self.bridgeManager invalidate];
@@ -58,27 +58,34 @@ RCT_EXPORT_METHOD(registerReactComponent:(NSString *)appKey options:(NSDictionar
58
58
  }
59
59
 
60
60
  RCT_EXPORT_METHOD(signalFirstRenderComplete:(NSString *) sceneId) {
61
- // RCTLogInfo(@"[Navigator] signalFirstRenderComplete sceneId:%@", sceneId);
62
- UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
61
+ // RCTLogInfo(@"[Navigation] signalFirstRenderComplete sceneId:%@", sceneId);
62
+ UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
63
63
  if ([vc isKindOfClass:[HBDReactViewController class]]) {
64
64
  [(HBDReactViewController *)vc signalFirstRenderComplete];
65
65
  }
66
66
  }
67
67
 
68
- RCT_EXPORT_METHOD(setRoot:(NSDictionary *)layout sticky:(BOOL)sticky tag:(NSNumber *__nonnull)tag) {
68
+ RCT_EXPORT_METHOD(setRoot:(NSDictionary *)layout sticky:(BOOL)sticky callback:(RCTResponseSenderBlock)callback) {
69
69
  self.bridgeManager.viewHierarchyReady = NO;
70
70
  UIViewController *vc = [self.bridgeManager viewControllerWithLayout:layout];
71
- if (vc) {
72
- self.bridgeManager.hasRootLayout = YES;
73
- [self.bridgeManager setRootViewController:vc withTag:tag];
71
+ if (!vc) {
72
+ @throw [[NSException alloc] initWithName:@"IllegalArgumentsException" reason:@"无法创建 ViewController" userInfo:@{ @"layout": layout }];
73
+ }
74
+
75
+ if (self.bridgeManager.didSetRoot) {
76
+ self.bridgeManager.didSetRoot(@[NSNull.null, @NO]);
74
77
  }
78
+ self.bridgeManager.didSetRoot = callback;
79
+ self.bridgeManager.hasRootLayout = YES;
80
+
81
+ [self.bridgeManager setRootViewController:vc];
75
82
  }
76
83
 
77
84
  RCT_EXPORT_METHOD(dispatch:(NSString *)sceneId action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback) {
78
- UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
85
+ UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
79
86
  if (!vc) {
80
87
  callback(@[NSNull.null, @NO]);
81
- RCTLogWarn(@"[Navigator] Can't find target scene for action: %@, maybe the scene is gone. \nextras: %@", action, extras);
88
+ RCTLogWarn(@"[Navigation] Can't find target scene for action: %@, maybe the scene is gone. \nextras: %@", action, extras);
82
89
  return;
83
90
  }
84
91
 
@@ -86,7 +93,7 @@ RCT_EXPORT_METHOD(dispatch:(NSString *)sceneId action:(NSString *)action extras:
86
93
  }
87
94
 
88
95
  RCT_EXPORT_METHOD(currentTab:(NSString *)sceneId callback:(RCTResponseSenderBlock)callback) {
89
- UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
96
+ UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
90
97
  UITabBarController *tabs = vc.tabBarController;
91
98
  if (tabs) {
92
99
  callback(@[NSNull.null, @(tabs.selectedIndex)]);
@@ -96,7 +103,7 @@ RCT_EXPORT_METHOD(currentTab:(NSString *)sceneId callback:(RCTResponseSenderBloc
96
103
  }
97
104
 
98
105
  RCT_EXPORT_METHOD(isStackRoot:(NSString *)sceneId callback:(RCTResponseSenderBlock)callback) {
99
- UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
106
+ UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
100
107
  UINavigationController *nav = vc.navigationController;
101
108
  if (!nav) {
102
109
  callback(@[NSNull.null, @NO]);
@@ -119,7 +126,7 @@ RCT_EXPORT_METHOD(isStackRoot:(NSString *)sceneId callback:(RCTResponseSenderBlo
119
126
  }
120
127
 
121
128
  RCT_EXPORT_METHOD(setResult:(NSString *)sceneId resultCode:(NSInteger)resultCode data:(NSDictionary *)data) {
122
- UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
129
+ UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
123
130
  [vc setResultCode:resultCode resultData:data];
124
131
  }
125
132
 
@@ -141,12 +148,12 @@ RCT_EXPORT_METHOD(findSceneIdByModuleName:(NSString *)moduleName callback:(RCTRe
141
148
 
142
149
  NSString *sceneId = [self findSceneIdByModuleName:moduleName];
143
150
  if (sceneId == nil) {
144
- RCTLogInfo(@"[Navigator] Can't find sceneId by : %@", moduleName);
151
+ RCTLogInfo(@"[Navigation] Can't find sceneId by : %@", moduleName);
145
152
  callback(@[NSNull.null, NSNull.null]);
146
153
  return;
147
154
  }
148
155
 
149
- RCTLogInfo(@"[Navigator] The sceneId found by %@ : %@", moduleName, sceneId);
156
+ RCTLogInfo(@"[Navigation] The sceneId found by %@ : %@", moduleName, sceneId);
150
157
  callback(@[[NSNull null], sceneId]);
151
158
  }
152
159
 
@@ -158,7 +165,7 @@ RCT_EXPORT_METHOD(findSceneIdByModuleName:(NSString *)moduleName callback:(RCTRe
158
165
  UIWindow *window = application.windows[i];
159
166
  NSString *sceneId = [self findSceneIdByModuleName:moduleName withViewController:window.rootViewController];
160
167
  if (sceneId != nil) {
161
- RCTLogInfo(@"[Navigator] The sceneId found by %@ : %@", moduleName, sceneId);
168
+ RCTLogInfo(@"[Navigation] The sceneId found by %@ : %@", moduleName, sceneId);
162
169
  return sceneId;
163
170
  }
164
171
  }
@@ -23,6 +23,7 @@ extern const NSInteger ResultCancel;
23
23
  @property(nonatomic, assign, readonly, getter=isReactModuleRegisterCompleted) BOOL reactModuleRegisterCompleted;
24
24
  @property(nonatomic, assign, getter=isViewHierarchyReady) BOOL viewHierarchyReady;
25
25
  @property(nonatomic, assign) BOOL hasRootLayout;
26
+ @property(nonatomic, copy) RCTResponseSenderBlock didSetRoot;
26
27
 
27
28
  - (void)installWithBridge:(RCTBridge *)bridge;
28
29
 
@@ -46,12 +47,10 @@ extern const NSInteger ResultCancel;
46
47
 
47
48
  - (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout;
48
49
 
49
- - (UIViewController *)viewControllerWithSceneId:(NSString *)sceneId;
50
+ - (UIViewController *)viewControllerBySceneId:(NSString *)sceneId;
50
51
 
51
52
  - (void)setRootViewController:(UIViewController *)rootViewController;
52
53
 
53
- - (void)setRootViewController:(UIViewController *)rootViewController withTag:(NSNumber *)tag;
54
-
55
54
  - (NSArray *)routeGraph;
56
55
 
57
56
  - (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc;
@@ -53,7 +53,7 @@ const NSInteger ResultCancel = 0;
53
53
  }
54
54
 
55
55
  - (void)invalidate {
56
- RCTLogInfo(@"[Navigator] HBDReactBridgeManager#invalidate");
56
+ RCTLogInfo(@"[Navigation] HBDReactBridgeManager#invalidate");
57
57
  [NSObject cancelPreviousPerformRequestsWithTarget:self];
58
58
 
59
59
  NSArray<id <HBDNavigator>> *navigators = [self.navigatorRegistry allNavigators];
@@ -63,6 +63,7 @@ const NSInteger ResultCancel = 0;
63
63
 
64
64
  self.viewHierarchyReady = NO;
65
65
  self.reactModuleRegisterCompleted = NO;
66
+ self.didSetRoot = NULL;
66
67
 
67
68
  UIWindow *mainWindow = [self mainWindow];
68
69
  UIViewController *presentedViewController = mainWindow.rootViewController.presentedViewController;
@@ -155,7 +156,7 @@ const NSInteger ResultCancel = 0;
155
156
  UIViewController *vc = [self createViewControllerWithLayout:layout];
156
157
 
157
158
  if (!vc) {
158
- RCTLogError(@"[Navigator] Can't find a navigator that can handle layout '%@'. Did you forget to register?", layout);
159
+ RCTLogError(@"[Navigation] Can't find a navigator that can handle layout '%@'. Did you forget to register?", layout);
159
160
  return nil;
160
161
  }
161
162
 
@@ -186,13 +187,13 @@ const NSInteger ResultCancel = 0;
186
187
  }
187
188
  }
188
189
 
189
- - (UIViewController *)viewControllerWithSceneId:(NSString *)sceneId {
190
- if (!self.viewHierarchyReady) {
191
- return nil;
190
+ - (UIViewController *)viewControllerBySceneId:(NSString *)sceneId {
191
+ if (self.viewHierarchyReady) {
192
+ UIWindow *window = [self mainWindow];
193
+ return [self viewControllerWithSceneId:sceneId viewController:window.rootViewController];
192
194
  }
193
195
 
194
- UIWindow *window = [self mainWindow];
195
- return [self viewControllerWithSceneId:sceneId viewController:window.rootViewController];
196
+ return nil;
196
197
  }
197
198
 
198
199
  - (UIViewController *)viewControllerWithSceneId:(NSString *)sceneId viewController:(UIViewController *)vc {
@@ -224,24 +225,19 @@ const NSInteger ResultCancel = 0;
224
225
  }
225
226
 
226
227
  - (void)setRootViewController:(UIViewController *)rootViewController {
227
- [self setRootViewController:rootViewController withTag:@(0)];
228
- }
229
-
230
- - (void)setRootViewController:(UIViewController *)rootViewController withTag:(NSNumber *)tag {
231
- [HBDEventEmitter sendEvent:EVENT_WILL_SET_ROOT data:@{}];
232
-
233
228
  UIWindow *mainWindow = [self mainWindow];
234
229
  UIViewController *presentedViewController = mainWindow.rootViewController.presentedViewController;
235
230
  if (presentedViewController && !presentedViewController.isBeingDismissed) {
236
231
  [mainWindow.rootViewController dismissViewControllerAnimated:NO completion:^{
237
- [self performSetRootViewController:rootViewController withTag:tag animated:NO];
232
+ [self performSetRootViewController:rootViewController animated:NO];
238
233
  }];
239
234
  } else {
240
- [self performSetRootViewController:rootViewController withTag:tag animated:YES];
235
+ [self performSetRootViewController:rootViewController animated:YES];
241
236
  }
242
237
  }
243
238
 
244
- - (void)performSetRootViewController:(UIViewController *)rootViewController withTag:(NSNumber *)tag animated:(BOOL)animated {
239
+ - (void)performSetRootViewController:(UIViewController *)rootViewController animated:(BOOL)animated {
240
+ [HBDEventEmitter sendEvent:EVENT_WILL_SET_ROOT data:@{}];
245
241
  UIWindow *mainWindow = [self mainWindow];
246
242
  if (animated) {
247
243
  [UIView transitionWithView:mainWindow duration:0.15f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
@@ -253,9 +249,13 @@ const NSInteger ResultCancel = 0;
253
249
  [mainWindow makeKeyAndVisible];
254
250
  }
255
251
  [UIView setAnimationsEnabled:oldState];
252
+ } completion:^(BOOL finished) {
256
253
  self.viewHierarchyReady = YES;
257
- } completion:^(BOOL finished) {
258
- [HBDEventEmitter sendEvent:EVENT_DID_SET_ROOT data:@{@"tag": tag}];
254
+ if (self.didSetRoot) {
255
+ self.didSetRoot(@[NSNull.null, @YES]);
256
+ self.didSetRoot = NULL;
257
+ }
258
+ [HBDEventEmitter sendEvent:EVENT_DID_SET_ROOT data:@{}];
259
259
  }];
260
260
  } else {
261
261
  mainWindow.rootViewController = rootViewController;
@@ -263,8 +263,13 @@ const NSInteger ResultCancel = 0;
263
263
  if (!mainWindow.isKeyWindow) {
264
264
  [mainWindow makeKeyAndVisible];
265
265
  }
266
+
266
267
  self.viewHierarchyReady = YES;
267
- [HBDEventEmitter sendEvent:EVENT_DID_SET_ROOT data:@{@"tag": tag}];
268
+ if (self.didSetRoot) {
269
+ self.didSetRoot(@[NSNull.null, @YES]);
270
+ self.didSetRoot = NULL;
271
+ }
272
+ [HBDEventEmitter sendEvent:EVENT_DID_SET_ROOT data:@{}];
268
273
  }
269
274
  }
270
275
 
@@ -281,11 +286,12 @@ const NSInteger ResultCancel = 0;
281
286
  }
282
287
 
283
288
  NSString *layout = [self.navigatorRegistry layoutForViewController:vc];
284
- if (!layout) {
285
- return nil;
289
+ if (layout) {
290
+ id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:layout];
291
+ return [navigator primaryViewControllerWithViewController:vc];
286
292
  }
287
- id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:layout];
288
- return [navigator primaryViewControllerWithViewController:vc];
293
+
294
+ return nil;
289
295
  }
290
296
 
291
297
  - (NSArray *)routeGraph {
@@ -295,13 +301,13 @@ const NSInteger ResultCancel = 0;
295
301
  NSMutableArray *root = [[NSMutableArray alloc] init];
296
302
  [root addObject:graph];
297
303
  [root addObjectsFromArray:[self presentedGraphsWithRootViewController:vc]];
298
-
299
304
  return root;
300
305
  }
301
306
 
302
307
  - (NSArray *)presentedGraphsWithRootViewController:(UIViewController *)vc {
303
308
  NSMutableArray *graphs = [[NSMutableArray alloc] init];
304
309
  UIViewController *presented = vc.presentedViewController;
310
+
305
311
  while (presented && !presented.beingDismissed && ![presented isKindOfClass:[UIAlertController class]]) {
306
312
  NSDictionary *graph = [self routeGraphWithViewController:presented];
307
313
  if (graph) {
@@ -315,17 +321,17 @@ const NSInteger ResultCancel = 0;
315
321
 
316
322
  - (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc {
317
323
  NSString *layout = [self.navigatorRegistry layoutForViewController:vc];
318
- if (!layout) {
319
- return nil;
324
+ if (layout) {
325
+ id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:layout];
326
+ return [navigator routeGraphWithViewController:vc];
320
327
  }
321
- id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:layout];
322
- return [navigator routeGraphWithViewController:vc];
328
+ return nil;
323
329
  }
324
330
 
325
331
  - (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
326
332
  id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForAction:action];
327
333
  if (!navigator) {
328
- RCTLogWarn(@"[Navigator] Can't find a navigator that can handle action '%@'", action);
334
+ RCTLogWarn(@"[Navigation] Can't find a navigator that can handle action '%@'", action);
329
335
  callback(@[NSNull.null, @NO]);
330
336
  return;
331
337
  }
@@ -327,7 +327,7 @@
327
327
  @dynamic navigationBar;
328
328
 
329
329
  - (void)dealloc {
330
- RCTLogInfo(@"[Navigator] %s", __FUNCTION__);
330
+ RCTLogInfo(@"[Navigation] %s", __FUNCTION__);
331
331
  }
332
332
 
333
333
  - (instancetype)initWithRootViewController:(UIViewController *)rootViewController {
@@ -415,7 +415,7 @@
415
415
  UIEdgeInsets safeAreaInsets = self.view.safeAreaInsets;
416
416
  UIEdgeInsets additionalInsets = self.additionalSafeAreaInsets;
417
417
 
418
- // RCTLogInfo(@"[Navigator] safeAreaInsets:%@, additionalInsets:%@", NSStringFromUIEdgeInsets(safeAreaInsets), NSStringFromUIEdgeInsets(additionalInsets));
418
+ // RCTLogInfo(@"[Navigation] safeAreaInsets:%@, additionalInsets:%@", NSStringFromUIEdgeInsets(safeAreaInsets), NSStringFromUIEdgeInsets(additionalInsets));
419
419
 
420
420
  BOOL statusBarHidden = [UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarHidden;
421
421
 
@@ -18,7 +18,7 @@
18
18
  @implementation HBDViewController
19
19
 
20
20
  - (void)dealloc {
21
- RCTLogInfo(@"[Navigator] %s", __FUNCTION__);
21
+ RCTLogInfo(@"[Navigation] %s", __FUNCTION__);
22
22
  }
23
23
 
24
24
  - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
@@ -50,7 +50,7 @@
50
50
  - (BOOL)canPresentViewController {
51
51
  UIViewController *presented = self.presentedViewController;
52
52
  if (presented && !presented.isBeingDismissed) {
53
- RCTLogWarn(@"[Navigator] Can't present since the scene had present another scene already.");
53
+ RCTLogWarn(@"[Navigation] Can't present since the scene had present another scene already.");
54
54
  return NO;
55
55
  }
56
56
  return YES;
package/lib/Event.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { Visibility } from './Route';
2
- declare function listenStatusBarHeightChange(listener: (statusBarHeight: number) => void): import("react-native").EmitterSubscription;
3
2
  declare function listenComponentResult(listener: (sceneId: string, requestCode: number, resultCode: number, resultData: object) => void): import("react-native").EmitterSubscription;
4
3
  declare function listenComponentVisibility(listener: (sceneId: string, visibility: Visibility) => void): import("react-native").EmitterSubscription;
5
4
  declare function listenBarButtonItemClick(listener: (sceneId: string, action: string) => void): import("react-native").EmitterSubscription;
@@ -7,7 +6,6 @@ declare function listenTabSwitch(listener: (sceneId: string, from: number, to: n
7
6
  declare function listenWillSetRoot(willSetRoot: () => void): import("react-native").EmitterSubscription;
8
7
  declare function listenDidSetRoot(didSetRoot: (tag: number) => void): import("react-native").EmitterSubscription;
9
8
  declare const _default: {
10
- listenStatusBarHeightChange: typeof listenStatusBarHeightChange;
11
9
  listenBarButtonItemClick: typeof listenBarButtonItemClick;
12
10
  listenComponentResult: typeof listenComponentResult;
13
11
  listenComponentVisibility: typeof listenComponentVisibility;
package/lib/Event.js CHANGED
@@ -1,12 +1,4 @@
1
1
  import { NativeModules, NativeEventEmitter } from 'react-native';
2
- import GardenModule from './GardenModule';
3
- function listenStatusBarHeightChange(listener) {
4
- const GardenEventReceiver = new NativeEventEmitter(GardenModule);
5
- const { EVENT_STATUSBAR_FRAME_CHANGE } = GardenModule.getConstants();
6
- return GardenEventReceiver.addListener(EVENT_STATUSBAR_FRAME_CHANGE, ({ statusBarHeight }) => {
7
- listener(statusBarHeight);
8
- });
9
- }
10
2
  const HBDEventEmitter = NativeModules.HBDEventEmitter;
11
3
  const HBDEventReceiver = new NativeEventEmitter(HBDEventEmitter);
12
4
  function listenComponentResult(listener) {
@@ -61,7 +53,6 @@ function listenDidSetRoot(didSetRoot) {
61
53
  });
62
54
  }
63
55
  export default {
64
- listenStatusBarHeightChange,
65
56
  listenBarButtonItemClick,
66
57
  listenComponentResult,
67
58
  listenComponentVisibility,
@@ -17,4 +17,8 @@ interface GardenModule extends NativeModule {
17
17
  setMenuInteractive: (sceneId: string, enabled: boolean) => void;
18
18
  }
19
19
  declare const GardenModule: GardenModule;
20
+ declare function statusBarHeight(): number;
21
+ declare function toolbarHeight(): number;
22
+ declare function topBarHeight(): number;
23
+ export { statusBarHeight, toolbarHeight, topBarHeight };
20
24
  export default GardenModule;
@@ -1,3 +1,21 @@
1
- import { NativeModules } from 'react-native';
1
+ import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
2
2
  const GardenModule = NativeModules.GardenModule;
3
+ const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT, EVENT_STATUSBAR_FRAME_CHANGE } = GardenModule.getConstants();
4
+ let _statusBarHeight = STATUSBAR_HEIGHT;
5
+ if (Platform.OS === 'ios') {
6
+ const GardenEventReceiver = new NativeEventEmitter(GardenModule);
7
+ GardenEventReceiver.addListener(EVENT_STATUSBAR_FRAME_CHANGE, ({ statusBarHeight: height }) => {
8
+ _statusBarHeight = height;
9
+ });
10
+ }
11
+ function statusBarHeight() {
12
+ return _statusBarHeight;
13
+ }
14
+ function toolbarHeight() {
15
+ return TOOLBAR_HEIGHT;
16
+ }
17
+ function topBarHeight() {
18
+ return statusBarHeight() + toolbarHeight();
19
+ }
20
+ export { statusBarHeight, toolbarHeight, topBarHeight };
3
21
  export default GardenModule;
@@ -43,7 +43,7 @@ export declare class Navigation implements Navigation {
43
43
  setResult: <T extends ResultType>(sceneId: string, resultCode: number, data?: T) => void;
44
44
  result<T>(sceneId: string, resultCode: number): Promise<[number, T]>;
45
45
  unmount(sceneId: string): void;
46
- setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<void>;
46
+ setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<boolean>;
47
47
  setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
48
48
  currentTab(sceneId: string): Promise<number>;
49
49
  findSceneIdByModuleName(moduleName: string): Promise<string | null>;
@@ -8,7 +8,7 @@ declare function endRegisterReactComponent(): void;
8
8
  declare function registerReactComponent(appKey: string, options: object): void;
9
9
  declare function signalFirstRenderComplete(sceneId: string): void;
10
10
  declare function setResult(sceneId: string, resultCode: number, data: object | null): void;
11
- declare function setRoot(layout: object, sticky: boolean, tag: number): void;
11
+ declare function setRoot(layout: object, sticky: boolean): Promise<boolean>;
12
12
  declare function dispatch(sceneId: string, action: string, params: object): Promise<boolean>;
13
13
  declare function currentTab(sceneId: string): Promise<number>;
14
14
  declare function isStackRoot(sceneId: string): Promise<boolean>;
@@ -18,8 +18,12 @@ function signalFirstRenderComplete(sceneId) {
18
18
  function setResult(sceneId, resultCode, data) {
19
19
  NavigationModule.setResult(sceneId, resultCode, data);
20
20
  }
21
- function setRoot(layout, sticky, tag) {
22
- NavigationModule.setRoot(layout, sticky, tag);
21
+ function setRoot(layout, sticky) {
22
+ return new Promise(resolve => {
23
+ NavigationModule.setRoot(layout, sticky, (_, success) => {
24
+ resolve(success);
25
+ });
26
+ });
23
27
  }
24
28
  function dispatch(sceneId, action, params) {
25
29
  return new Promise(resolve => {
package/lib/Navigator.js CHANGED
@@ -135,11 +135,13 @@ export class Navigator {
135
135
  }
136
136
  return await Navigation.result(this.sceneId, 0);
137
137
  };
138
- pop = () => Navigation.dispatch(this.sceneId, 'pop');
139
- popTo = (moduleName, inclusive = false) => Navigation.dispatch(this.sceneId, 'popTo', { moduleName, inclusive });
140
- popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot');
138
+ pop = () => Navigation.dispatch(this.sceneId, 'pop', { from: this.moduleName });
139
+ popTo = (moduleName, inclusive = false) => Navigation.dispatch(this.sceneId, 'popTo', { moduleName, inclusive, from: this.moduleName });
140
+ popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot', { from: this.moduleName });
141
141
  redirectTo = (moduleName, props = {}, options = {}) => Navigation.dispatch(this.sceneId, 'redirectTo', {
142
142
  moduleName,
143
+ from: this.moduleName,
144
+ to: moduleName,
143
145
  props,
144
146
  options,
145
147
  });
@@ -170,7 +172,7 @@ export class Navigator {
170
172
  }
171
173
  return await Navigation.result(this.sceneId, requestCode);
172
174
  };
173
- dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss');
175
+ dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss', { from: this.moduleName });
174
176
  showModal = async (moduleName, props = {}, options = {}) => {
175
177
  const requestCode = --tagGenerator;
176
178
  const success = await Navigation.dispatch(this.sceneId, 'showModal', {
@@ -198,15 +200,15 @@ export class Navigator {
198
200
  }
199
201
  return await Navigation.result(this.sceneId, requestCode);
200
202
  };
201
- hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal');
203
+ hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal', { from: this.moduleName });
202
204
  setResult = (resultCode, data = null) => Navigation.setResult(this.sceneId, resultCode, data);
203
205
  switchTab = async (index, popToRoot = false) => {
204
206
  const from = await Navigation.currentTab(this.sceneId);
205
207
  return Navigation.dispatch(this.sceneId, 'switchTab', { from, to: index, popToRoot });
206
208
  };
207
- toggleMenu = () => Navigation.dispatch(this.sceneId, 'toggleMenu');
208
- openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu');
209
- closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu');
209
+ toggleMenu = () => Navigation.dispatch(this.sceneId, 'toggleMenu', { from: this.moduleName });
210
+ openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu', { from: this.moduleName });
211
+ closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', { from: this.moduleName });
210
212
  isStackRoot = () => Navigation.isStackRoot(this.sceneId);
211
213
  signalFirstRenderComplete = () => Navigation.signalFirstRenderComplete(this.sceneId);
212
214
  }
@@ -2,10 +2,8 @@ import { BuildInLayout, Layout } from '../Route';
2
2
  export default class LayoutCommandHandler {
3
3
  private willSetRoot;
4
4
  private didSetRoot;
5
- private canInvokeWillSetRoot;
6
- private tagGenerator;
7
5
  constructor();
8
6
  handleRootLayoutChange(): void;
9
- setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<void>;
7
+ setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<boolean>;
10
8
  setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
11
9
  }
@@ -3,34 +3,17 @@ import NavigationModule from '../NavigationModule';
3
3
  export default class LayoutCommandHandler {
4
4
  willSetRoot = () => { };
5
5
  didSetRoot = () => { };
6
- canInvokeWillSetRoot = true;
7
- tagGenerator = 0;
8
6
  constructor() { }
9
7
  handleRootLayoutChange() {
10
8
  Event.listenWillSetRoot(() => {
11
- if (this.canInvokeWillSetRoot) {
12
- this.willSetRoot();
13
- }
9
+ this.willSetRoot();
14
10
  });
15
11
  Event.listenDidSetRoot(() => {
16
12
  this.didSetRoot();
17
- this.canInvokeWillSetRoot = true;
18
13
  });
19
14
  }
20
15
  setRoot(layout, sticky = false) {
21
- this.willSetRoot();
22
- this.canInvokeWillSetRoot = false;
23
- const flag = this.tagGenerator++;
24
- NavigationModule.setRoot(layout, sticky, flag);
25
- return new Promise(resolve => {
26
- const subscription = Event.listenDidSetRoot((tag) => {
27
- // FIXME: 此处恐有内存泄漏
28
- if (tag === flag) {
29
- subscription.remove();
30
- resolve();
31
- }
32
- });
33
- });
16
+ return NavigationModule.setRoot(layout, sticky);
34
17
  }
35
18
  setRootLayoutUpdateListener(willSetRoot = () => { }, didSetRoot = () => { }) {
36
19
  this.willSetRoot = willSetRoot;
package/lib/index.d.ts CHANGED
@@ -1,11 +1,8 @@
1
1
  import Navigation from './Navigation';
2
- declare function statusBarHeight(): number;
3
- declare function toolbarHeight(): number;
4
- declare function topBarHeight(): number;
5
2
  export default Navigation;
6
- export { statusBarHeight, toolbarHeight, topBarHeight };
7
3
  export { RESULT_OK, RESULT_CANCEL } from './Navigation';
8
- export { withNavigation, withNavigationItem, NavigationProps, InjectedProps, } from './NavigationComponentWrap';
4
+ export { statusBarHeight, toolbarHeight, topBarHeight } from './GardenModule';
5
+ export { withNavigationItem, NavigationProps, InjectedProps } from './NavigationComponentWrap';
9
6
  export * from './Navigator';
10
7
  export * from './Garden';
11
8
  export * from './ReactRegistry';
package/lib/index.js CHANGED
@@ -1,29 +1,10 @@
1
- import { Platform } from 'react-native';
2
- import Navigation from './Navigation';
3
- import Event from './Event';
4
- import GardenModule from './GardenModule';
5
1
  import { withNavigation } from './NavigationComponentWrap';
2
+ import Navigation from './Navigation';
6
3
  Navigation.setNavigationComponentWrap(withNavigation);
7
- const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT } = GardenModule.getConstants();
8
- let _statusBarHeight = STATUSBAR_HEIGHT;
9
- if (Platform.OS === 'ios') {
10
- Event.listenStatusBarHeightChange(height => {
11
- _statusBarHeight = height;
12
- });
13
- }
14
- function statusBarHeight() {
15
- return _statusBarHeight;
16
- }
17
- function toolbarHeight() {
18
- return TOOLBAR_HEIGHT;
19
- }
20
- function topBarHeight() {
21
- return statusBarHeight() + toolbarHeight();
22
- }
23
4
  export default Navigation;
24
- export { statusBarHeight, toolbarHeight, topBarHeight };
25
5
  export { RESULT_OK, RESULT_CANCEL } from './Navigation';
26
- export { withNavigation, withNavigationItem, } from './NavigationComponentWrap';
6
+ export { statusBarHeight, toolbarHeight, topBarHeight } from './GardenModule';
7
+ export { withNavigationItem } from './NavigationComponentWrap';
27
8
  export * from './Navigator';
28
9
  export * from './Garden';
29
10
  export * from './ReactRegistry';
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": "2.13.1",
4
+ "version": "2.13.4",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "./lib/index.d.ts",
7
7
  "react-native": "src/index",
package/src/Event.ts CHANGED
@@ -1,15 +1,5 @@
1
1
  import { NativeModules, NativeEventEmitter, NativeModule } from 'react-native'
2
- import GardenModule from './GardenModule'
3
2
  import type { Visibility } from './Route'
4
-
5
- function listenStatusBarHeightChange(listener: (statusBarHeight: number) => void) {
6
- const GardenEventReceiver = new NativeEventEmitter(GardenModule)
7
- const { EVENT_STATUSBAR_FRAME_CHANGE } = GardenModule.getConstants()
8
- return GardenEventReceiver.addListener(EVENT_STATUSBAR_FRAME_CHANGE, ({ statusBarHeight }) => {
9
- listener(statusBarHeight)
10
- })
11
- }
12
-
13
3
  interface HBDEventEmitter extends NativeModule {
14
4
  getConstants: () => {
15
5
  EVENT_NAVIGATION: string
@@ -113,7 +103,6 @@ function listenDidSetRoot(didSetRoot: (tag: number) => void) {
113
103
  }
114
104
 
115
105
  export default {
116
- listenStatusBarHeightChange,
117
106
  listenBarButtonItemClick,
118
107
  listenComponentResult,
119
108
  listenComponentVisibility,
@@ -1,4 +1,4 @@
1
- import { NativeModules, NativeModule } from 'react-native'
1
+ import { NativeModules, NativeModule, NativeEventEmitter, Platform } from 'react-native'
2
2
 
3
3
  interface GardenModule extends NativeModule {
4
4
  getConstants: () => {
@@ -21,4 +21,30 @@ interface GardenModule extends NativeModule {
21
21
 
22
22
  const GardenModule: GardenModule = NativeModules.GardenModule
23
23
 
24
+ const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT, EVENT_STATUSBAR_FRAME_CHANGE } =
25
+ GardenModule.getConstants()
26
+
27
+ let _statusBarHeight = STATUSBAR_HEIGHT
28
+
29
+ if (Platform.OS === 'ios') {
30
+ const GardenEventReceiver = new NativeEventEmitter(GardenModule)
31
+ GardenEventReceiver.addListener(EVENT_STATUSBAR_FRAME_CHANGE, ({ statusBarHeight: height }) => {
32
+ _statusBarHeight = height
33
+ })
34
+ }
35
+
36
+ function statusBarHeight() {
37
+ return _statusBarHeight
38
+ }
39
+
40
+ function toolbarHeight() {
41
+ return TOOLBAR_HEIGHT
42
+ }
43
+
44
+ function topBarHeight() {
45
+ return statusBarHeight() + toolbarHeight()
46
+ }
47
+
48
+ export { statusBarHeight, toolbarHeight, topBarHeight }
49
+
24
50
  export default GardenModule
@@ -1,8 +1,6 @@
1
1
  import React, { useEffect } from 'react'
2
-
3
2
  import type { Garden } from './Garden'
4
3
  import type { NavigationItem } from './Options'
5
-
6
4
  import { Navigator, NavigationContext } from './Navigator'
7
5
 
8
6
  export interface NavigationProps {