hybrid-navigation 2.18.3 → 2.18.5
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/HBDReactRootView.java +4 -54
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +0 -3
- package/{lib → dist}/Navigation.js +3 -2
- package/{lib → dist}/NavigationComponentWrap.js +6 -5
- package/{lib → dist}/Navigator.d.ts +0 -1
- package/{lib → dist}/Navigator.js +15 -4
- package/{lib → dist}/hooks.js +2 -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 +11 -12
- 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 -281
- package/src/NavigationComponentWrap.tsx +52 -47
- package/src/NavigationModule.ts +77 -77
- 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}/Navigation.d.ts +0 -0
- /package/{lib → dist}/NavigationComponentWrap.d.ts +0 -0
- /package/{lib → dist}/NavigationModule.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}/index.d.ts +0 -0
- /package/{lib → dist}/index.js +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/Navigator.ts
CHANGED
|
@@ -1,219 +1,230 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {createContext} from 'react';
|
|
2
2
|
|
|
3
|
-
import store from './store'
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import Navigation, {
|
|
3
|
+
import store from './store';
|
|
4
|
+
import type {Visibility, Layout, BuildInLayout} from './Route';
|
|
5
|
+
import type {NavigationItem} from './Options';
|
|
6
|
+
import Navigation, {ResultType, RESULT_BLOCK} from './Navigation';
|
|
7
7
|
|
|
8
|
-
export const NavigationContext = createContext<any>(null)
|
|
8
|
+
export const NavigationContext = createContext<any>(null);
|
|
9
9
|
|
|
10
10
|
interface NavigationState {
|
|
11
|
-
|
|
11
|
+
params: {readonly [index: string]: any};
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
interface PropsType {
|
|
15
|
-
|
|
15
|
+
[index: string]: any;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
let tagGenerator = 0
|
|
18
|
+
let tagGenerator = 0;
|
|
19
19
|
|
|
20
20
|
Navigation.addGlobalVisibilityEventListener((sceneId: string, visibility: Visibility) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})
|
|
21
|
+
const navigator = store.getNavigator(sceneId);
|
|
22
|
+
if (navigator) {
|
|
23
|
+
navigator.visibility = visibility;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
26
|
|
|
27
27
|
Navigation.setBarButtonClickEventListener((sceneId, value) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
})
|
|
28
|
+
const navigator = Navigator.of(sceneId);
|
|
29
|
+
value(navigator);
|
|
30
|
+
});
|
|
31
31
|
|
|
32
32
|
export interface Navigator {}
|
|
33
33
|
|
|
34
34
|
export class Navigator implements Navigator {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
35
|
+
static of(sceneId: string) {
|
|
36
|
+
let navigator = store.getNavigator(sceneId);
|
|
37
|
+
if (!navigator) {
|
|
38
|
+
navigator = new Navigator(sceneId);
|
|
39
|
+
store.addNavigator(sceneId, navigator);
|
|
40
|
+
}
|
|
41
|
+
return navigator;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static unmount = (sceneId: string) => {
|
|
45
|
+
store.removeNavigator(sceneId);
|
|
46
|
+
Navigation.unmount(sceneId);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
static async find(moduleName: string) {
|
|
50
|
+
const sceneId = await Navigation.findSceneIdByModuleName(moduleName);
|
|
51
|
+
if (sceneId) {
|
|
52
|
+
return Navigator.of(sceneId);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static async current(): Promise<Navigator> {
|
|
57
|
+
const route = await Navigation.currentRoute();
|
|
58
|
+
return Navigator.of(route.sceneId);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
constructor(public sceneId: string, public moduleName?: string) {}
|
|
62
|
+
|
|
63
|
+
visibility: Visibility = 'pending';
|
|
64
|
+
|
|
65
|
+
readonly state: NavigationState = {
|
|
66
|
+
params: {},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
setParams = (params: {[index: string]: any}) => {
|
|
70
|
+
this.state.params = {...this.state.params, ...params};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
push = async <T extends ResultType, P extends PropsType = {}>(
|
|
74
|
+
moduleName: string,
|
|
75
|
+
props: P = {} as P,
|
|
76
|
+
options: NavigationItem = {},
|
|
77
|
+
) => {
|
|
78
|
+
const success = await Navigation.dispatch(this.sceneId, 'push', {
|
|
79
|
+
moduleName,
|
|
80
|
+
from: this.moduleName,
|
|
81
|
+
to: moduleName,
|
|
82
|
+
props,
|
|
83
|
+
options,
|
|
84
|
+
});
|
|
85
|
+
if (!success) {
|
|
86
|
+
return [RESULT_BLOCK, null] as [number, T];
|
|
87
|
+
}
|
|
88
|
+
return Navigation.result<T>(this.sceneId, 0);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
pushLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
|
|
92
|
+
const success = await Navigation.dispatch(this.sceneId, 'pushLayout', {
|
|
93
|
+
from: this.moduleName,
|
|
94
|
+
layout,
|
|
95
|
+
});
|
|
96
|
+
if (!success) {
|
|
97
|
+
return [RESULT_BLOCK, null] as [number, T];
|
|
98
|
+
}
|
|
99
|
+
return Navigation.result<T>(this.sceneId, 0);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
pop = () => Navigation.dispatch(this.sceneId, 'pop', {from: this.moduleName});
|
|
103
|
+
|
|
104
|
+
popTo = (moduleName: string, inclusive: boolean = false) =>
|
|
105
|
+
Navigation.dispatch(this.sceneId, 'popTo', {
|
|
106
|
+
moduleName,
|
|
107
|
+
inclusive,
|
|
108
|
+
from: this.moduleName,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot', {from: this.moduleName});
|
|
112
|
+
|
|
113
|
+
redirectTo = <P extends PropsType>(
|
|
114
|
+
moduleName: string,
|
|
115
|
+
props: P = {} as P,
|
|
116
|
+
options: NavigationItem = {},
|
|
117
|
+
) =>
|
|
118
|
+
Navigation.dispatch(this.sceneId, 'redirectTo', {
|
|
119
|
+
moduleName,
|
|
120
|
+
from: this.moduleName,
|
|
121
|
+
to: moduleName,
|
|
122
|
+
props,
|
|
123
|
+
options,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
present = async <T extends ResultType, P extends PropsType = {}>(
|
|
127
|
+
moduleName: string,
|
|
128
|
+
props: P = {} as P,
|
|
129
|
+
options: NavigationItem = {},
|
|
130
|
+
) => {
|
|
131
|
+
const requestCode = --tagGenerator;
|
|
132
|
+
const success = await Navigation.dispatch(this.sceneId, 'present', {
|
|
133
|
+
moduleName,
|
|
134
|
+
from: this.moduleName,
|
|
135
|
+
to: moduleName,
|
|
136
|
+
props,
|
|
137
|
+
options,
|
|
138
|
+
requestCode,
|
|
139
|
+
});
|
|
140
|
+
if (!success) {
|
|
141
|
+
console.warn(
|
|
142
|
+
`present from:${this.moduleName} to:${moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`,
|
|
143
|
+
);
|
|
144
|
+
return [RESULT_BLOCK, null] as [number, T];
|
|
145
|
+
}
|
|
146
|
+
return Navigation.result<T>(this.sceneId, requestCode);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
presentLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
|
|
150
|
+
const requestCode = --tagGenerator;
|
|
151
|
+
const success = await Navigation.dispatch(this.sceneId, 'presentLayout', {
|
|
152
|
+
layout,
|
|
153
|
+
from: this.moduleName,
|
|
154
|
+
requestCode,
|
|
155
|
+
});
|
|
156
|
+
if (!success) {
|
|
157
|
+
console.warn(
|
|
158
|
+
`presentLayout from:${this.moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`,
|
|
159
|
+
);
|
|
160
|
+
return [RESULT_BLOCK, null] as [number, T];
|
|
161
|
+
}
|
|
162
|
+
return Navigation.result<T>(this.sceneId, requestCode);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss', {from: this.moduleName});
|
|
166
|
+
|
|
167
|
+
showModal = async <T extends ResultType, P extends PropsType = {}>(
|
|
168
|
+
moduleName: string,
|
|
169
|
+
props: P = {} as P,
|
|
170
|
+
options: NavigationItem = {},
|
|
171
|
+
) => {
|
|
172
|
+
const requestCode = --tagGenerator;
|
|
173
|
+
const success = await Navigation.dispatch(this.sceneId, 'showModal', {
|
|
174
|
+
moduleName,
|
|
175
|
+
from: this.moduleName,
|
|
176
|
+
to: moduleName,
|
|
177
|
+
props,
|
|
178
|
+
options,
|
|
179
|
+
requestCode,
|
|
180
|
+
});
|
|
181
|
+
if (!success) {
|
|
182
|
+
console.warn(
|
|
183
|
+
`showModal from:${this.moduleName} to:${moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`,
|
|
184
|
+
);
|
|
185
|
+
return [RESULT_BLOCK, null] as [number, T];
|
|
186
|
+
}
|
|
187
|
+
return Navigation.result<T>(this.sceneId, requestCode);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
showModalLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
|
|
191
|
+
const requestCode = --tagGenerator;
|
|
192
|
+
const success = await Navigation.dispatch(this.sceneId, 'showModalLayout', {
|
|
193
|
+
from: this.moduleName,
|
|
194
|
+
layout,
|
|
195
|
+
requestCode,
|
|
196
|
+
});
|
|
197
|
+
if (!success) {
|
|
198
|
+
console.warn(
|
|
199
|
+
`showModal from:${this.moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`,
|
|
200
|
+
);
|
|
201
|
+
return [RESULT_BLOCK, null] as [number, T];
|
|
202
|
+
}
|
|
203
|
+
return Navigation.result<T>(this.sceneId, requestCode);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal', {from: this.moduleName});
|
|
207
|
+
|
|
208
|
+
setResult = <T extends ResultType>(resultCode: number, data: T = null as any): void =>
|
|
209
|
+
Navigation.setResult(this.sceneId, resultCode, data);
|
|
210
|
+
|
|
211
|
+
switchTab = async (index: number, popToRoot: boolean = false) => {
|
|
212
|
+
const from = await Navigation.currentTab(this.sceneId);
|
|
213
|
+
return Navigation.dispatch(this.sceneId, 'switchTab', {
|
|
214
|
+
from,
|
|
215
|
+
to: index,
|
|
216
|
+
popToRoot,
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
toggleMenu = () =>
|
|
221
|
+
Navigation.dispatch(this.sceneId, 'toggleMenu', {
|
|
222
|
+
from: this.moduleName,
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu', {from: this.moduleName});
|
|
226
|
+
|
|
227
|
+
closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', {from: this.moduleName});
|
|
228
|
+
|
|
229
|
+
isStackRoot = () => Navigation.isStackRoot(this.sceneId);
|
|
219
230
|
}
|