hybrid-navigation 2.12.2 → 2.13.0-beta.0
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 +63 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +2 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +1 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +29 -30
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +2 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +4 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +24 -33
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +22 -22
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +8 -8
- package/ios/HybridNavigation/GlobalStyle.h +0 -8
- package/ios/HybridNavigation/GlobalStyle.m +7 -15
- package/ios/HybridNavigation/HBDUtils.h +5 -13
- package/ios/HybridNavigation/HBDUtils.m +2 -12
- package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.m +91 -67
- package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.h +2 -7
- package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +28 -26
- package/ios/HybridNavigation/Navigator/HBDScreenNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDScreenNavigator.m +127 -99
- package/ios/HybridNavigation/Navigator/HBDStackNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +199 -142
- package/ios/HybridNavigation/Navigator/HBDTabNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDTabNavigator.m +144 -124
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.h +1 -11
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.m +4 -10
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +5 -0
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +128 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +6 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +237 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigator.h +20 -0
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.h +12 -20
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.m +91 -91
- package/ios/HybridNavigation/View/HBDBarButtonItem.h +0 -8
- package/ios/HybridNavigation/View/HBDBarButtonItem.m +1 -11
- package/ios/HybridNavigation/View/HBDNavigationBar.h +0 -8
- package/ios/HybridNavigation/View/HBDNavigationBar.m +13 -20
- package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -8
- package/ios/HybridNavigation/View/HBDReactTabBar.m +1 -8
- package/ios/HybridNavigation/View/HBDRootView.h +0 -9
- package/ios/HybridNavigation/View/HBDRootView.m +0 -8
- package/ios/HybridNavigation/View/HBDTitleView.h +0 -9
- package/ios/HybridNavigation/View/HBDTitleView.m +1 -26
- package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -8
- package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -7
- package/ios/HybridNavigation/ViewController/HBDDrawerController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDDrawerController.m +2 -9
- package/ios/HybridNavigation/ViewController/HBDFadeAnimation.h +9 -0
- package/ios/HybridNavigation/ViewController/HBDFadeAnimation.m +22 -0
- package/ios/HybridNavigation/ViewController/HBDNavigationController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDNavigationController.m +17 -120
- package/ios/HybridNavigation/ViewController/HBDPopAnimation.h +0 -7
- package/ios/HybridNavigation/ViewController/HBDPopAnimation.m +1 -8
- package/ios/HybridNavigation/ViewController/HBDPushAnimation.h +0 -7
- package/ios/HybridNavigation/ViewController/HBDPushAnimation.m +1 -8
- package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDReactViewController.m +59 -26
- package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDTabBarController.m +12 -9
- package/ios/HybridNavigation/ViewController/HBDViewController+Garden.m +23 -33
- package/ios/HybridNavigation/ViewController/HBDViewController.h +1 -8
- package/ios/HybridNavigation/ViewController/HBDViewController.m +6 -23
- package/ios/HybridNavigation/ViewController/UINavigationController+HBD.h +0 -8
- package/ios/HybridNavigation/ViewController/UINavigationController+HBD.m +0 -8
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +2 -16
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +32 -46
- package/lib/Navigator.d.ts +25 -25
- package/lib/Navigator.js +116 -73
- package/package.json +4 -5
- package/src/Navigator.ts +96 -58
- package/ios/HybridNavigation/Bridge/HBDGardenModule.h +0 -14
- package/ios/HybridNavigation/Bridge/HBDGardenModule.m +0 -155
- package/ios/HybridNavigation/Bridge/HBDNavigationModule.h +0 -15
- package/ios/HybridNavigation/Bridge/HBDNavigationModule.m +0 -272
- package/ios/HybridNavigation/Navigator/HBDNavigator.h +0 -26
package/lib/Navigator.js
CHANGED
|
@@ -56,7 +56,16 @@ export class Navigator {
|
|
|
56
56
|
return navigator;
|
|
57
57
|
}
|
|
58
58
|
static async find(moduleName) {
|
|
59
|
-
const sceneId = await
|
|
59
|
+
const sceneId = await new Promise((resolve, reject) => {
|
|
60
|
+
NavigationModule.findSceneIdByModuleName(moduleName, (error, id) => {
|
|
61
|
+
if (error) {
|
|
62
|
+
reject(error);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
resolve(id);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
60
69
|
if (sceneId) {
|
|
61
70
|
return Navigator.of(sceneId);
|
|
62
71
|
}
|
|
@@ -65,11 +74,29 @@ export class Navigator {
|
|
|
65
74
|
const route = await Navigator.currentRoute();
|
|
66
75
|
return Navigator.of(route.sceneId);
|
|
67
76
|
}
|
|
68
|
-
static
|
|
69
|
-
return
|
|
77
|
+
static currentRoute() {
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
NavigationModule.currentRoute((error, route) => {
|
|
80
|
+
if (error) {
|
|
81
|
+
reject(error);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
resolve(route);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
70
88
|
}
|
|
71
|
-
static
|
|
72
|
-
return
|
|
89
|
+
static routeGraph() {
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
NavigationModule.routeGraph((error, result) => {
|
|
92
|
+
if (error) {
|
|
93
|
+
reject(error);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
resolve(result);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
73
100
|
}
|
|
74
101
|
static setRoot(layout, sticky = false) {
|
|
75
102
|
const pureLayout = bindBarButtonItemClickEvent(layout, {
|
|
@@ -114,54 +141,47 @@ export class Navigator {
|
|
|
114
141
|
}
|
|
115
142
|
}
|
|
116
143
|
if (!intercepted) {
|
|
117
|
-
return
|
|
144
|
+
return new Promise((resolve, reject) => {
|
|
145
|
+
NavigationModule.dispatch(sceneId, action, params, (error, result) => {
|
|
146
|
+
if (error) {
|
|
147
|
+
reject(error);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
resolve(result);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
118
154
|
}
|
|
119
155
|
return false;
|
|
120
156
|
}
|
|
121
157
|
static setInterceptor(interceptFn) {
|
|
122
158
|
interceptor = interceptFn;
|
|
123
159
|
}
|
|
124
|
-
visibility = 'pending';
|
|
125
160
|
constructor(sceneId, moduleName) {
|
|
126
161
|
this.sceneId = sceneId;
|
|
127
162
|
this.moduleName = moduleName;
|
|
128
|
-
this.dispatch = this.dispatch.bind(this);
|
|
129
|
-
this.setParams = this.setParams.bind(this);
|
|
130
|
-
this.push = this.push.bind(this);
|
|
131
|
-
this.pop = this.pop.bind(this);
|
|
132
|
-
this.popTo = this.popTo.bind(this);
|
|
133
|
-
this.popToRoot = this.popToRoot.bind(this);
|
|
134
|
-
this.redirectTo = this.redirectTo.bind(this);
|
|
135
|
-
this.isStackRoot = this.isStackRoot.bind(this);
|
|
136
|
-
this.present = this.present.bind(this);
|
|
137
|
-
this.dismiss = this.dismiss.bind(this);
|
|
138
|
-
this.showModal = this.showModal.bind(this);
|
|
139
|
-
this.hideModal = this.hideModal.bind(this);
|
|
140
|
-
this.setResult = this.setResult.bind(this);
|
|
141
|
-
this.toggleMenu = this.toggleMenu.bind(this);
|
|
142
|
-
this.openMenu = this.openMenu.bind(this);
|
|
143
|
-
this.closeMenu = this.closeMenu.bind(this);
|
|
144
163
|
}
|
|
164
|
+
visibility = 'pending';
|
|
145
165
|
state = {
|
|
146
166
|
params: {},
|
|
147
167
|
};
|
|
148
|
-
setParams(params) {
|
|
168
|
+
setParams = (params) => {
|
|
149
169
|
this.state.params = { ...this.state.params, ...params };
|
|
150
|
-
}
|
|
151
|
-
dispatch(action, params = {}) {
|
|
170
|
+
};
|
|
171
|
+
dispatch = (action, params = {}) => {
|
|
152
172
|
return Navigator.dispatch(this.sceneId, action, {
|
|
153
173
|
from: this.moduleName,
|
|
154
174
|
to: params.moduleName,
|
|
155
175
|
...params,
|
|
156
176
|
});
|
|
157
|
-
}
|
|
158
|
-
result(resultCode, data) {
|
|
177
|
+
};
|
|
178
|
+
result = (resultCode, data) => {
|
|
159
179
|
if (this.resultListener) {
|
|
160
180
|
this.resultListener(resultCode, data);
|
|
161
181
|
this.resultListener = null;
|
|
162
182
|
}
|
|
163
|
-
}
|
|
164
|
-
unmount() {
|
|
183
|
+
};
|
|
184
|
+
unmount = () => {
|
|
165
185
|
const codes = [];
|
|
166
186
|
for (const [requestCode, listener] of resultListeners) {
|
|
167
187
|
if (listener.sceneId === this.sceneId) {
|
|
@@ -174,7 +194,7 @@ export class Navigator {
|
|
|
174
194
|
this.resultListener.cancel();
|
|
175
195
|
this.resultListener = null;
|
|
176
196
|
}
|
|
177
|
-
}
|
|
197
|
+
};
|
|
178
198
|
_garden;
|
|
179
199
|
get garden() {
|
|
180
200
|
if (!this._garden) {
|
|
@@ -207,34 +227,48 @@ export class Navigator {
|
|
|
207
227
|
}
|
|
208
228
|
});
|
|
209
229
|
}
|
|
210
|
-
async
|
|
230
|
+
push = async (moduleName, props = {}, options = {}) => {
|
|
211
231
|
const success = await this.dispatch('push', { moduleName, props, options });
|
|
232
|
+
console.log('push', success);
|
|
212
233
|
return await this.waitResult(0, success);
|
|
213
|
-
}
|
|
214
|
-
async
|
|
234
|
+
};
|
|
235
|
+
pushLayout = async (layout) => {
|
|
215
236
|
const success = await this.dispatch('pushLayout', { layout });
|
|
216
237
|
return await this.waitResult(0, success);
|
|
217
|
-
}
|
|
218
|
-
pop() {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
238
|
+
};
|
|
239
|
+
pop = async () => {
|
|
240
|
+
const success = await this.dispatch('pop');
|
|
241
|
+
console.log('pop', success);
|
|
242
|
+
return success;
|
|
243
|
+
};
|
|
244
|
+
popTo = (moduleName, inclusive = false) => {
|
|
222
245
|
return this.dispatch('popTo', { moduleName, inclusive });
|
|
223
|
-
}
|
|
224
|
-
popToRoot() {
|
|
246
|
+
};
|
|
247
|
+
popToRoot = () => {
|
|
225
248
|
return this.dispatch('popToRoot');
|
|
226
|
-
}
|
|
227
|
-
redirectTo(moduleName, props = {}, options = {}) {
|
|
228
|
-
|
|
249
|
+
};
|
|
250
|
+
redirectTo = async (moduleName, props = {}, options = {}) => {
|
|
251
|
+
const success = await this.dispatch('redirectTo', {
|
|
229
252
|
moduleName,
|
|
230
253
|
props,
|
|
231
254
|
options,
|
|
232
255
|
});
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
256
|
+
console.log('redirectTo', success);
|
|
257
|
+
return success;
|
|
258
|
+
};
|
|
259
|
+
isStackRoot = () => {
|
|
260
|
+
return new Promise((resolve, reject) => {
|
|
261
|
+
NavigationModule.isStackRoot(this.sceneId, (error, result) => {
|
|
262
|
+
if (error) {
|
|
263
|
+
reject(error);
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
resolve(result);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
present = async (moduleName, props = {}, options = {}) => {
|
|
238
272
|
const requestCode = --tag;
|
|
239
273
|
const success = await this.dispatch('present', {
|
|
240
274
|
moduleName,
|
|
@@ -243,16 +277,16 @@ export class Navigator {
|
|
|
243
277
|
requestCode,
|
|
244
278
|
});
|
|
245
279
|
return await this.waitResult(requestCode, success);
|
|
246
|
-
}
|
|
247
|
-
async
|
|
280
|
+
};
|
|
281
|
+
presentLayout = async (layout) => {
|
|
248
282
|
const requestCode = --tag;
|
|
249
283
|
const success = await this.dispatch('presentLayout', { layout, requestCode });
|
|
250
284
|
return await this.waitResult(requestCode, success);
|
|
251
|
-
}
|
|
252
|
-
dismiss() {
|
|
285
|
+
};
|
|
286
|
+
dismiss = () => {
|
|
253
287
|
return this.dispatch('dismiss');
|
|
254
|
-
}
|
|
255
|
-
async
|
|
288
|
+
};
|
|
289
|
+
showModal = async (moduleName, props = {}, options = {}) => {
|
|
256
290
|
const requestCode = --tag;
|
|
257
291
|
const success = await this.dispatch('showModal', {
|
|
258
292
|
moduleName,
|
|
@@ -261,32 +295,41 @@ export class Navigator {
|
|
|
261
295
|
requestCode,
|
|
262
296
|
});
|
|
263
297
|
return await this.waitResult(requestCode, success);
|
|
264
|
-
}
|
|
265
|
-
async
|
|
298
|
+
};
|
|
299
|
+
showModalLayout = async (layout) => {
|
|
266
300
|
const requestCode = --tag;
|
|
267
301
|
const success = await this.dispatch('showModalLayout', { layout, requestCode });
|
|
268
302
|
return await this.waitResult(requestCode, success);
|
|
269
|
-
}
|
|
270
|
-
hideModal() {
|
|
303
|
+
};
|
|
304
|
+
hideModal = () => {
|
|
271
305
|
return this.dispatch('hideModal');
|
|
272
|
-
}
|
|
273
|
-
setResult(resultCode, data = null) {
|
|
306
|
+
};
|
|
307
|
+
setResult = (resultCode, data = null) => {
|
|
274
308
|
NavigationModule.setResult(this.sceneId, resultCode, data);
|
|
275
|
-
}
|
|
276
|
-
async
|
|
277
|
-
const from = await
|
|
309
|
+
};
|
|
310
|
+
switchTab = async (index, popToRoot = false) => {
|
|
311
|
+
const from = await new Promise((resolve, reject) => {
|
|
312
|
+
NavigationModule.currentTab(this.sceneId, (error, result) => {
|
|
313
|
+
if (error) {
|
|
314
|
+
reject(error);
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
resolve(result);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
});
|
|
278
321
|
return this.dispatch('switchTab', { from, to: index, popToRoot });
|
|
279
|
-
}
|
|
280
|
-
toggleMenu() {
|
|
322
|
+
};
|
|
323
|
+
toggleMenu = () => {
|
|
281
324
|
return this.dispatch('toggleMenu');
|
|
282
|
-
}
|
|
283
|
-
openMenu() {
|
|
325
|
+
};
|
|
326
|
+
openMenu = () => {
|
|
284
327
|
return this.dispatch('openMenu');
|
|
285
|
-
}
|
|
286
|
-
closeMenu() {
|
|
328
|
+
};
|
|
329
|
+
closeMenu = () => {
|
|
287
330
|
return this.dispatch('closeMenu');
|
|
288
|
-
}
|
|
289
|
-
signalFirstRenderComplete() {
|
|
331
|
+
};
|
|
332
|
+
signalFirstRenderComplete = () => {
|
|
290
333
|
NavigationModule.signalFirstRenderComplete(this.sceneId);
|
|
291
|
-
}
|
|
334
|
+
};
|
|
292
335
|
}
|
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.13.0-beta.0",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"typings": "./lib/index.d.ts",
|
|
7
7
|
"react-native": "src/index",
|
|
@@ -32,9 +32,8 @@
|
|
|
32
32
|
"build": "rm -rf ./lib && tsc -p tsconfig.build.json",
|
|
33
33
|
"prepare": "npm run build",
|
|
34
34
|
"start": "react-native start --reset-cache",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"run:android": "cd example/android && ./gradlew installDebug && npm run start:android",
|
|
35
|
+
"android": "react-native run-android",
|
|
36
|
+
"ios": "react-native run-ios",
|
|
38
37
|
"test": "jest",
|
|
39
38
|
"tsc": "tsc",
|
|
40
39
|
"lint": "eslint . --fix --ext .js,.jsx,.ts,.tsx",
|
|
@@ -71,7 +70,7 @@
|
|
|
71
70
|
"react-test-renderer": "17.0.2",
|
|
72
71
|
"redux": "^4.1.1",
|
|
73
72
|
"typescript": "^4.6.4",
|
|
74
|
-
"vuepress": "^2.0.0-beta.
|
|
73
|
+
"vuepress": "^2.0.0-beta.49",
|
|
75
74
|
"zustand": "^3.7.1"
|
|
76
75
|
}
|
|
77
76
|
}
|
package/src/Navigator.ts
CHANGED
|
@@ -109,7 +109,16 @@ export class Navigator {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
static async find(moduleName: string) {
|
|
112
|
-
const sceneId = await
|
|
112
|
+
const sceneId = await new Promise<string>((resolve, reject) => {
|
|
113
|
+
NavigationModule.findSceneIdByModuleName(moduleName, (error: never, id: string) => {
|
|
114
|
+
if (error) {
|
|
115
|
+
reject(error)
|
|
116
|
+
} else {
|
|
117
|
+
resolve(id)
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
113
122
|
if (sceneId) {
|
|
114
123
|
return Navigator.of(sceneId)
|
|
115
124
|
}
|
|
@@ -120,12 +129,28 @@ export class Navigator {
|
|
|
120
129
|
return Navigator.of(route.sceneId)
|
|
121
130
|
}
|
|
122
131
|
|
|
123
|
-
static
|
|
124
|
-
return
|
|
132
|
+
static currentRoute(): Promise<Route> {
|
|
133
|
+
return new Promise<Route>((resolve, reject) => {
|
|
134
|
+
NavigationModule.currentRoute((error: never, route: Route) => {
|
|
135
|
+
if (error) {
|
|
136
|
+
reject(error)
|
|
137
|
+
} else {
|
|
138
|
+
resolve(route)
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
})
|
|
125
142
|
}
|
|
126
143
|
|
|
127
|
-
static
|
|
128
|
-
return
|
|
144
|
+
static routeGraph(): Promise<RouteGraph[]> {
|
|
145
|
+
return new Promise<RouteGraph[]>((resolve, reject) => {
|
|
146
|
+
NavigationModule.routeGraph((error: never, result: RouteGraph[]) => {
|
|
147
|
+
if (error) {
|
|
148
|
+
reject(error)
|
|
149
|
+
} else {
|
|
150
|
+
resolve(result)
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
})
|
|
129
154
|
}
|
|
130
155
|
|
|
131
156
|
static setRoot(layout: BuildInLayout | Layout, sticky = false) {
|
|
@@ -175,7 +200,15 @@ export class Navigator {
|
|
|
175
200
|
}
|
|
176
201
|
|
|
177
202
|
if (!intercepted) {
|
|
178
|
-
return
|
|
203
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
204
|
+
NavigationModule.dispatch(sceneId, action, params, (error: never, result: boolean) => {
|
|
205
|
+
if (error) {
|
|
206
|
+
reject(error)
|
|
207
|
+
} else {
|
|
208
|
+
resolve(result)
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
})
|
|
179
212
|
}
|
|
180
213
|
|
|
181
214
|
return false
|
|
@@ -185,39 +218,19 @@ export class Navigator {
|
|
|
185
218
|
interceptor = interceptFn
|
|
186
219
|
}
|
|
187
220
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
constructor(public sceneId: string, public moduleName?: string) {
|
|
191
|
-
this.dispatch = this.dispatch.bind(this)
|
|
192
|
-
this.setParams = this.setParams.bind(this)
|
|
221
|
+
constructor(public sceneId: string, public moduleName?: string) {}
|
|
193
222
|
|
|
194
|
-
|
|
195
|
-
this.pop = this.pop.bind(this)
|
|
196
|
-
this.popTo = this.popTo.bind(this)
|
|
197
|
-
this.popToRoot = this.popToRoot.bind(this)
|
|
198
|
-
this.redirectTo = this.redirectTo.bind(this)
|
|
199
|
-
this.isStackRoot = this.isStackRoot.bind(this)
|
|
200
|
-
|
|
201
|
-
this.present = this.present.bind(this)
|
|
202
|
-
this.dismiss = this.dismiss.bind(this)
|
|
203
|
-
this.showModal = this.showModal.bind(this)
|
|
204
|
-
this.hideModal = this.hideModal.bind(this)
|
|
205
|
-
this.setResult = this.setResult.bind(this)
|
|
206
|
-
|
|
207
|
-
this.toggleMenu = this.toggleMenu.bind(this)
|
|
208
|
-
this.openMenu = this.openMenu.bind(this)
|
|
209
|
-
this.closeMenu = this.closeMenu.bind(this)
|
|
210
|
-
}
|
|
223
|
+
visibility: Visibility = 'pending'
|
|
211
224
|
|
|
212
225
|
readonly state: NavigationState = {
|
|
213
226
|
params: {},
|
|
214
227
|
}
|
|
215
228
|
|
|
216
|
-
setParams(params: { [index: string]: any }) {
|
|
229
|
+
setParams = (params: { [index: string]: any }) => {
|
|
217
230
|
this.state.params = { ...this.state.params, ...params }
|
|
218
231
|
}
|
|
219
232
|
|
|
220
|
-
dispatch(action: string, params: Params = {}) {
|
|
233
|
+
dispatch = (action: string, params: Params = {}) => {
|
|
221
234
|
return Navigator.dispatch(this.sceneId, action, {
|
|
222
235
|
from: this.moduleName,
|
|
223
236
|
to: params.moduleName,
|
|
@@ -225,14 +238,14 @@ export class Navigator {
|
|
|
225
238
|
})
|
|
226
239
|
}
|
|
227
240
|
|
|
228
|
-
result(resultCode: number, data: ResultType) {
|
|
241
|
+
result = (resultCode: number, data: ResultType) => {
|
|
229
242
|
if (this.resultListener) {
|
|
230
243
|
this.resultListener(resultCode, data)
|
|
231
244
|
this.resultListener = null
|
|
232
245
|
}
|
|
233
246
|
}
|
|
234
247
|
|
|
235
|
-
unmount() {
|
|
248
|
+
unmount = () => {
|
|
236
249
|
const codes: number[] = []
|
|
237
250
|
for (const [requestCode, listener] of resultListeners) {
|
|
238
251
|
if (listener.sceneId === this.sceneId) {
|
|
@@ -288,49 +301,66 @@ export class Navigator {
|
|
|
288
301
|
})
|
|
289
302
|
}
|
|
290
303
|
|
|
291
|
-
async
|
|
304
|
+
push = async <T extends ResultType, P extends PropsType = PropsType>(
|
|
292
305
|
moduleName: string,
|
|
293
306
|
props: P = {} as any,
|
|
294
307
|
options: NavigationItem = {},
|
|
295
|
-
) {
|
|
308
|
+
) => {
|
|
296
309
|
const success = await this.dispatch('push', { moduleName, props, options })
|
|
310
|
+
console.log('push', success)
|
|
297
311
|
return await this.waitResult<T>(0, success)
|
|
298
312
|
}
|
|
299
313
|
|
|
300
|
-
async
|
|
314
|
+
pushLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
|
|
301
315
|
const success = await this.dispatch('pushLayout', { layout })
|
|
302
316
|
return await this.waitResult<T>(0, success)
|
|
303
317
|
}
|
|
304
318
|
|
|
305
|
-
pop() {
|
|
306
|
-
|
|
319
|
+
pop = async () => {
|
|
320
|
+
const success = await this.dispatch('pop')
|
|
321
|
+
console.log('pop', success)
|
|
322
|
+
return success
|
|
307
323
|
}
|
|
308
324
|
|
|
309
|
-
popTo(moduleName: string, inclusive: boolean = false) {
|
|
325
|
+
popTo = (moduleName: string, inclusive: boolean = false) => {
|
|
310
326
|
return this.dispatch('popTo', { moduleName, inclusive })
|
|
311
327
|
}
|
|
312
328
|
|
|
313
|
-
popToRoot() {
|
|
329
|
+
popToRoot = () => {
|
|
314
330
|
return this.dispatch('popToRoot')
|
|
315
331
|
}
|
|
316
332
|
|
|
317
|
-
redirectTo<P extends PropsType = PropsType>(
|
|
318
|
-
|
|
333
|
+
redirectTo = async <P extends PropsType = PropsType>(
|
|
334
|
+
moduleName: string,
|
|
335
|
+
props: P = {} as any,
|
|
336
|
+
options: NavigationItem = {},
|
|
337
|
+
) => {
|
|
338
|
+
const success = await this.dispatch('redirectTo', {
|
|
319
339
|
moduleName,
|
|
320
340
|
props,
|
|
321
341
|
options,
|
|
322
342
|
})
|
|
343
|
+
console.log('redirectTo', success)
|
|
344
|
+
return success
|
|
323
345
|
}
|
|
324
346
|
|
|
325
|
-
isStackRoot()
|
|
326
|
-
return
|
|
347
|
+
isStackRoot = () => {
|
|
348
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
349
|
+
NavigationModule.isStackRoot(this.sceneId, (error: never, result: boolean) => {
|
|
350
|
+
if (error) {
|
|
351
|
+
reject(error)
|
|
352
|
+
} else {
|
|
353
|
+
resolve(result)
|
|
354
|
+
}
|
|
355
|
+
})
|
|
356
|
+
})
|
|
327
357
|
}
|
|
328
358
|
|
|
329
|
-
async
|
|
359
|
+
present = async <T extends ResultType, P extends PropsType = PropsType>(
|
|
330
360
|
moduleName: string,
|
|
331
361
|
props: P = {} as any,
|
|
332
362
|
options: NavigationItem = {},
|
|
333
|
-
) {
|
|
363
|
+
) => {
|
|
334
364
|
const requestCode = --tag
|
|
335
365
|
const success = await this.dispatch('present', {
|
|
336
366
|
moduleName,
|
|
@@ -341,21 +371,21 @@ export class Navigator {
|
|
|
341
371
|
return await this.waitResult<T>(requestCode, success)
|
|
342
372
|
}
|
|
343
373
|
|
|
344
|
-
async
|
|
374
|
+
presentLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
|
|
345
375
|
const requestCode = --tag
|
|
346
376
|
const success = await this.dispatch('presentLayout', { layout, requestCode })
|
|
347
377
|
return await this.waitResult<T>(requestCode, success)
|
|
348
378
|
}
|
|
349
379
|
|
|
350
|
-
dismiss() {
|
|
380
|
+
dismiss = () => {
|
|
351
381
|
return this.dispatch('dismiss')
|
|
352
382
|
}
|
|
353
383
|
|
|
354
|
-
async
|
|
384
|
+
showModal = async <T extends ResultType, P extends PropsType = PropsType>(
|
|
355
385
|
moduleName: string,
|
|
356
386
|
props: P = {} as any,
|
|
357
387
|
options: NavigationItem = {},
|
|
358
|
-
) {
|
|
388
|
+
) => {
|
|
359
389
|
const requestCode = --tag
|
|
360
390
|
const success = await this.dispatch('showModal', {
|
|
361
391
|
moduleName,
|
|
@@ -366,38 +396,46 @@ export class Navigator {
|
|
|
366
396
|
return await this.waitResult<T>(requestCode, success)
|
|
367
397
|
}
|
|
368
398
|
|
|
369
|
-
async
|
|
399
|
+
showModalLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
|
|
370
400
|
const requestCode = --tag
|
|
371
401
|
const success = await this.dispatch('showModalLayout', { layout, requestCode })
|
|
372
402
|
return await this.waitResult<T>(requestCode, success)
|
|
373
403
|
}
|
|
374
404
|
|
|
375
|
-
hideModal() {
|
|
405
|
+
hideModal = () => {
|
|
376
406
|
return this.dispatch('hideModal')
|
|
377
407
|
}
|
|
378
408
|
|
|
379
|
-
setResult<T extends ResultType>(resultCode: number, data: T = null as any): void {
|
|
409
|
+
setResult = <T extends ResultType>(resultCode: number, data: T = null as any): void => {
|
|
380
410
|
NavigationModule.setResult(this.sceneId, resultCode, data)
|
|
381
411
|
}
|
|
382
412
|
|
|
383
|
-
async
|
|
384
|
-
const from = await
|
|
413
|
+
switchTab = async (index: number, popToRoot: boolean = false) => {
|
|
414
|
+
const from = await new Promise<number>((resolve, reject) => {
|
|
415
|
+
NavigationModule.currentTab(this.sceneId, (error: never, result: number) => {
|
|
416
|
+
if (error) {
|
|
417
|
+
reject(error)
|
|
418
|
+
} else {
|
|
419
|
+
resolve(result)
|
|
420
|
+
}
|
|
421
|
+
})
|
|
422
|
+
})
|
|
385
423
|
return this.dispatch('switchTab', { from, to: index, popToRoot })
|
|
386
424
|
}
|
|
387
425
|
|
|
388
|
-
toggleMenu() {
|
|
426
|
+
toggleMenu = () => {
|
|
389
427
|
return this.dispatch('toggleMenu')
|
|
390
428
|
}
|
|
391
429
|
|
|
392
|
-
openMenu() {
|
|
430
|
+
openMenu = () => {
|
|
393
431
|
return this.dispatch('openMenu')
|
|
394
432
|
}
|
|
395
433
|
|
|
396
|
-
closeMenu() {
|
|
434
|
+
closeMenu = () => {
|
|
397
435
|
return this.dispatch('closeMenu')
|
|
398
436
|
}
|
|
399
437
|
|
|
400
|
-
signalFirstRenderComplete()
|
|
438
|
+
signalFirstRenderComplete = () => {
|
|
401
439
|
NavigationModule.signalFirstRenderComplete(this.sceneId)
|
|
402
440
|
}
|
|
403
441
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// HBDGardenModule.h
|
|
3
|
-
// HybridNavigation
|
|
4
|
-
//
|
|
5
|
-
// Created by Listen on 2017/11/26.
|
|
6
|
-
// Copyright © 2018年 Listen. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#import <Foundation/Foundation.h>
|
|
10
|
-
#import <React/RCTBridgeModule.h>
|
|
11
|
-
|
|
12
|
-
@interface HBDGardenModule : NSObject <RCTBridgeModule>
|
|
13
|
-
|
|
14
|
-
@end
|