hybrid-navigation 2.18.2 → 2.18.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.
- package/LICENSE +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +1 -0
- package/{lib → dist}/Navigation.d.ts +1 -1
- package/{lib → dist}/Navigation.js +10 -4
- package/{lib → dist}/NavigationComponentWrap.js +6 -5
- package/{lib → dist}/NavigationModule.d.ts +1 -0
- package/{lib → dist}/Navigator.d.ts +0 -1
- package/{lib → dist}/Navigator.js +22 -11
- package/{lib → dist}/hooks.js +2 -1
- package/{lib → dist}/index.d.ts +1 -1
- package/{lib → dist}/index.js +1 -1
- package/{lib → dist}/router/index.js +6 -2
- package/{lib → dist}/router/stack.js +1 -1
- package/ios/HybridNavigation/HBDUtils.h +2 -0
- package/ios/HybridNavigation/HBDUtils.m +12 -3
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +2 -6
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +13 -13
- package/ios/HybridNavigation/ReactBridge/HBDReactBridgeManager.h +1 -0
- package/ios/HybridNavigation/ReactBridge/HBDReactBridgeManager.m +1 -0
- package/ios/HybridNavigation/ViewController/HBDDrawerController.m +1 -1
- package/ios/HybridNavigation/ViewController/HBDNavigationController.m +1 -1
- package/ios/HybridNavigation/ViewController/HBDViewController.m +1 -1
- package/package.json +47 -78
- package/src/DeepLink.ts +52 -52
- package/src/Event.ts +88 -83
- package/src/GardenModule.ts +30 -30
- package/src/Navigation.ts +293 -274
- package/src/NavigationComponentWrap.tsx +52 -47
- package/src/NavigationModule.ts +77 -76
- package/src/Navigator.ts +212 -201
- package/src/Options.ts +120 -112
- package/src/Route.ts +59 -59
- package/src/handler/BarButtonEventHandler.ts +50 -46
- package/src/handler/DispatchCommandHandler.ts +56 -52
- package/src/handler/LayoutCommandHandler.ts +21 -21
- package/src/handler/ResultEventHandler.ts +63 -49
- package/src/handler/VisibilityEventHandler.ts +57 -40
- package/src/hooks.ts +23 -21
- package/src/index.ts +15 -15
- package/src/router/drawer.ts +24 -24
- package/src/router/index.ts +206 -198
- package/src/router/screen.ts +28 -28
- package/src/router/stack.ts +76 -76
- package/src/router/tabs.ts +28 -28
- package/src/store.ts +9 -9
- package/README.md +0 -79
- /package/{lib → dist}/DeepLink.d.ts +0 -0
- /package/{lib → dist}/DeepLink.js +0 -0
- /package/{lib → dist}/Event.d.ts +0 -0
- /package/{lib → dist}/Event.js +0 -0
- /package/{lib → dist}/GardenModule.d.ts +0 -0
- /package/{lib → dist}/GardenModule.js +0 -0
- /package/{lib → dist}/NavigationComponentWrap.d.ts +0 -0
- /package/{lib → dist}/NavigationModule.js +0 -0
- /package/{lib → dist}/Options.d.ts +0 -0
- /package/{lib → dist}/Options.js +0 -0
- /package/{lib → dist}/Route.d.ts +0 -0
- /package/{lib → dist}/Route.js +0 -0
- /package/{lib → dist}/handler/BarButtonEventHandler.d.ts +0 -0
- /package/{lib → dist}/handler/BarButtonEventHandler.js +0 -0
- /package/{lib → dist}/handler/DispatchCommandHandler.d.ts +0 -0
- /package/{lib → dist}/handler/DispatchCommandHandler.js +0 -0
- /package/{lib → dist}/handler/LayoutCommandHandler.d.ts +0 -0
- /package/{lib → dist}/handler/LayoutCommandHandler.js +0 -0
- /package/{lib → dist}/handler/ResultEventHandler.d.ts +0 -0
- /package/{lib → dist}/handler/ResultEventHandler.js +0 -0
- /package/{lib → dist}/handler/VisibilityEventHandler.d.ts +0 -0
- /package/{lib → dist}/handler/VisibilityEventHandler.js +0 -0
- /package/{lib → dist}/hooks.d.ts +0 -0
- /package/{lib → dist}/router/drawer.d.ts +0 -0
- /package/{lib → dist}/router/drawer.js +0 -0
- /package/{lib → dist}/router/index.d.ts +0 -0
- /package/{lib → dist}/router/screen.d.ts +0 -0
- /package/{lib → dist}/router/screen.js +0 -0
- /package/{lib → dist}/router/stack.d.ts +0 -0
- /package/{lib → dist}/router/tabs.d.ts +0 -0
- /package/{lib → dist}/router/tabs.js +0 -0
- /package/{lib → dist}/store.d.ts +0 -0
- /package/{lib → dist}/store.js +0 -0
package/src/DeepLink.ts
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {EmitterSubscription, Linking} from 'react-native';
|
|
2
|
+
import {router} from './router';
|
|
3
3
|
|
|
4
4
|
class DeepLinkImpl {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
private active = 0;
|
|
6
|
+
private uriPrefix = '';
|
|
7
|
+
private hasHandleInitialURL = false;
|
|
8
|
+
private subscription: EmitterSubscription | null = null;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
10
|
+
activate(uriPrefix: string) {
|
|
11
|
+
if (!uriPrefix) {
|
|
12
|
+
throw new Error('must pass `uriPrefix` when activate router.');
|
|
13
|
+
}
|
|
14
|
+
if (this.active === 0) {
|
|
15
|
+
this.uriPrefix = uriPrefix;
|
|
16
|
+
if (!this.hasHandleInitialURL) {
|
|
17
|
+
this.hasHandleInitialURL = true;
|
|
18
|
+
Linking.getInitialURL()
|
|
19
|
+
.then(url => {
|
|
20
|
+
if (url) {
|
|
21
|
+
console.info(`deeplink:${url}`);
|
|
22
|
+
const path = url.replace(this.uriPrefix, '');
|
|
23
|
+
return router.open(path);
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
.catch(err => console.error('An error occurred', err));
|
|
27
|
+
}
|
|
28
|
+
this.subscription = Linking.addEventListener('url', this.handleLinking);
|
|
29
|
+
}
|
|
30
|
+
this.active++;
|
|
31
|
+
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
deactivate() {
|
|
34
|
+
this.active--;
|
|
35
|
+
if (this.active === 0) {
|
|
36
|
+
if (this.subscription) {
|
|
37
|
+
this.subscription.remove();
|
|
38
|
+
this.subscription = null;
|
|
39
|
+
} else {
|
|
40
|
+
//@ts-ignore
|
|
41
|
+
Linking.removeEventListener('url', this.handleLinking);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
if (this.active < 0) {
|
|
46
|
+
this.active = 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
private handleLinking = (event: {url: string}) => {
|
|
51
|
+
console.info(`deeplink:${event.url}`);
|
|
52
|
+
let path = event.url.replace(this.uriPrefix, '');
|
|
53
|
+
if (!path.startsWith('/')) {
|
|
54
|
+
path = '/' + path;
|
|
55
|
+
}
|
|
56
|
+
router.open(path);
|
|
57
|
+
};
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
export const DeepLink = new DeepLinkImpl()
|
|
60
|
+
export const DeepLink = new DeepLinkImpl();
|
package/src/Event.ts
CHANGED
|
@@ -1,112 +1,117 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
1
|
+
import {NativeModules, NativeEventEmitter, NativeModule} from 'react-native';
|
|
2
|
+
import type {Visibility} from './Route';
|
|
3
3
|
interface HBDEventEmitter extends NativeModule {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
4
|
+
getConstants: () => {
|
|
5
|
+
EVENT_NAVIGATION: string;
|
|
6
|
+
EVENT_SWITCH_TAB: string;
|
|
7
|
+
EVENT_DID_SET_ROOT: string;
|
|
8
|
+
EVENT_WILL_SET_ROOT: string;
|
|
9
|
+
ON_COMPONENT_RESULT: string;
|
|
10
|
+
ON_BAR_BUTTON_ITEM_CLICK: string;
|
|
11
|
+
ON_COMPONENT_APPEAR: string;
|
|
12
|
+
ON_COMPONENT_DISAPPEAR: string;
|
|
13
|
+
KEY_REQUEST_CODE: string;
|
|
14
|
+
KEY_RESULT_CODE: string;
|
|
15
|
+
KEY_RESULT_DATA: string;
|
|
16
|
+
KEY_SCENE_ID: string;
|
|
17
|
+
KEY_MODULE_NAME: string;
|
|
18
|
+
KEY_INDEX: string;
|
|
19
|
+
KEY_ACTION: string;
|
|
20
|
+
KEY_ON: string;
|
|
21
|
+
};
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const HBDEventEmitter: HBDEventEmitter = NativeModules.HBDEventEmitter
|
|
25
|
-
const HBDEventReceiver = new NativeEventEmitter(HBDEventEmitter)
|
|
24
|
+
const HBDEventEmitter: HBDEventEmitter = NativeModules.HBDEventEmitter;
|
|
25
|
+
const HBDEventReceiver = new NativeEventEmitter(HBDEventEmitter);
|
|
26
26
|
|
|
27
27
|
function listenComponentResult(
|
|
28
|
-
|
|
28
|
+
listener: (
|
|
29
|
+
sceneId: string,
|
|
30
|
+
requestCode: number,
|
|
31
|
+
resultCode: number,
|
|
32
|
+
resultData: object,
|
|
33
|
+
) => void,
|
|
29
34
|
) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const {
|
|
36
|
+
EVENT_NAVIGATION,
|
|
37
|
+
KEY_ON,
|
|
38
|
+
ON_COMPONENT_RESULT,
|
|
39
|
+
KEY_REQUEST_CODE,
|
|
40
|
+
KEY_RESULT_CODE,
|
|
41
|
+
KEY_RESULT_DATA,
|
|
42
|
+
KEY_SCENE_ID,
|
|
43
|
+
} = HBDEventEmitter.getConstants();
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
return HBDEventReceiver.addListener(EVENT_NAVIGATION, data => {
|
|
46
|
+
if (data[KEY_ON] === ON_COMPONENT_RESULT) {
|
|
47
|
+
const requestCode = data[KEY_REQUEST_CODE];
|
|
48
|
+
const resultCode = data[KEY_RESULT_CODE];
|
|
49
|
+
const resultData = data[KEY_RESULT_DATA];
|
|
50
|
+
const sceneId = data[KEY_SCENE_ID];
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
listener(sceneId, requestCode, resultCode, resultData);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
function listenComponentVisibility(listener: (sceneId: string, visibility: Visibility) => void) {
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
const {EVENT_NAVIGATION, KEY_ON, ON_COMPONENT_APPEAR, ON_COMPONENT_DISAPPEAR, KEY_SCENE_ID} =
|
|
59
|
+
HBDEventEmitter.getConstants();
|
|
55
60
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
return HBDEventReceiver.addListener(EVENT_NAVIGATION, data => {
|
|
62
|
+
if (data[KEY_ON] === ON_COMPONENT_APPEAR) {
|
|
63
|
+
listener(data[KEY_SCENE_ID], 'visible');
|
|
64
|
+
}
|
|
60
65
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
if (data[KEY_ON] === ON_COMPONENT_DISAPPEAR) {
|
|
67
|
+
listener(data[KEY_SCENE_ID], 'invisible');
|
|
68
|
+
}
|
|
69
|
+
});
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
function listenBarButtonItemClick(listener: (sceneId: string, action: string) => void) {
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
const {EVENT_NAVIGATION, KEY_ON, ON_BAR_BUTTON_ITEM_CLICK, KEY_ACTION, KEY_SCENE_ID} =
|
|
74
|
+
HBDEventEmitter.getConstants();
|
|
70
75
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
return HBDEventReceiver.addListener(
|
|
77
|
+
EVENT_NAVIGATION,
|
|
78
|
+
data => {
|
|
79
|
+
if (data[KEY_ON] === ON_BAR_BUTTON_ITEM_CLICK) {
|
|
80
|
+
listener(data[KEY_SCENE_ID], data[KEY_ACTION]);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
{},
|
|
84
|
+
);
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
function listenTabSwitch(listener: (sceneId: string, from: number, to: number) => void) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
const {EVENT_SWITCH_TAB, KEY_INDEX, KEY_SCENE_ID} = HBDEventEmitter.getConstants();
|
|
89
|
+
return HBDEventReceiver.addListener(EVENT_SWITCH_TAB, event => {
|
|
90
|
+
const index = event[KEY_INDEX];
|
|
91
|
+
const [from, to] = index.split('-');
|
|
92
|
+
listener(event[KEY_SCENE_ID], parseInt(from, 10), parseInt(to, 10));
|
|
93
|
+
});
|
|
89
94
|
}
|
|
90
95
|
|
|
91
96
|
function listenWillSetRoot(willSetRoot: () => void) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
const {EVENT_WILL_SET_ROOT} = HBDEventEmitter.getConstants();
|
|
98
|
+
return HBDEventReceiver.addListener(EVENT_WILL_SET_ROOT, _ => {
|
|
99
|
+
willSetRoot();
|
|
100
|
+
});
|
|
96
101
|
}
|
|
97
102
|
|
|
98
103
|
function listenDidSetRoot(didSetRoot: (tag: number) => void) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
const {EVENT_DID_SET_ROOT} = HBDEventEmitter.getConstants();
|
|
105
|
+
return HBDEventReceiver.addListener(EVENT_DID_SET_ROOT, (event: {tag: number}) => {
|
|
106
|
+
didSetRoot(event.tag);
|
|
107
|
+
});
|
|
103
108
|
}
|
|
104
109
|
|
|
105
110
|
export default {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
111
|
+
listenBarButtonItemClick,
|
|
112
|
+
listenComponentResult,
|
|
113
|
+
listenComponentVisibility,
|
|
114
|
+
listenTabSwitch,
|
|
115
|
+
listenWillSetRoot,
|
|
116
|
+
listenDidSetRoot,
|
|
117
|
+
};
|
package/src/GardenModule.ts
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {NativeModules, NativeModule, NativeEventEmitter, Platform} from 'react-native';
|
|
2
2
|
|
|
3
3
|
interface GardenModule extends NativeModule {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
getConstants: () => {
|
|
5
|
+
TOOLBAR_HEIGHT: number;
|
|
6
|
+
STATUSBAR_HEIGHT: number;
|
|
7
|
+
EVENT_STATUSBAR_FRAME_CHANGE: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
setStyle: (style: object) => void;
|
|
11
|
+
setTitleItem: (sceneId: string, item: object) => void;
|
|
12
|
+
setLeftBarButtonItem: (sceneId: string, item: object | null) => void;
|
|
13
|
+
setRightBarButtonItem: (sceneId: string, item: object | null) => void;
|
|
14
|
+
setLeftBarButtonItems: (sceneId: string, item: object | null) => void;
|
|
15
|
+
setRightBarButtonItems: (sceneId: string, item: object | null) => void;
|
|
16
|
+
updateOptions: (sceneId: string, options: object) => void;
|
|
17
|
+
updateTabBar: (sceneId: string, item: object) => void;
|
|
18
|
+
setTabItem: (sceneId: string, item: object) => void;
|
|
19
|
+
setMenuInteractive: (sceneId: string, enabled: boolean) => void;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const GardenModule: GardenModule = NativeModules.GardenModule
|
|
22
|
+
const GardenModule: GardenModule = NativeModules.GardenModule;
|
|
23
23
|
|
|
24
|
-
const {
|
|
25
|
-
|
|
24
|
+
const {STATUSBAR_HEIGHT, TOOLBAR_HEIGHT, EVENT_STATUSBAR_FRAME_CHANGE} =
|
|
25
|
+
GardenModule.getConstants();
|
|
26
26
|
|
|
27
|
-
let _statusBarHeight = STATUSBAR_HEIGHT
|
|
27
|
+
let _statusBarHeight = STATUSBAR_HEIGHT;
|
|
28
28
|
|
|
29
29
|
if (Platform.OS === 'ios') {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const GardenEventReceiver = new NativeEventEmitter(GardenModule);
|
|
31
|
+
GardenEventReceiver.addListener(EVENT_STATUSBAR_FRAME_CHANGE, ({statusBarHeight: height}) => {
|
|
32
|
+
_statusBarHeight = height;
|
|
33
|
+
});
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
function statusBarHeight() {
|
|
37
|
-
|
|
37
|
+
return _statusBarHeight;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
function toolbarHeight() {
|
|
41
|
-
|
|
41
|
+
return TOOLBAR_HEIGHT;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
function topBarHeight() {
|
|
45
|
-
|
|
45
|
+
return statusBarHeight() + toolbarHeight();
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export {
|
|
48
|
+
export {statusBarHeight, toolbarHeight, topBarHeight};
|
|
49
49
|
|
|
50
|
-
export default GardenModule
|
|
50
|
+
export default GardenModule;
|