hybrid-navigation 2.13.0-beta.2 → 2.13.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/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +3 -20
- package/ios/HybridNavigation/HBDUtils.h +3 -6
- package/ios/HybridNavigation/HBDUtils.m +10 -0
- package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +7 -2
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +1 -1
- package/ios/HybridNavigation/View/HBDRootView.m +9 -3
- package/ios/HybridNavigation/ViewController/HBDNavigationController.m +0 -30
- package/ios/HybridNavigation/ViewController/HBDViewController.m +7 -3
- package/ios/HybridNavigation/ViewController/UINavigationController+HBD.m +0 -3
- package/lib/Event.d.ts +18 -0
- package/lib/Event.js +71 -0
- package/lib/Garden.d.ts +46 -68
- package/lib/Garden.js +53 -70
- package/lib/GardenModule.d.ts +20 -0
- package/lib/GardenModule.js +3 -0
- package/lib/Navigation.d.ts +74 -0
- package/lib/Navigation.js +182 -0
- package/lib/NavigationComponentWrap.d.ts +19 -0
- package/lib/NavigationComponentWrap.js +46 -0
- package/lib/NavigationModule.d.ts +33 -22
- package/lib/NavigationModule.js +79 -22
- package/lib/Navigator.d.ts +55 -28
- package/lib/Navigator.js +122 -263
- package/lib/{typing.d.ts → Options.d.ts} +46 -50
- package/lib/{typing.js → Options.js} +0 -0
- package/lib/ReactRegistry.d.ts +16 -14
- package/lib/ReactRegistry.js +18 -93
- package/lib/Route.d.ts +74 -0
- package/lib/{router/typing.js → Route.js} +0 -0
- package/lib/handler/BarButtonEventHandler.d.ts +10 -0
- package/lib/handler/BarButtonEventHandler.js +38 -0
- package/lib/handler/DispatchCommandHandler.d.ts +24 -0
- package/lib/handler/DispatchCommandHandler.js +28 -0
- package/lib/handler/LayoutCommandHandler.d.ts +11 -0
- package/lib/handler/LayoutCommandHandler.js +39 -0
- package/lib/handler/ResultEventHandler.d.ts +15 -0
- package/lib/handler/ResultEventHandler.js +47 -0
- package/lib/handler/VisibilityEventHandler.d.ts +13 -0
- package/lib/handler/VisibilityEventHandler.js +32 -0
- package/lib/hooks.d.ts +0 -1
- package/lib/hooks.js +14 -29
- package/lib/index.d.ts +10 -2
- package/lib/index.js +17 -2
- package/lib/router/drawer.d.ts +1 -1
- package/lib/router/index.d.ts +4 -7
- package/lib/router/index.js +13 -6
- package/lib/router/screen.d.ts +1 -1
- package/lib/router/stack.d.ts +1 -1
- package/lib/router/tabs.d.ts +1 -1
- package/lib/store.d.ts +0 -9
- package/lib/store.js +0 -22
- package/package.json +1 -1
- package/src/Event.ts +123 -0
- package/src/Garden.ts +63 -149
- package/src/GardenModule.ts +24 -0
- package/src/Navigation.ts +278 -0
- package/src/NavigationComponentWrap.tsx +73 -0
- package/src/NavigationModule.ts +118 -29
- package/src/Navigator.ts +147 -319
- package/src/{typing.ts → Options.ts} +51 -57
- package/src/ReactRegistry.tsx +25 -127
- package/src/Route.ts +88 -0
- package/src/handler/BarButtonEventHandler.ts +50 -0
- package/src/handler/DispatchCommandHandler.ts +56 -0
- package/src/handler/LayoutCommandHandler.ts +49 -0
- package/src/handler/ResultEventHandler.ts +67 -0
- package/src/handler/VisibilityEventHandler.ts +44 -0
- package/src/hooks.ts +13 -38
- package/src/index.ts +38 -3
- package/src/router/drawer.ts +1 -1
- package/src/router/index.ts +36 -12
- package/src/router/screen.ts +1 -1
- package/src/router/stack.ts +1 -1
- package/src/router/tabs.ts +1 -1
- package/src/store.ts +0 -28
- package/lib/router/typing.d.ts +0 -37
- package/lib/utils.d.ts +0 -9
- package/lib/utils.js +0 -50
- package/src/router/typing.ts +0 -45
- package/src/utils.ts +0 -83
package/src/Navigator.ts
CHANGED
|
@@ -1,104 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
NavigationModule,
|
|
4
|
-
EVENT_WILL_SET_ROOT,
|
|
5
|
-
EVENT_DID_SET_ROOT,
|
|
6
|
-
EVENT_SWITCH_TAB,
|
|
7
|
-
KEY_SCENE_ID,
|
|
8
|
-
KEY_INDEX,
|
|
9
|
-
RESULT_CANCEL,
|
|
10
|
-
EVENT_NAVIGATION,
|
|
11
|
-
KEY_ON,
|
|
12
|
-
ON_COMPONENT_RESULT,
|
|
13
|
-
KEY_REQUEST_CODE,
|
|
14
|
-
KEY_RESULT_CODE,
|
|
15
|
-
KEY_RESULT_DATA,
|
|
16
|
-
} from './NavigationModule'
|
|
17
|
-
import { bindBarButtonItemClickEvent } from './utils'
|
|
1
|
+
import { createContext } from 'react'
|
|
2
|
+
|
|
18
3
|
import store from './store'
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
IndexType,
|
|
23
|
-
ResultType,
|
|
24
|
-
NavigationInterceptor,
|
|
25
|
-
Layout,
|
|
26
|
-
BuildInLayout,
|
|
27
|
-
NavigationItem,
|
|
28
|
-
PropsType,
|
|
29
|
-
} from './typing'
|
|
4
|
+
import type { Visibility, Layout, BuildInLayout, Route, RouteGraph } from './Route'
|
|
5
|
+
import type { NavigationItem } from './Options'
|
|
30
6
|
import { Garden } from './Garden'
|
|
7
|
+
import Navigation, {
|
|
8
|
+
NavigationInterceptor,
|
|
9
|
+
DispatchParams,
|
|
10
|
+
ResultType,
|
|
11
|
+
RESULT_CANCEL,
|
|
12
|
+
} from './Navigation'
|
|
31
13
|
|
|
32
|
-
|
|
33
|
-
animated?: boolean
|
|
34
|
-
moduleName?: string
|
|
35
|
-
layout?: BuildInLayout | Layout
|
|
36
|
-
popToRoot?: boolean
|
|
37
|
-
requestCode?: number
|
|
38
|
-
props?: IndexType
|
|
39
|
-
options?: NavigationItem
|
|
40
|
-
[index: string]: any
|
|
41
|
-
}
|
|
14
|
+
export const NavigationContext = createContext<any>(null)
|
|
42
15
|
|
|
43
16
|
interface NavigationState {
|
|
44
17
|
params: { readonly [index: string]: any }
|
|
45
18
|
}
|
|
46
19
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
let didSetRootCallback: () => void
|
|
51
|
-
let tag = 0
|
|
20
|
+
interface PropsType {
|
|
21
|
+
[index: string]: any
|
|
22
|
+
}
|
|
52
23
|
|
|
53
|
-
|
|
54
|
-
didSetRootCallback && didSetRootCallback()
|
|
55
|
-
shouldCallWillSetRootCallback = 0
|
|
56
|
-
})
|
|
24
|
+
let tagGenerator = 0
|
|
57
25
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
26
|
+
Navigation.addGlobalVisibilityEventListener((sceneId: string, visibility: Visibility) => {
|
|
27
|
+
const navigator = store.getNavigator(sceneId)
|
|
28
|
+
if (navigator) {
|
|
29
|
+
navigator.visibility = visibility
|
|
61
30
|
}
|
|
62
31
|
})
|
|
63
32
|
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
Navigator.dispatch(event[KEY_SCENE_ID], 'switchTab', {
|
|
68
|
-
from: Number(from),
|
|
69
|
-
to: Number(to),
|
|
70
|
-
})
|
|
33
|
+
Navigation.setBarButtonClickEventListener((sceneId, value) => {
|
|
34
|
+
const navigator = Navigator.of(sceneId)
|
|
35
|
+
value(navigator)
|
|
71
36
|
})
|
|
72
37
|
|
|
73
|
-
interface
|
|
74
|
-
(resultCode: number, data: T): void
|
|
75
|
-
cancel: () => void
|
|
76
|
-
sceneId: string
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const resultListeners = new Map<number, ResultListener<any>>()
|
|
80
|
-
|
|
81
|
-
EventEmitter.addListener(EVENT_NAVIGATION, data => {
|
|
82
|
-
if (data[KEY_ON] === ON_COMPONENT_RESULT) {
|
|
83
|
-
const requestCode = data[KEY_REQUEST_CODE]
|
|
84
|
-
const resultCode = data[KEY_RESULT_CODE]
|
|
85
|
-
const resultData = data[KEY_RESULT_DATA]
|
|
86
|
-
const sceneId = data[KEY_SCENE_ID]
|
|
87
|
-
|
|
88
|
-
if (requestCode < 0) {
|
|
89
|
-
const listener = resultListeners.get(requestCode)
|
|
90
|
-
if (listener) {
|
|
91
|
-
resultListeners.delete(requestCode)
|
|
92
|
-
listener(resultCode, resultData)
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
const navigator = Navigator.of(sceneId)
|
|
96
|
-
navigator.result(resultCode, resultData)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
})
|
|
38
|
+
export interface Navigator {}
|
|
100
39
|
|
|
101
|
-
export class Navigator {
|
|
40
|
+
export class Navigator implements Navigator {
|
|
102
41
|
static of(sceneId: string) {
|
|
103
42
|
let navigator = store.getNavigator(sceneId)
|
|
104
43
|
if (!navigator) {
|
|
@@ -108,17 +47,13 @@ export class Navigator {
|
|
|
108
47
|
return navigator
|
|
109
48
|
}
|
|
110
49
|
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated Use Navigation.findSceneIdByModuleName() instead.
|
|
52
|
+
* @param moduleName
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
111
55
|
static async find(moduleName: string) {
|
|
112
|
-
const sceneId = await
|
|
113
|
-
NavigationModule.findSceneIdByModuleName(moduleName, (error: never, id: string) => {
|
|
114
|
-
if (error) {
|
|
115
|
-
reject(error)
|
|
116
|
-
} else {
|
|
117
|
-
resolve(id)
|
|
118
|
-
}
|
|
119
|
-
})
|
|
120
|
-
})
|
|
121
|
-
|
|
56
|
+
const sceneId = await Navigation.findSceneIdByModuleName(moduleName)
|
|
122
57
|
if (sceneId) {
|
|
123
58
|
return Navigator.of(sceneId)
|
|
124
59
|
}
|
|
@@ -129,138 +64,65 @@ export class Navigator {
|
|
|
129
64
|
return Navigator.of(route.sceneId)
|
|
130
65
|
}
|
|
131
66
|
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated Use Navigation.currentRoute() instead
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
132
71
|
static currentRoute(): Promise<Route> {
|
|
133
|
-
return
|
|
134
|
-
NavigationModule.currentRoute((error: never, route: Route) => {
|
|
135
|
-
if (error) {
|
|
136
|
-
reject(error)
|
|
137
|
-
} else {
|
|
138
|
-
resolve(route)
|
|
139
|
-
}
|
|
140
|
-
})
|
|
141
|
-
})
|
|
72
|
+
return Navigation.currentRoute()
|
|
142
73
|
}
|
|
143
74
|
|
|
75
|
+
/**
|
|
76
|
+
* @deprecated Use Navigation.routeGraph() instead
|
|
77
|
+
* @returns
|
|
78
|
+
*/
|
|
144
79
|
static routeGraph(): Promise<RouteGraph[]> {
|
|
145
|
-
return
|
|
146
|
-
NavigationModule.routeGraph((error: never, result: RouteGraph[]) => {
|
|
147
|
-
if (error) {
|
|
148
|
-
reject(error)
|
|
149
|
-
} else {
|
|
150
|
-
resolve(result)
|
|
151
|
-
}
|
|
152
|
-
})
|
|
153
|
-
})
|
|
80
|
+
return Navigation.routeGraph()
|
|
154
81
|
}
|
|
155
82
|
|
|
83
|
+
/**
|
|
84
|
+
* @deprecated Use Navigation.setRoot() instead
|
|
85
|
+
* @param layout
|
|
86
|
+
* @param sticky
|
|
87
|
+
*/
|
|
156
88
|
static setRoot(layout: BuildInLayout | Layout, sticky = false) {
|
|
157
|
-
|
|
158
|
-
inLayout: true,
|
|
159
|
-
navigatorFactory: (sceneId: string) => {
|
|
160
|
-
return Navigator.of(sceneId)
|
|
161
|
-
},
|
|
162
|
-
})
|
|
163
|
-
if (willSetRootCallback) {
|
|
164
|
-
shouldCallWillSetRootCallback++
|
|
165
|
-
willSetRootCallback()
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const flag = --tag
|
|
169
|
-
NavigationModule.setRoot(pureLayout, sticky, flag)
|
|
170
|
-
|
|
171
|
-
return new Promise<void>(resolve => {
|
|
172
|
-
const subscription = EventEmitter.addListener(EVENT_DID_SET_ROOT, (data: { tag: number }) => {
|
|
173
|
-
if (data.tag === flag) {
|
|
174
|
-
subscription.remove()
|
|
175
|
-
resolve()
|
|
176
|
-
}
|
|
177
|
-
})
|
|
178
|
-
})
|
|
89
|
+
Navigation.setRoot(layout, sticky)
|
|
179
90
|
}
|
|
180
91
|
|
|
92
|
+
/**
|
|
93
|
+
* @deprecated Use Navigation.setRootLayoutUpdateListener() instead
|
|
94
|
+
* @param willSetRoot
|
|
95
|
+
* @param didSetRoot
|
|
96
|
+
*/
|
|
181
97
|
static setRootLayoutUpdateListener(willSetRoot = () => {}, didSetRoot = () => {}) {
|
|
182
|
-
|
|
183
|
-
didSetRootCallback = didSetRoot
|
|
98
|
+
Navigation.setRootLayoutUpdateListener(willSetRoot, didSetRoot)
|
|
184
99
|
}
|
|
185
100
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (!intercepted) {
|
|
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
|
-
})
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return false
|
|
101
|
+
/**
|
|
102
|
+
* @deprecated Use Navigation.dispatch() instead
|
|
103
|
+
* @param sceneId
|
|
104
|
+
* @param action
|
|
105
|
+
* @param params
|
|
106
|
+
* @returns
|
|
107
|
+
*/
|
|
108
|
+
static async dispatch(
|
|
109
|
+
sceneId: string,
|
|
110
|
+
action: string,
|
|
111
|
+
params: DispatchParams = {},
|
|
112
|
+
): Promise<boolean> {
|
|
113
|
+
return Navigation.dispatch(sceneId, action, params)
|
|
215
114
|
}
|
|
216
115
|
|
|
217
|
-
|
|
218
|
-
|
|
116
|
+
/**
|
|
117
|
+
* @deprecated Use Navigation.setInterceptor() instead
|
|
118
|
+
* @param interceptor
|
|
119
|
+
*/
|
|
120
|
+
static setInterceptor(interceptor: NavigationInterceptor) {
|
|
121
|
+
Navigation.setInterceptor(interceptor)
|
|
219
122
|
}
|
|
220
123
|
|
|
221
124
|
constructor(public sceneId: string, public moduleName?: string) {}
|
|
222
125
|
|
|
223
|
-
visibility: Visibility = 'pending'
|
|
224
|
-
|
|
225
|
-
readonly state: NavigationState = {
|
|
226
|
-
params: {},
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
setParams = (params: { [index: string]: any }) => {
|
|
230
|
-
this.state.params = { ...this.state.params, ...params }
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
dispatch = (action: string, params: Params = {}) => {
|
|
234
|
-
return Navigator.dispatch(this.sceneId, action, {
|
|
235
|
-
from: this.moduleName,
|
|
236
|
-
to: params.moduleName,
|
|
237
|
-
...params,
|
|
238
|
-
})
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
result = (resultCode: number, data: ResultType) => {
|
|
242
|
-
if (this.resultListener) {
|
|
243
|
-
this.resultListener(resultCode, data)
|
|
244
|
-
this.resultListener = null
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
unmount = () => {
|
|
249
|
-
const codes: number[] = []
|
|
250
|
-
for (const [requestCode, listener] of resultListeners) {
|
|
251
|
-
if (listener.sceneId === this.sceneId) {
|
|
252
|
-
codes.push(requestCode)
|
|
253
|
-
listener.cancel()
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
codes.forEach(code => resultListeners.delete(code))
|
|
257
|
-
|
|
258
|
-
if (this.resultListener) {
|
|
259
|
-
this.resultListener.cancel()
|
|
260
|
-
this.resultListener = null
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
126
|
private _garden?: Garden
|
|
265
127
|
|
|
266
128
|
get garden() {
|
|
@@ -270,172 +132,138 @@ export class Navigator {
|
|
|
270
132
|
return this._garden
|
|
271
133
|
}
|
|
272
134
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
private waitResult<T extends ResultType>(requestCode: number, successful: boolean): Promise<[number, T]> {
|
|
276
|
-
if (!successful) {
|
|
277
|
-
return Promise.resolve([RESULT_CANCEL, null as any])
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (this.resultListener) {
|
|
281
|
-
this.resultListener.cancel()
|
|
282
|
-
this.resultListener = null
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return new Promise<[number, T]>(resolve => {
|
|
286
|
-
const listener = (resultCode: number, data: T) => {
|
|
287
|
-
resolve([resultCode, data])
|
|
288
|
-
}
|
|
135
|
+
visibility: Visibility = 'pending'
|
|
289
136
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
137
|
+
readonly state: NavigationState = {
|
|
138
|
+
params: {},
|
|
139
|
+
}
|
|
293
140
|
|
|
294
|
-
|
|
141
|
+
setParams = (params: { [index: string]: any }) => {
|
|
142
|
+
this.state.params = { ...this.state.params, ...params }
|
|
143
|
+
}
|
|
295
144
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
this.resultListener = listener
|
|
300
|
-
}
|
|
301
|
-
})
|
|
145
|
+
unmount = () => {
|
|
146
|
+
store.removeNavigator(this.sceneId)
|
|
147
|
+
Navigation.unmount(this.sceneId)
|
|
302
148
|
}
|
|
303
149
|
|
|
304
|
-
push = async <T extends ResultType, P extends PropsType =
|
|
150
|
+
push = async <T extends ResultType, P extends PropsType = {}>(
|
|
305
151
|
moduleName: string,
|
|
306
|
-
props: P = {} as
|
|
152
|
+
props: P = {} as P,
|
|
307
153
|
options: NavigationItem = {},
|
|
308
154
|
) => {
|
|
309
|
-
const success = await
|
|
310
|
-
|
|
311
|
-
|
|
155
|
+
const success = await Navigation.dispatch(this.sceneId, 'push', { moduleName, props, options })
|
|
156
|
+
if (!success) {
|
|
157
|
+
return [RESULT_CANCEL, null] as [number, T]
|
|
158
|
+
}
|
|
159
|
+
return await Navigation.result<T>(this.sceneId, 0)
|
|
312
160
|
}
|
|
313
161
|
|
|
314
162
|
pushLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
|
|
315
|
-
const success = await
|
|
316
|
-
|
|
163
|
+
const success = await Navigation.dispatch(this.sceneId, 'pushLayout', { layout })
|
|
164
|
+
if (!success) {
|
|
165
|
+
return [RESULT_CANCEL, null] as [number, T]
|
|
166
|
+
}
|
|
167
|
+
return await Navigation.result<T>(this.sceneId, 0)
|
|
317
168
|
}
|
|
318
169
|
|
|
319
|
-
pop =
|
|
320
|
-
const success = await this.dispatch('pop')
|
|
321
|
-
console.log('pop', success)
|
|
322
|
-
return success
|
|
323
|
-
}
|
|
170
|
+
pop = () => Navigation.dispatch(this.sceneId, 'pop')
|
|
324
171
|
|
|
325
|
-
popTo = (moduleName: string, inclusive: boolean = false) =>
|
|
326
|
-
|
|
327
|
-
}
|
|
172
|
+
popTo = (moduleName: string, inclusive: boolean = false) =>
|
|
173
|
+
Navigation.dispatch(this.sceneId, 'popTo', { moduleName, inclusive })
|
|
328
174
|
|
|
329
|
-
popToRoot = () =>
|
|
330
|
-
return this.dispatch('popToRoot')
|
|
331
|
-
}
|
|
175
|
+
popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot')
|
|
332
176
|
|
|
333
|
-
redirectTo =
|
|
177
|
+
redirectTo = <P extends PropsType>(
|
|
334
178
|
moduleName: string,
|
|
335
|
-
props: P = {} as
|
|
179
|
+
props: P = {} as P,
|
|
336
180
|
options: NavigationItem = {},
|
|
337
|
-
) =>
|
|
338
|
-
|
|
181
|
+
) =>
|
|
182
|
+
Navigation.dispatch(this.sceneId, 'redirectTo', {
|
|
339
183
|
moduleName,
|
|
340
184
|
props,
|
|
341
185
|
options,
|
|
342
186
|
})
|
|
343
|
-
console.log('redirectTo', success)
|
|
344
|
-
return success
|
|
345
|
-
}
|
|
346
|
-
|
|
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
|
-
})
|
|
357
|
-
}
|
|
358
187
|
|
|
359
|
-
present = async <T extends ResultType, P extends PropsType =
|
|
188
|
+
present = async <T extends ResultType, P extends PropsType = {}>(
|
|
360
189
|
moduleName: string,
|
|
361
|
-
props: P = {} as
|
|
190
|
+
props: P = {} as P,
|
|
362
191
|
options: NavigationItem = {},
|
|
363
192
|
) => {
|
|
364
|
-
const requestCode = --
|
|
365
|
-
const success = await
|
|
193
|
+
const requestCode = --tagGenerator
|
|
194
|
+
const success = await Navigation.dispatch(this.sceneId, 'present', {
|
|
366
195
|
moduleName,
|
|
367
196
|
props,
|
|
368
197
|
options,
|
|
369
198
|
requestCode,
|
|
370
199
|
})
|
|
371
|
-
|
|
200
|
+
if (!success) {
|
|
201
|
+
return [RESULT_CANCEL, null] as [number, T]
|
|
202
|
+
}
|
|
203
|
+
return await Navigation.result<T>(this.sceneId, requestCode)
|
|
372
204
|
}
|
|
373
205
|
|
|
374
206
|
presentLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
|
|
375
|
-
const requestCode = --
|
|
376
|
-
const success = await
|
|
377
|
-
|
|
207
|
+
const requestCode = --tagGenerator
|
|
208
|
+
const success = await Navigation.dispatch(this.sceneId, 'presentLayout', {
|
|
209
|
+
layout,
|
|
210
|
+
requestCode,
|
|
211
|
+
})
|
|
212
|
+
if (!success) {
|
|
213
|
+
return [RESULT_CANCEL, null] as [number, T]
|
|
214
|
+
}
|
|
215
|
+
return await Navigation.result<T>(this.sceneId, requestCode)
|
|
378
216
|
}
|
|
379
217
|
|
|
380
|
-
dismiss = () =>
|
|
381
|
-
return this.dispatch('dismiss')
|
|
382
|
-
}
|
|
218
|
+
dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss')
|
|
383
219
|
|
|
384
|
-
showModal = async <T extends ResultType, P extends PropsType =
|
|
220
|
+
showModal = async <T extends ResultType, P extends PropsType = {}>(
|
|
385
221
|
moduleName: string,
|
|
386
|
-
props: P = {} as
|
|
222
|
+
props: P = {} as P,
|
|
387
223
|
options: NavigationItem = {},
|
|
388
224
|
) => {
|
|
389
|
-
const requestCode = --
|
|
390
|
-
const success = await
|
|
225
|
+
const requestCode = --tagGenerator
|
|
226
|
+
const success = await Navigation.dispatch(this.sceneId, 'showModal', {
|
|
391
227
|
moduleName,
|
|
392
228
|
props,
|
|
393
229
|
options,
|
|
394
230
|
requestCode,
|
|
395
231
|
})
|
|
396
|
-
|
|
232
|
+
if (!success) {
|
|
233
|
+
return [RESULT_CANCEL, null] as [number, T]
|
|
234
|
+
}
|
|
235
|
+
return await Navigation.result<T>(this.sceneId, requestCode)
|
|
397
236
|
}
|
|
398
237
|
|
|
399
238
|
showModalLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
|
|
400
|
-
const requestCode = --
|
|
401
|
-
const success = await
|
|
402
|
-
|
|
239
|
+
const requestCode = --tagGenerator
|
|
240
|
+
const success = await Navigation.dispatch(this.sceneId, 'showModalLayout', {
|
|
241
|
+
layout,
|
|
242
|
+
requestCode,
|
|
243
|
+
})
|
|
244
|
+
if (!success) {
|
|
245
|
+
return [RESULT_CANCEL, null] as [number, T]
|
|
246
|
+
}
|
|
247
|
+
return await Navigation.result<T>(this.sceneId, requestCode)
|
|
403
248
|
}
|
|
404
249
|
|
|
405
|
-
hideModal = () =>
|
|
406
|
-
return this.dispatch('hideModal')
|
|
407
|
-
}
|
|
250
|
+
hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal')
|
|
408
251
|
|
|
409
|
-
setResult = <T extends ResultType>(resultCode: number, data: T = null as any): void =>
|
|
410
|
-
|
|
411
|
-
}
|
|
252
|
+
setResult = <T extends ResultType>(resultCode: number, data: T = null as any): void =>
|
|
253
|
+
Navigation.setResult(this.sceneId, resultCode, data)
|
|
412
254
|
|
|
413
255
|
switchTab = async (index: number, popToRoot: boolean = false) => {
|
|
414
|
-
const from = await
|
|
415
|
-
|
|
416
|
-
if (error) {
|
|
417
|
-
reject(error)
|
|
418
|
-
} else {
|
|
419
|
-
resolve(result)
|
|
420
|
-
}
|
|
421
|
-
})
|
|
422
|
-
})
|
|
423
|
-
return this.dispatch('switchTab', { from, to: index, popToRoot })
|
|
256
|
+
const from = await Navigation.currentTab(this.sceneId)
|
|
257
|
+
return Navigation.dispatch(this.sceneId, 'switchTab', { from, to: index, popToRoot })
|
|
424
258
|
}
|
|
425
259
|
|
|
426
|
-
toggleMenu = () =>
|
|
427
|
-
return this.dispatch('toggleMenu')
|
|
428
|
-
}
|
|
260
|
+
toggleMenu = () => Navigation.dispatch(this.sceneId, 'toggleMenu')
|
|
429
261
|
|
|
430
|
-
openMenu = () =>
|
|
431
|
-
return this.dispatch('openMenu')
|
|
432
|
-
}
|
|
262
|
+
openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu')
|
|
433
263
|
|
|
434
|
-
closeMenu = () =>
|
|
435
|
-
return this.dispatch('closeMenu')
|
|
436
|
-
}
|
|
264
|
+
closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu')
|
|
437
265
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
266
|
+
isStackRoot = () => Navigation.isStackRoot(this.sceneId)
|
|
267
|
+
|
|
268
|
+
signalFirstRenderComplete = () => Navigation.signalFirstRenderComplete(this.sceneId)
|
|
441
269
|
}
|