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
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import type React from 'react'
|
|
2
|
+
import { AppRegistry, ComponentProvider, Platform } from 'react-native'
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
BarButtonItem,
|
|
6
|
+
DefaultOptions,
|
|
7
|
+
NavigationOption,
|
|
8
|
+
TabBarStyle,
|
|
9
|
+
TabItemInfo,
|
|
10
|
+
TitleItem,
|
|
11
|
+
} from './Options'
|
|
12
|
+
import type { BuildInLayout, Layout, Route, RouteGraph, RouteConfig } from './Route'
|
|
13
|
+
|
|
14
|
+
import BarButtonEventHandler from './handler/BarButtonEventHandler'
|
|
15
|
+
import LayoutCommandHandler from './handler/LayoutCommandHandler'
|
|
16
|
+
import DispatchCommandHandler from './handler/DispatchCommandHandler'
|
|
17
|
+
import ResultEventHandler, { ResultType } from './handler/ResultEventHandler'
|
|
18
|
+
import VisibilityEventHandler, {
|
|
19
|
+
GlobalVisibilityEventListener,
|
|
20
|
+
VisibilityEventListener,
|
|
21
|
+
} from './handler/VisibilityEventHandler'
|
|
22
|
+
|
|
23
|
+
import Event from './Event'
|
|
24
|
+
import GardenModule from './GardenModule'
|
|
25
|
+
import NavigationModule from './NavigationModule'
|
|
26
|
+
|
|
27
|
+
export type { ResultType } from './handler/ResultEventHandler'
|
|
28
|
+
import type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler'
|
|
29
|
+
export type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler'
|
|
30
|
+
|
|
31
|
+
type BarButtonClickEventListener = (sceneId: string, value: Function) => void
|
|
32
|
+
|
|
33
|
+
type Nullable<T> = {
|
|
34
|
+
[P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT } = GardenModule.getConstants()
|
|
38
|
+
export const { RESULT_CANCEL, RESULT_OK } = NavigationModule.getConstants()
|
|
39
|
+
|
|
40
|
+
export type NavigationSubscription = {
|
|
41
|
+
remove: () => void
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type HOC = (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>
|
|
45
|
+
|
|
46
|
+
export interface Navigation {}
|
|
47
|
+
|
|
48
|
+
export class Navigation implements Navigation {
|
|
49
|
+
private dispatchHandler = new DispatchCommandHandler()
|
|
50
|
+
private resultHandler = new ResultEventHandler()
|
|
51
|
+
private buttonHandler = new BarButtonEventHandler()
|
|
52
|
+
private layoutHandler = new LayoutCommandHandler()
|
|
53
|
+
private visibilityHandler = new VisibilityEventHandler()
|
|
54
|
+
|
|
55
|
+
constructor() {
|
|
56
|
+
this.handleStatusBarHeightChange()
|
|
57
|
+
this.handleTabSwitch()
|
|
58
|
+
this.layoutHandler.handleRootLayoutChange()
|
|
59
|
+
this.visibilityHandler.handleComponentVisibility()
|
|
60
|
+
this.resultHandler.handleComponentResult()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private wrap?: (moduleName: string) => HOC
|
|
64
|
+
private hoc?: HOC
|
|
65
|
+
private registerEnded = false
|
|
66
|
+
|
|
67
|
+
startRegisterComponent(hoc?: HOC) {
|
|
68
|
+
this.hoc = hoc
|
|
69
|
+
this.registerEnded = false
|
|
70
|
+
NavigationModule.startRegisterReactComponent()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
endRegisterComponent() {
|
|
74
|
+
if (this.registerEnded) {
|
|
75
|
+
console.warn(`Please don't call ReactRegistry#endRegisterComponent multiple times.`)
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
this.registerEnded = true
|
|
79
|
+
NavigationModule.endRegisterReactComponent()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
registerComponent(
|
|
83
|
+
appKey: string,
|
|
84
|
+
getComponentFunc: ComponentProvider,
|
|
85
|
+
routeConfig?: RouteConfig,
|
|
86
|
+
) {
|
|
87
|
+
if (routeConfig) {
|
|
88
|
+
this.registerRoute(appKey, routeConfig)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let WrappedComponent = getComponentFunc()
|
|
92
|
+
if (this.hoc) {
|
|
93
|
+
WrappedComponent = this.hoc(WrappedComponent)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// build static options
|
|
97
|
+
let options: object =
|
|
98
|
+
this.bindBarButtonClickEvent('permanent', (WrappedComponent as any).navigationItem) || {}
|
|
99
|
+
NavigationModule.registerReactComponent(appKey, options)
|
|
100
|
+
|
|
101
|
+
let RootComponent = this.wrap!(appKey)(WrappedComponent)
|
|
102
|
+
AppRegistry.registerComponent(appKey, () => RootComponent)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
setNavigationComponentWrap(wrap: (moduleName: string) => HOC) {
|
|
106
|
+
this.wrap = wrap
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
addGlobalVisibilityEventListener(
|
|
110
|
+
listener: GlobalVisibilityEventListener,
|
|
111
|
+
): NavigationSubscription {
|
|
112
|
+
this.visibilityHandler.addGlobalVisibilityEventListener(listener)
|
|
113
|
+
return {
|
|
114
|
+
remove: () => this.visibilityHandler.removeGlobalVisibilityEventListener(listener),
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
addVisibilityEventListener(
|
|
119
|
+
sceneId: string,
|
|
120
|
+
listener: VisibilityEventListener,
|
|
121
|
+
): NavigationSubscription {
|
|
122
|
+
this.visibilityHandler.addVisibilityEventListener(sceneId, listener)
|
|
123
|
+
return {
|
|
124
|
+
remove: () => this.visibilityHandler.removeVisibilityEventListener(sceneId, listener),
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
dispatch(sceneId: string, action: string, params: DispatchParams = {}) {
|
|
129
|
+
return this.dispatchHandler.dispatch(sceneId, action, params)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private handleTabSwitch() {
|
|
133
|
+
Event.listenTabSwitch((sceneId: string, from: number, to: number) => {
|
|
134
|
+
this.dispatch(sceneId, 'switchTab', { from, to })
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
setInterceptor(interceptor: NavigationInterceptor) {
|
|
139
|
+
this.dispatchHandler.setInterceptor(interceptor)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
setResult = <T extends ResultType>(
|
|
143
|
+
sceneId: string,
|
|
144
|
+
resultCode: number,
|
|
145
|
+
data: T = null as any,
|
|
146
|
+
): void => NavigationModule.setResult(sceneId, resultCode, data)
|
|
147
|
+
|
|
148
|
+
result<T>(sceneId: string, resultCode: number) {
|
|
149
|
+
return this.resultHandler.waitResult<T>(sceneId, resultCode)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
unmount(sceneId: string) {
|
|
153
|
+
this.resultHandler.invalidateResultEventListener(sceneId)
|
|
154
|
+
this.buttonHandler.unbindBarButtonClickEvent(sceneId)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
setRoot(layout: BuildInLayout | Layout, sticky = false) {
|
|
158
|
+
return this.layoutHandler.setRoot(layout, sticky)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
setRootLayoutUpdateListener(willSetRoot = () => {}, didSetRoot = () => {}) {
|
|
162
|
+
this.layoutHandler.setRootLayoutUpdateListener(willSetRoot, didSetRoot)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
currentTab(sceneId: string) {
|
|
166
|
+
return NavigationModule.currentTab(sceneId)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
findSceneIdByModuleName(moduleName: string) {
|
|
170
|
+
return NavigationModule.findSceneIdByModuleName(moduleName)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
isStackRoot(sceneId: string) {
|
|
174
|
+
return NavigationModule.isStackRoot(sceneId)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
signalFirstRenderComplete(sceneId: string) {
|
|
178
|
+
NavigationModule.signalFirstRenderComplete(sceneId)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
currentRoute(): Promise<Route> {
|
|
182
|
+
return NavigationModule.currentRoute()
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
routeGraph(): Promise<RouteGraph[]> {
|
|
186
|
+
return NavigationModule.routeGraph()
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
private _routeConfigs = new Map<string, RouteConfig>()
|
|
190
|
+
|
|
191
|
+
private registerRoute(moduleName: string, route: RouteConfig) {
|
|
192
|
+
this._routeConfigs.set(moduleName, route)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
routeConfigs() {
|
|
196
|
+
return this._routeConfigs
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
setDefaultOptions(options: DefaultOptions) {
|
|
200
|
+
GardenModule.setStyle(options)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
setLeftBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null) {
|
|
204
|
+
const options = this.bindBarButtonClickEvent(sceneId, buttonItem)
|
|
205
|
+
GardenModule.setLeftBarButtonItem(sceneId, options)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
setRightBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null) {
|
|
209
|
+
const options = this.bindBarButtonClickEvent(sceneId, buttonItem)
|
|
210
|
+
GardenModule.setRightBarButtonItem(sceneId, options)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
setLeftBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null) {
|
|
214
|
+
const options = this.bindBarButtonClickEvent(sceneId, buttonItems)
|
|
215
|
+
GardenModule.setLeftBarButtonItems(sceneId, options)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
setRightBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null) {
|
|
219
|
+
const options = this.bindBarButtonClickEvent(sceneId, buttonItems)
|
|
220
|
+
GardenModule.setRightBarButtonItems(sceneId, options)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
setTitleItem(sceneId: string, titleItem: TitleItem) {
|
|
224
|
+
GardenModule.setTitleItem(sceneId, titleItem)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
updateOptions(sceneId: string, options: NavigationOption) {
|
|
228
|
+
GardenModule.updateOptions(sceneId, options)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
updateTabBar(sceneId: string, options: TabBarStyle) {
|
|
232
|
+
GardenModule.updateTabBar(sceneId, options)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]) {
|
|
236
|
+
if (!Array.isArray(item)) {
|
|
237
|
+
item = [item]
|
|
238
|
+
}
|
|
239
|
+
GardenModule.setTabItem(sceneId, item)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
setMenuInteractive(sceneId: string, enabled: boolean) {
|
|
243
|
+
GardenModule.setMenuInteractive(sceneId, enabled)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private _statusBarHeight = STATUSBAR_HEIGHT
|
|
247
|
+
private _toolbarHeight = TOOLBAR_HEIGHT
|
|
248
|
+
|
|
249
|
+
private handleStatusBarHeightChange() {
|
|
250
|
+
if (Platform.OS === 'ios') {
|
|
251
|
+
Event.listenStatusBarHeightChange(statusBarHeight => {
|
|
252
|
+
this._statusBarHeight = statusBarHeight
|
|
253
|
+
})
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
statusBarHeight() {
|
|
258
|
+
return this._statusBarHeight
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
toolbarHeight() {
|
|
262
|
+
return this._toolbarHeight
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
topBarHeight() {
|
|
266
|
+
return this.statusBarHeight() + this.toolbarHeight()
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
setBarButtonClickEventListener(listener: BarButtonClickEventListener) {
|
|
270
|
+
this.buttonHandler.setBarButtonClickEventListener(listener)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
private bindBarButtonClickEvent(sceneId: string, item: object | null | undefined): object | null {
|
|
274
|
+
return this.buttonHandler.bindBarButtonClickEvent(sceneId, item)
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export default new Navigation()
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React, { useEffect } from 'react'
|
|
2
|
+
|
|
3
|
+
import type { Garden } from './Garden'
|
|
4
|
+
import type { NavigationItem } from './Options'
|
|
5
|
+
|
|
6
|
+
import { Navigator, NavigationContext } from './Navigator'
|
|
7
|
+
|
|
8
|
+
export interface NavigationProps {
|
|
9
|
+
navigator: Navigator
|
|
10
|
+
garden: Garden
|
|
11
|
+
sceneId: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use NavigationComponentProps instead.
|
|
16
|
+
*/
|
|
17
|
+
export type InjectedProps = NavigationProps
|
|
18
|
+
|
|
19
|
+
interface NativeProps {
|
|
20
|
+
sceneId: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getDisplayName(WrappedComponent: React.ComponentType<any>) {
|
|
24
|
+
return WrappedComponent.displayName || WrappedComponent.name || 'Component'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function withNavigation(moduleName: string) {
|
|
28
|
+
return function (WrappedComponent: React.ComponentType<any>) {
|
|
29
|
+
const FC = React.forwardRef((props: NativeProps, ref: React.Ref<React.ComponentType<any>>) => {
|
|
30
|
+
const { sceneId } = props
|
|
31
|
+
|
|
32
|
+
const navigator = Navigator.of(sceneId)
|
|
33
|
+
if (navigator.moduleName === undefined) {
|
|
34
|
+
navigator.moduleName = moduleName
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const garden = navigator.garden
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
navigator.signalFirstRenderComplete()
|
|
41
|
+
return () => {
|
|
42
|
+
navigator.unmount()
|
|
43
|
+
}
|
|
44
|
+
}, [navigator])
|
|
45
|
+
|
|
46
|
+
const injected = {
|
|
47
|
+
garden,
|
|
48
|
+
navigator,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<NavigationContext.Provider value={navigator}>
|
|
53
|
+
<WrappedComponent ref={ref} {...props} {...injected} />
|
|
54
|
+
</NavigationContext.Provider>
|
|
55
|
+
)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
FC.displayName = `withNavigation(${getDisplayName(WrappedComponent)})`
|
|
59
|
+
return FC
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function withNavigationItem(item: NavigationItem) {
|
|
64
|
+
return function (WrappedComponent: React.ComponentType<any>): React.ComponentType<any> {
|
|
65
|
+
let navigationItem = (WrappedComponent as any).navigationItem
|
|
66
|
+
if (navigationItem) {
|
|
67
|
+
;(WrappedComponent as any).navigationItem = { ...navigationItem, ...item }
|
|
68
|
+
} else {
|
|
69
|
+
;(WrappedComponent as any).navigationItem = item
|
|
70
|
+
}
|
|
71
|
+
return WrappedComponent
|
|
72
|
+
}
|
|
73
|
+
}
|
package/src/NavigationModule.ts
CHANGED
|
@@ -1,29 +1,118 @@
|
|
|
1
|
-
import { NativeModules
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
import { NativeModules } from 'react-native'
|
|
2
|
+
import { Route, RouteGraph } from './Route'
|
|
3
|
+
|
|
4
|
+
type Callback = (error: never, result: any) => void
|
|
5
|
+
|
|
6
|
+
interface NavigationModule {
|
|
7
|
+
getConstants: () => {
|
|
8
|
+
RESULT_OK: number
|
|
9
|
+
RESULT_CANCEL: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
startRegisterReactComponent: () => void
|
|
13
|
+
endRegisterReactComponent: () => void
|
|
14
|
+
registerReactComponent: (appKey: string, options: object) => void
|
|
15
|
+
signalFirstRenderComplete: (sceneId: string) => void
|
|
16
|
+
setRoot: (layout: object, sticky: boolean, tag: number) => void
|
|
17
|
+
setResult: (sceneId: string, resultCode: number, data: object | null) => void
|
|
18
|
+
dispatch: (sceneId: string, action: string, params: object, callback: Callback) => void
|
|
19
|
+
currentTab: (sceneId: string, callback: Callback) => void
|
|
20
|
+
isStackRoot: (sceneId: string, callback: Callback) => void
|
|
21
|
+
findSceneIdByModuleName: (moduleName: string, callback: Callback) => void
|
|
22
|
+
currentRoute: (callback: Callback) => void
|
|
23
|
+
routeGraph: (callback: Callback) => void
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const NavigationModule: NavigationModule = NativeModules.NavigationModule
|
|
27
|
+
|
|
28
|
+
function getConstants() {
|
|
29
|
+
return NavigationModule.getConstants()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function startRegisterReactComponent() {
|
|
33
|
+
NavigationModule.startRegisterReactComponent()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function endRegisterReactComponent() {
|
|
37
|
+
NavigationModule.endRegisterReactComponent()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function registerReactComponent(appKey: string, options: object) {
|
|
41
|
+
NavigationModule.registerReactComponent(appKey, options)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function signalFirstRenderComplete(sceneId: string) {
|
|
45
|
+
NavigationModule.signalFirstRenderComplete(sceneId)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function setResult(sceneId: string, resultCode: number, data: object | null) {
|
|
49
|
+
NavigationModule.setResult(sceneId, resultCode, data)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function setRoot(layout: object, sticky: boolean, tag: number) {
|
|
53
|
+
NavigationModule.setRoot(layout, sticky, tag)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function dispatch(sceneId: string, action: string, params: object) {
|
|
57
|
+
return new Promise<boolean>(resolve => {
|
|
58
|
+
NavigationModule.dispatch(sceneId, action, params, (_, result) => {
|
|
59
|
+
resolve(result)
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function currentTab(sceneId: string) {
|
|
65
|
+
return new Promise<number>(resolve => {
|
|
66
|
+
NavigationModule.currentTab(sceneId, (_, result) => {
|
|
67
|
+
resolve(result)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function isStackRoot(sceneId: string) {
|
|
73
|
+
return new Promise<boolean>(resolve => {
|
|
74
|
+
NavigationModule.isStackRoot(sceneId, (_, result) => {
|
|
75
|
+
resolve(result)
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function findSceneIdByModuleName(moduleName: string) {
|
|
81
|
+
return new Promise<string | null>(resolve => {
|
|
82
|
+
NavigationModule.findSceneIdByModuleName(moduleName, (_, result) => {
|
|
83
|
+
resolve(result)
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function currentRoute() {
|
|
89
|
+
return new Promise<Route>(resolve => {
|
|
90
|
+
NavigationModule.currentRoute((_, result) => {
|
|
91
|
+
resolve(result)
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function routeGraph() {
|
|
97
|
+
return new Promise<RouteGraph[]>(resolve => {
|
|
98
|
+
NavigationModule.routeGraph((_, result) => {
|
|
99
|
+
resolve(result)
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export default {
|
|
105
|
+
getConstants,
|
|
106
|
+
startRegisterReactComponent,
|
|
107
|
+
endRegisterReactComponent,
|
|
108
|
+
registerReactComponent,
|
|
109
|
+
signalFirstRenderComplete,
|
|
110
|
+
setResult,
|
|
111
|
+
setRoot,
|
|
112
|
+
dispatch,
|
|
113
|
+
currentTab,
|
|
114
|
+
isStackRoot,
|
|
115
|
+
findSceneIdByModuleName,
|
|
116
|
+
currentRoute,
|
|
117
|
+
routeGraph,
|
|
118
|
+
}
|