hybrid-navigation 2.13.2 → 2.13.3
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/README.md +4 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +10 -11
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigatorRegistry.java +0 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +32 -64
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +8 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFrameLayout.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +1 -2
- package/ios/HybridNavigation/HBDUtils.m +3 -3
- package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +2 -2
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +8 -8
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +22 -15
- package/ios/HybridNavigation/ReactBridge/HBDReactBridgeManager.h +2 -3
- package/ios/HybridNavigation/ReactBridge/HBDReactBridgeManager.m +35 -29
- package/ios/HybridNavigation/ViewController/HBDNavigationController.m +2 -2
- package/ios/HybridNavigation/ViewController/HBDViewController.m +1 -1
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +1 -1
- package/lib/Event.d.ts +0 -2
- package/lib/Event.js +0 -9
- package/lib/GardenModule.d.ts +4 -0
- package/lib/GardenModule.js +19 -1
- package/lib/Navigation.d.ts +1 -1
- package/lib/NavigationModule.d.ts +1 -1
- package/lib/NavigationModule.js +6 -2
- package/lib/Navigator.js +10 -8
- package/lib/handler/LayoutCommandHandler.d.ts +1 -3
- package/lib/handler/LayoutCommandHandler.js +2 -19
- package/lib/index.d.ts +1 -4
- package/lib/index.js +1 -20
- package/package.json +1 -1
- package/src/Event.ts +0 -11
- package/src/GardenModule.ts +27 -1
- package/src/NavigationModule.ts +7 -3
- package/src/Navigator.ts +10 -8
- package/src/handler/LayoutCommandHandler.ts +2 -22
- package/src/index.ts +1 -24
|
@@ -53,7 +53,7 @@ const NSInteger ResultCancel = 0;
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
- (void)invalidate {
|
|
56
|
-
RCTLogInfo(@"[
|
|
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(@"[
|
|
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 *)
|
|
190
|
-
if (
|
|
191
|
-
|
|
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
|
-
|
|
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
|
|
232
|
+
[self performSetRootViewController:rootViewController animated:NO];
|
|
238
233
|
}];
|
|
239
234
|
} else {
|
|
240
|
-
[self performSetRootViewController:rootViewController
|
|
235
|
+
[self performSetRootViewController:rootViewController animated:YES];
|
|
241
236
|
}
|
|
242
237
|
}
|
|
243
238
|
|
|
244
|
-
- (void)performSetRootViewController:(UIViewController *)rootViewController
|
|
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
|
-
|
|
258
|
-
|
|
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
|
-
|
|
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 (
|
|
285
|
-
|
|
289
|
+
if (layout) {
|
|
290
|
+
id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:layout];
|
|
291
|
+
return [navigator primaryViewControllerWithViewController:vc];
|
|
286
292
|
}
|
|
287
|
-
|
|
288
|
-
return
|
|
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 (
|
|
319
|
-
|
|
324
|
+
if (layout) {
|
|
325
|
+
id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:layout];
|
|
326
|
+
return [navigator routeGraphWithViewController:vc];
|
|
320
327
|
}
|
|
321
|
-
|
|
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(@"[
|
|
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(@"[
|
|
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(@"[
|
|
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(@"[
|
|
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(@"[
|
|
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,
|
package/lib/GardenModule.d.ts
CHANGED
|
@@ -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;
|
package/lib/GardenModule.js
CHANGED
|
@@ -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;
|
package/lib/Navigation.d.ts
CHANGED
|
@@ -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<
|
|
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
|
|
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>;
|
package/lib/NavigationModule.js
CHANGED
|
@@ -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
|
|
22
|
-
|
|
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<
|
|
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
|
-
|
|
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
|
-
|
|
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,10 +1,7 @@
|
|
|
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';
|
|
4
|
+
export { statusBarHeight, toolbarHeight, topBarHeight } from './GardenModule';
|
|
8
5
|
export { withNavigationItem, NavigationProps, InjectedProps } from './NavigationComponentWrap';
|
|
9
6
|
export * from './Navigator';
|
|
10
7
|
export * from './Garden';
|
package/lib/index.js
CHANGED
|
@@ -1,28 +1,9 @@
|
|
|
1
|
-
import { Platform } from 'react-native';
|
|
2
|
-
import Event from './Event';
|
|
3
|
-
import GardenModule from './GardenModule';
|
|
4
1
|
import { withNavigation } from './NavigationComponentWrap';
|
|
5
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';
|
|
6
|
+
export { statusBarHeight, toolbarHeight, topBarHeight } from './GardenModule';
|
|
26
7
|
export { withNavigationItem } from './NavigationComponentWrap';
|
|
27
8
|
export * from './Navigator';
|
|
28
9
|
export * from './Garden';
|
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.
|
|
4
|
+
"version": "2.13.3",
|
|
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,
|
package/src/GardenModule.ts
CHANGED
|
@@ -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
|
package/src/NavigationModule.ts
CHANGED
|
@@ -13,7 +13,7 @@ interface NavigationModule {
|
|
|
13
13
|
endRegisterReactComponent: () => void
|
|
14
14
|
registerReactComponent: (appKey: string, options: object) => void
|
|
15
15
|
signalFirstRenderComplete: (sceneId: string) => void
|
|
16
|
-
setRoot: (layout: object, sticky: boolean,
|
|
16
|
+
setRoot: (layout: object, sticky: boolean, callback: Callback) => void
|
|
17
17
|
setResult: (sceneId: string, resultCode: number, data: object | null) => void
|
|
18
18
|
dispatch: (sceneId: string, action: string, params: object, callback: Callback) => void
|
|
19
19
|
currentTab: (sceneId: string, callback: Callback) => void
|
|
@@ -49,8 +49,12 @@ function setResult(sceneId: string, resultCode: number, data: object | null) {
|
|
|
49
49
|
NavigationModule.setResult(sceneId, resultCode, data)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function setRoot(layout: object, sticky: boolean
|
|
53
|
-
|
|
52
|
+
function setRoot(layout: object, sticky: boolean) {
|
|
53
|
+
return new Promise<boolean>(resolve => {
|
|
54
|
+
NavigationModule.setRoot(layout, sticky, (_, success) => {
|
|
55
|
+
resolve(success)
|
|
56
|
+
})
|
|
57
|
+
})
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
function dispatch(sceneId: string, action: string, params: object) {
|
package/src/Navigator.ts
CHANGED
|
@@ -179,12 +179,12 @@ export class Navigator implements Navigator {
|
|
|
179
179
|
return await Navigation.result<T>(this.sceneId, 0)
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
pop = () => Navigation.dispatch(this.sceneId, 'pop')
|
|
182
|
+
pop = () => Navigation.dispatch(this.sceneId, 'pop', { from: this.moduleName })
|
|
183
183
|
|
|
184
184
|
popTo = (moduleName: string, inclusive: boolean = false) =>
|
|
185
|
-
Navigation.dispatch(this.sceneId, 'popTo', { moduleName, inclusive })
|
|
185
|
+
Navigation.dispatch(this.sceneId, 'popTo', { moduleName, inclusive, from: this.moduleName })
|
|
186
186
|
|
|
187
|
-
popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot')
|
|
187
|
+
popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot', { from: this.moduleName })
|
|
188
188
|
|
|
189
189
|
redirectTo = <P extends PropsType>(
|
|
190
190
|
moduleName: string,
|
|
@@ -193,6 +193,8 @@ export class Navigator implements Navigator {
|
|
|
193
193
|
) =>
|
|
194
194
|
Navigation.dispatch(this.sceneId, 'redirectTo', {
|
|
195
195
|
moduleName,
|
|
196
|
+
from: this.moduleName,
|
|
197
|
+
to: moduleName,
|
|
196
198
|
props,
|
|
197
199
|
options,
|
|
198
200
|
})
|
|
@@ -230,7 +232,7 @@ export class Navigator implements Navigator {
|
|
|
230
232
|
return await Navigation.result<T>(this.sceneId, requestCode)
|
|
231
233
|
}
|
|
232
234
|
|
|
233
|
-
dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss')
|
|
235
|
+
dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss', { from: this.moduleName })
|
|
234
236
|
|
|
235
237
|
showModal = async <T extends ResultType, P extends PropsType = {}>(
|
|
236
238
|
moduleName: string,
|
|
@@ -265,7 +267,7 @@ export class Navigator implements Navigator {
|
|
|
265
267
|
return await Navigation.result<T>(this.sceneId, requestCode)
|
|
266
268
|
}
|
|
267
269
|
|
|
268
|
-
hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal')
|
|
270
|
+
hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal', { from: this.moduleName })
|
|
269
271
|
|
|
270
272
|
setResult = <T extends ResultType>(resultCode: number, data: T = null as any): void =>
|
|
271
273
|
Navigation.setResult(this.sceneId, resultCode, data)
|
|
@@ -275,11 +277,11 @@ export class Navigator implements Navigator {
|
|
|
275
277
|
return Navigation.dispatch(this.sceneId, 'switchTab', { from, to: index, popToRoot })
|
|
276
278
|
}
|
|
277
279
|
|
|
278
|
-
toggleMenu = () => Navigation.dispatch(this.sceneId, 'toggleMenu')
|
|
280
|
+
toggleMenu = () => Navigation.dispatch(this.sceneId, 'toggleMenu', { from: this.moduleName })
|
|
279
281
|
|
|
280
|
-
openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu')
|
|
282
|
+
openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu', { from: this.moduleName })
|
|
281
283
|
|
|
282
|
-
closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu')
|
|
284
|
+
closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', { from: this.moduleName })
|
|
283
285
|
|
|
284
286
|
isStackRoot = () => Navigation.isStackRoot(this.sceneId)
|
|
285
287
|
|
|
@@ -6,40 +6,20 @@ export default class LayoutCommandHandler {
|
|
|
6
6
|
private willSetRoot = () => {}
|
|
7
7
|
private didSetRoot = () => {}
|
|
8
8
|
|
|
9
|
-
private canInvokeWillSetRoot = true
|
|
10
|
-
private tagGenerator = 0
|
|
11
|
-
|
|
12
9
|
constructor() {}
|
|
13
10
|
|
|
14
11
|
handleRootLayoutChange() {
|
|
15
12
|
Event.listenWillSetRoot(() => {
|
|
16
|
-
|
|
17
|
-
this.willSetRoot()
|
|
18
|
-
}
|
|
13
|
+
this.willSetRoot()
|
|
19
14
|
})
|
|
20
15
|
|
|
21
16
|
Event.listenDidSetRoot(() => {
|
|
22
17
|
this.didSetRoot()
|
|
23
|
-
this.canInvokeWillSetRoot = true
|
|
24
18
|
})
|
|
25
19
|
}
|
|
26
20
|
|
|
27
21
|
setRoot(layout: BuildInLayout | Layout, sticky = false) {
|
|
28
|
-
|
|
29
|
-
this.canInvokeWillSetRoot = false
|
|
30
|
-
|
|
31
|
-
const flag = this.tagGenerator++
|
|
32
|
-
NavigationModule.setRoot(layout, sticky, flag)
|
|
33
|
-
|
|
34
|
-
return new Promise<void>(resolve => {
|
|
35
|
-
const subscription = Event.listenDidSetRoot((tag: number) => {
|
|
36
|
-
// FIXME: 此处恐有内存泄漏
|
|
37
|
-
if (tag === flag) {
|
|
38
|
-
subscription.remove()
|
|
39
|
-
resolve()
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
})
|
|
22
|
+
return NavigationModule.setRoot(layout, sticky)
|
|
43
23
|
}
|
|
44
24
|
|
|
45
25
|
setRootLayoutUpdateListener(willSetRoot = () => {}, didSetRoot = () => {}) {
|