hybrid-navigation 2.17.12 → 2.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +6 -5
- package/ios/HybridNavigation/Navigator/HBDScreenNavigator.m +11 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +3 -1
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +2 -0
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +7 -5
- package/lib/NavigationComponentWrap.js +3 -3
- package/lib/Navigator.d.ts +1 -1
- package/lib/Navigator.js +4 -4
- package/lib/Route.d.ts +1 -0
- package/lib/handler/ResultEventHandler.d.ts +1 -1
- package/lib/handler/ResultEventHandler.js +14 -19
- package/package.json +1 -1
- package/src/NavigationComponentWrap.tsx +3 -3
- package/src/Navigator.ts +5 -5
- package/src/Route.ts +1 -0
- package/src/handler/ResultEventHandler.ts +17 -20
|
@@ -91,7 +91,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
91
91
|
if (activity == null) {
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
|
|
95
95
|
activity.scheduleTaskAtStarted(() -> {
|
|
96
96
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
97
97
|
if (fragment instanceof ReactFragment) {
|
|
@@ -166,7 +166,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
166
166
|
callback.invoke(null, -1);
|
|
167
167
|
return;
|
|
168
168
|
}
|
|
169
|
-
|
|
169
|
+
|
|
170
170
|
activity.scheduleTaskAtStarted(() -> {
|
|
171
171
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
172
172
|
if (fragment == null) {
|
|
@@ -193,7 +193,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
193
193
|
callback.invoke(null, -1);
|
|
194
194
|
return;
|
|
195
195
|
}
|
|
196
|
-
|
|
196
|
+
|
|
197
197
|
activity.scheduleTaskAtStarted(() -> {
|
|
198
198
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
199
199
|
if (fragment == null) {
|
|
@@ -225,7 +225,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
225
225
|
UiThreadUtil.runOnUiThread(this, 16);
|
|
226
226
|
return;
|
|
227
227
|
}
|
|
228
|
-
|
|
228
|
+
|
|
229
229
|
activity.scheduleTaskAtStarted(() -> {
|
|
230
230
|
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
|
231
231
|
Fragment fragment = fragmentManager.findFragmentById(android.R.id.content);
|
|
@@ -300,6 +300,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
300
300
|
bundle.putString("moduleName", current.getModuleName());
|
|
301
301
|
bundle.putString("sceneId", current.getSceneId());
|
|
302
302
|
bundle.putString("mode", Navigator.Util.getMode(current));
|
|
303
|
+
bundle.putInt("requestCode", current.getRequestCode());
|
|
303
304
|
callback.invoke(null, Arguments.fromBundle(bundle));
|
|
304
305
|
});
|
|
305
306
|
}
|
|
@@ -318,7 +319,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
318
319
|
UiThreadUtil.runOnUiThread(this, 16);
|
|
319
320
|
return;
|
|
320
321
|
}
|
|
321
|
-
|
|
322
|
+
|
|
322
323
|
activity.scheduleTaskAtStarted(() -> {
|
|
323
324
|
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
|
324
325
|
ArrayList<Bundle> graph = bridgeManager.buildRouteGraph(fragmentManager);
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
#import "HBDReactBridgeManager.h"
|
|
4
4
|
#import "HBDNavigationController.h"
|
|
5
5
|
#import "HBDAnimationObserver.h"
|
|
6
|
+
#import "UIViewController+HBD.h"
|
|
6
7
|
|
|
7
8
|
#import <React/RCTLog.h>
|
|
8
9
|
|
|
@@ -82,6 +83,11 @@
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
- (void)handlePresentWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
86
|
+
if (![presenting canPresentViewController]) {
|
|
87
|
+
callback(@[NSNull.null, @NO]);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
85
91
|
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
86
92
|
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
87
93
|
HBDNavigationController *nav = [[HBDNavigationController alloc] initWithRootViewController:vc];
|
|
@@ -100,6 +106,11 @@
|
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
- (void)handleShowModalWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
109
|
+
if (![presenting canPresentViewController]) {
|
|
110
|
+
callback(@[NSNull.null, @NO]);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
103
114
|
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
104
115
|
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
105
116
|
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
@@ -214,11 +214,13 @@ RCT_EXPORT_METHOD(currentRoute:(RCTResponseSenderBlock)callback) {
|
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
HBDViewController *current = [self.bridgeManager primaryViewController];
|
|
217
|
+
|
|
217
218
|
if (current) {
|
|
218
219
|
callback(@[[NSNull null], @{
|
|
219
220
|
@"moduleName": RCTNullIfNil(current.moduleName),
|
|
220
221
|
@"sceneId": current.sceneId,
|
|
221
|
-
@"mode": [current hbd_mode]
|
|
222
|
+
@"mode": [current hbd_mode],
|
|
223
|
+
@"requestCode": @(current.requestCode),
|
|
222
224
|
}]);
|
|
223
225
|
} else {
|
|
224
226
|
[self performSelector:@selector(currentRouteWithCallback:) withObject:callback afterDelay:0.016];
|
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
@property(nonatomic, assign) NSInteger requestCode;
|
|
25
25
|
@property(nonatomic, copy) NSDictionary *resultData;
|
|
26
26
|
|
|
27
|
+
- (BOOL)canPresentViewController;
|
|
28
|
+
|
|
27
29
|
- (void)setResultCode:(NSInteger)resultCode resultData:(NSDictionary *)data;
|
|
28
30
|
|
|
29
31
|
- (void)didReceiveResultCode:(NSInteger)resultCode resultData:(NSDictionary *)data requestCode:(NSInteger)requestCode;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#import "UIViewController+HBD.h"
|
|
2
2
|
|
|
3
3
|
#import "HBDNavigationController.h"
|
|
4
|
+
#import "HBDReactViewController.h"
|
|
4
5
|
#import "HBDUtils.h"
|
|
5
6
|
#import "GlobalStyle.h"
|
|
6
7
|
#import "UITabBar+Badge.h"
|
|
@@ -20,10 +21,6 @@
|
|
|
20
21
|
|
|
21
22
|
- (void)hbd_presentViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(void (^)(void))completion {
|
|
22
23
|
if (![self canPresentViewController]) {
|
|
23
|
-
[self didReceiveResultCode:0 resultData:nil requestCode:viewController.requestCode];
|
|
24
|
-
if (completion) {
|
|
25
|
-
completion();
|
|
26
|
-
}
|
|
27
24
|
return;
|
|
28
25
|
}
|
|
29
26
|
viewController.presentingSceneId = self.sceneId;
|
|
@@ -33,7 +30,12 @@
|
|
|
33
30
|
- (BOOL)canPresentViewController {
|
|
34
31
|
UIViewController *presented = self.presentedViewController;
|
|
35
32
|
if (presented && !presented.isBeingDismissed) {
|
|
36
|
-
|
|
33
|
+
if ([presented isKindOfClass:[HBDReactViewController class]]) {
|
|
34
|
+
HBDReactViewController *vc = (HBDReactViewController *)presented;
|
|
35
|
+
RCTLogInfo(@"[Navigation] Can't present since the scene had present another scene already. %@", vc.moduleName);
|
|
36
|
+
} else {
|
|
37
|
+
RCTLogInfo(@"[Navigation] Can't present since the scene had present another scene already. %@", NSStringFromClass([presented class]));
|
|
38
|
+
}
|
|
37
39
|
return NO;
|
|
38
40
|
}
|
|
39
41
|
return YES;
|
|
@@ -13,11 +13,11 @@ export function withNavigation(moduleName) {
|
|
|
13
13
|
navigator.moduleName = moduleName;
|
|
14
14
|
}
|
|
15
15
|
useEffect(() => {
|
|
16
|
-
Navigation.signalFirstRenderComplete(
|
|
16
|
+
Navigation.signalFirstRenderComplete(sceneId);
|
|
17
17
|
return () => {
|
|
18
|
-
|
|
18
|
+
Navigator.unmount(sceneId);
|
|
19
19
|
};
|
|
20
|
-
}, [
|
|
20
|
+
}, [sceneId]);
|
|
21
21
|
const injected = {
|
|
22
22
|
navigator,
|
|
23
23
|
};
|
package/lib/Navigator.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare class Navigator implements Navigator {
|
|
|
17
17
|
sceneId: string;
|
|
18
18
|
moduleName?: string | undefined;
|
|
19
19
|
static of(sceneId: string): Navigator;
|
|
20
|
+
static unmount: (sceneId: string) => void;
|
|
20
21
|
static find(moduleName: string): Promise<Navigator | undefined>;
|
|
21
22
|
static current(): Promise<Navigator>;
|
|
22
23
|
constructor(sceneId: string, moduleName?: string | undefined);
|
|
@@ -25,7 +26,6 @@ export declare class Navigator implements Navigator {
|
|
|
25
26
|
setParams: (params: {
|
|
26
27
|
[index: string]: any;
|
|
27
28
|
}) => void;
|
|
28
|
-
unmount: () => void;
|
|
29
29
|
push: <T extends ResultType, P extends PropsType = {}>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
|
|
30
30
|
pushLayout: <T extends ResultType>(layout: BuildInLayout | Layout) => Promise<[number, T]>;
|
|
31
31
|
pop: () => Promise<boolean>;
|
package/lib/Navigator.js
CHANGED
|
@@ -24,6 +24,10 @@ export class Navigator {
|
|
|
24
24
|
}
|
|
25
25
|
return navigator;
|
|
26
26
|
}
|
|
27
|
+
static unmount = (sceneId) => {
|
|
28
|
+
store.removeNavigator(sceneId);
|
|
29
|
+
Navigation.unmount(sceneId);
|
|
30
|
+
};
|
|
27
31
|
static async find(moduleName) {
|
|
28
32
|
const sceneId = await Navigation.findSceneIdByModuleName(moduleName);
|
|
29
33
|
if (sceneId) {
|
|
@@ -45,10 +49,6 @@ export class Navigator {
|
|
|
45
49
|
setParams = (params) => {
|
|
46
50
|
this.state.params = { ...this.state.params, ...params };
|
|
47
51
|
};
|
|
48
|
-
unmount = () => {
|
|
49
|
-
store.removeNavigator(this.sceneId);
|
|
50
|
-
Navigation.unmount(this.sceneId);
|
|
51
|
-
};
|
|
52
52
|
push = async (moduleName, props = {}, options = {}) => {
|
|
53
53
|
const success = await Navigation.dispatch(this.sceneId, 'push', {
|
|
54
54
|
moduleName,
|
package/lib/Route.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ interface IndexType {
|
|
|
4
4
|
export type ResultType = IndexType | null;
|
|
5
5
|
export type ResultEventListener<T extends ResultType> = (resultCode: number, data: T) => void;
|
|
6
6
|
export default class ResultEventHandler {
|
|
7
|
-
private
|
|
7
|
+
private listenerRecords;
|
|
8
8
|
constructor();
|
|
9
9
|
handleComponentResult(): void;
|
|
10
10
|
private addResultEventListener;
|
|
@@ -1,39 +1,34 @@
|
|
|
1
1
|
import Event from '../Event';
|
|
2
|
-
import NavigationModule from '../NavigationModule';
|
|
3
|
-
const { RESULT_CANCEL } = NavigationModule.getConstants();
|
|
4
2
|
export default class ResultEventHandler {
|
|
5
|
-
|
|
3
|
+
listenerRecords = {};
|
|
6
4
|
constructor() { }
|
|
7
5
|
handleComponentResult() {
|
|
8
6
|
Event.listenComponentResult((sceneId, requestCode, resultCode, data) => {
|
|
9
|
-
const
|
|
10
|
-
if (
|
|
11
|
-
delete this.
|
|
12
|
-
|
|
7
|
+
const listeners = this.listenerRecords[sceneId]?.[requestCode];
|
|
8
|
+
if (listeners) {
|
|
9
|
+
delete this.listenerRecords[sceneId][requestCode];
|
|
10
|
+
listeners.forEach(l => l(resultCode, data));
|
|
13
11
|
}
|
|
14
12
|
});
|
|
15
13
|
}
|
|
16
14
|
addResultEventListener(sceneId, requestCode, listener) {
|
|
17
|
-
if (!this.
|
|
18
|
-
this.
|
|
15
|
+
if (!this.listenerRecords[sceneId]) {
|
|
16
|
+
this.listenerRecords[sceneId] = {};
|
|
19
17
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
previousListener(RESULT_CANCEL, null);
|
|
18
|
+
if (!this.listenerRecords[sceneId][requestCode]) {
|
|
19
|
+
this.listenerRecords[sceneId][requestCode] = [];
|
|
23
20
|
}
|
|
24
|
-
this.
|
|
21
|
+
this.listenerRecords[sceneId][requestCode].push(listener);
|
|
25
22
|
}
|
|
26
23
|
removeResultEventListener(sceneId, requestCode) {
|
|
27
|
-
if (this.
|
|
28
|
-
delete this.
|
|
24
|
+
if (this.listenerRecords[sceneId]) {
|
|
25
|
+
delete this.listenerRecords[sceneId][requestCode];
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
28
|
invalidateResultEventListener(sceneId) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Object.values(listeners).forEach(listener => listener(RESULT_CANCEL, null));
|
|
29
|
+
if (this.listenerRecords[sceneId]) {
|
|
30
|
+
delete this.listenerRecords[sceneId];
|
|
35
31
|
}
|
|
36
|
-
delete this.listeners[sceneId];
|
|
37
32
|
}
|
|
38
33
|
waitResult(sceneId, requestCode) {
|
|
39
34
|
return new Promise(resolve => {
|
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.
|
|
4
|
+
"version": "2.18.1",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"typings": "./lib/index.d.ts",
|
|
7
7
|
"react-native": "src/index",
|
|
@@ -27,11 +27,11 @@ export function withNavigation(moduleName: string) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
useEffect(() => {
|
|
30
|
-
Navigation.signalFirstRenderComplete(
|
|
30
|
+
Navigation.signalFirstRenderComplete(sceneId)
|
|
31
31
|
return () => {
|
|
32
|
-
|
|
32
|
+
Navigator.unmount(sceneId)
|
|
33
33
|
}
|
|
34
|
-
}, [
|
|
34
|
+
}, [sceneId])
|
|
35
35
|
|
|
36
36
|
const injected = {
|
|
37
37
|
navigator,
|
package/src/Navigator.ts
CHANGED
|
@@ -41,6 +41,11 @@ export class Navigator implements Navigator {
|
|
|
41
41
|
return navigator
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
static unmount = (sceneId: string) => {
|
|
45
|
+
store.removeNavigator(sceneId)
|
|
46
|
+
Navigation.unmount(sceneId)
|
|
47
|
+
}
|
|
48
|
+
|
|
44
49
|
static async find(moduleName: string) {
|
|
45
50
|
const sceneId = await Navigation.findSceneIdByModuleName(moduleName)
|
|
46
51
|
if (sceneId) {
|
|
@@ -65,11 +70,6 @@ export class Navigator implements Navigator {
|
|
|
65
70
|
this.state.params = { ...this.state.params, ...params }
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
unmount = () => {
|
|
69
|
-
store.removeNavigator(this.sceneId)
|
|
70
|
-
Navigation.unmount(this.sceneId)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
73
|
push = async <T extends ResultType, P extends PropsType = {}>(
|
|
74
74
|
moduleName: string,
|
|
75
75
|
props: P = {} as P,
|
package/src/Route.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Event from '../Event'
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
interface IndexType {
|
|
4
4
|
[index: string]: any
|
|
5
5
|
}
|
|
@@ -7,19 +7,18 @@ interface IndexType {
|
|
|
7
7
|
export type ResultType = IndexType | null
|
|
8
8
|
export type ResultEventListener<T extends ResultType> = (resultCode: number, data: T) => void
|
|
9
9
|
|
|
10
|
-
const { RESULT_CANCEL } = NavigationModule.getConstants()
|
|
11
10
|
export default class ResultEventHandler {
|
|
12
|
-
private
|
|
11
|
+
private listenerRecords: Record<string, Record<number, Array<ResultEventListener<any>>>> = {}
|
|
13
12
|
|
|
14
13
|
constructor() {}
|
|
15
14
|
|
|
16
15
|
handleComponentResult() {
|
|
17
16
|
Event.listenComponentResult(
|
|
18
17
|
(sceneId: string, requestCode: number, resultCode: number, data: any) => {
|
|
19
|
-
const
|
|
20
|
-
if (
|
|
21
|
-
delete this.
|
|
22
|
-
|
|
18
|
+
const listeners = this.listenerRecords[sceneId]?.[requestCode]
|
|
19
|
+
if (listeners) {
|
|
20
|
+
delete this.listenerRecords[sceneId][requestCode]
|
|
21
|
+
listeners.forEach(l => l(resultCode, data))
|
|
23
22
|
}
|
|
24
23
|
},
|
|
25
24
|
)
|
|
@@ -30,29 +29,27 @@ export default class ResultEventHandler {
|
|
|
30
29
|
requestCode: number,
|
|
31
30
|
listener: ResultEventListener<any>,
|
|
32
31
|
) {
|
|
33
|
-
if (!this.
|
|
34
|
-
this.
|
|
32
|
+
if (!this.listenerRecords[sceneId]) {
|
|
33
|
+
this.listenerRecords[sceneId] = {}
|
|
35
34
|
}
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
35
|
+
|
|
36
|
+
if (!this.listenerRecords[sceneId][requestCode]) {
|
|
37
|
+
this.listenerRecords[sceneId][requestCode] = []
|
|
39
38
|
}
|
|
40
|
-
|
|
39
|
+
|
|
40
|
+
this.listenerRecords[sceneId][requestCode].push(listener)
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
private removeResultEventListener(sceneId: string, requestCode: number) {
|
|
44
|
-
if (this.
|
|
45
|
-
delete this.
|
|
44
|
+
if (this.listenerRecords[sceneId]) {
|
|
45
|
+
delete this.listenerRecords[sceneId][requestCode]
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
invalidateResultEventListener(sceneId: string) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
Object.values(listeners).forEach(listener => listener(RESULT_CANCEL, null))
|
|
50
|
+
if (this.listenerRecords[sceneId]) {
|
|
51
|
+
delete this.listenerRecords[sceneId]
|
|
53
52
|
}
|
|
54
|
-
|
|
55
|
-
delete this.listeners[sceneId]
|
|
56
53
|
}
|
|
57
54
|
|
|
58
55
|
waitResult<T extends ResultType>(sceneId: string, requestCode: number): Promise<[number, T]> {
|