hybrid-navigation 2.13.0-beta.4 → 2.13.2
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/build.gradle +1 -1
- package/lib/Garden.d.ts +3 -0
- package/lib/Garden.js +3 -0
- package/lib/Navigation.d.ts +6 -12
- package/lib/Navigation.js +11 -31
- package/lib/NavigationComponentWrap.d.ts +3 -3
- package/lib/Navigator.d.ts +5 -2
- package/lib/Navigator.js +25 -7
- package/lib/ReactRegistry.d.ts +3 -0
- package/lib/ReactRegistry.js +6 -3
- package/lib/Route.d.ts +13 -8
- package/lib/handler/DispatchCommandHandler.d.ts +2 -0
- package/lib/hooks.d.ts +4 -0
- package/lib/hooks.js +4 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +16 -5
- package/lib/router/drawer.d.ts +3 -1
- package/lib/router/drawer.js +17 -17
- package/lib/router/index.d.ts +19 -15
- package/lib/router/index.js +137 -125
- package/lib/router/screen.d.ts +5 -1
- package/lib/router/screen.js +29 -0
- package/lib/router/stack.d.ts +5 -1
- package/lib/router/stack.js +59 -46
- package/lib/router/tabs.d.ts +3 -1
- package/lib/router/tabs.js +18 -28
- package/package.json +1 -1
- package/src/Garden.ts +4 -0
- package/src/Navigation.ts +15 -40
- package/src/NavigationComponentWrap.tsx +3 -5
- package/src/Navigator.ts +26 -8
- package/src/ReactRegistry.tsx +6 -3
- package/src/Route.ts +14 -9
- package/src/handler/DispatchCommandHandler.ts +2 -0
- package/src/hooks.ts +4 -1
- package/src/index.ts +17 -20
- package/src/router/drawer.ts +20 -17
- package/src/router/index.ts +145 -131
- package/src/router/screen.ts +34 -1
- package/src/router/stack.ts +61 -48
- package/src/router/tabs.ts +19 -29
package/src/Navigation.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type React from 'react'
|
|
2
|
-
import { AppRegistry, ComponentProvider
|
|
2
|
+
import { AppRegistry, ComponentProvider } from 'react-native'
|
|
3
3
|
|
|
4
4
|
import type {
|
|
5
5
|
BarButtonItem,
|
|
@@ -34,7 +34,6 @@ type Nullable<T> = {
|
|
|
34
34
|
[P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P]
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT } = GardenModule.getConstants()
|
|
38
37
|
export const { RESULT_CANCEL, RESULT_OK } = NavigationModule.getConstants()
|
|
39
38
|
|
|
40
39
|
export type NavigationSubscription = {
|
|
@@ -53,7 +52,6 @@ export class Navigation implements Navigation {
|
|
|
53
52
|
private visibilityHandler = new VisibilityEventHandler()
|
|
54
53
|
|
|
55
54
|
constructor() {
|
|
56
|
-
this.handleStatusBarHeightChange()
|
|
57
55
|
this.handleTabSwitch()
|
|
58
56
|
this.layoutHandler.handleRootLayoutChange()
|
|
59
57
|
this.visibilityHandler.handleComponentVisibility()
|
|
@@ -64,13 +62,13 @@ export class Navigation implements Navigation {
|
|
|
64
62
|
private hoc?: HOC
|
|
65
63
|
private registerEnded = false
|
|
66
64
|
|
|
67
|
-
|
|
65
|
+
startRegisterComponent(hoc?: HOC) {
|
|
68
66
|
this.hoc = hoc
|
|
69
67
|
this.registerEnded = false
|
|
70
68
|
NavigationModule.startRegisterReactComponent()
|
|
71
69
|
}
|
|
72
70
|
|
|
73
|
-
|
|
71
|
+
endRegisterComponent() {
|
|
74
72
|
if (this.registerEnded) {
|
|
75
73
|
console.warn(`Please don't call ReactRegistry#endRegisterComponent multiple times.`)
|
|
76
74
|
return
|
|
@@ -79,7 +77,7 @@ export class Navigation implements Navigation {
|
|
|
79
77
|
NavigationModule.endRegisterReactComponent()
|
|
80
78
|
}
|
|
81
79
|
|
|
82
|
-
|
|
80
|
+
registerComponent(
|
|
83
81
|
appKey: string,
|
|
84
82
|
getComponentFunc: ComponentProvider,
|
|
85
83
|
routeConfig?: RouteConfig,
|
|
@@ -102,6 +100,16 @@ export class Navigation implements Navigation {
|
|
|
102
100
|
AppRegistry.registerComponent(appKey, () => RootComponent)
|
|
103
101
|
}
|
|
104
102
|
|
|
103
|
+
private _routeConfigs = new Map<string, RouteConfig>()
|
|
104
|
+
|
|
105
|
+
private registerRoute(moduleName: string, route: RouteConfig) {
|
|
106
|
+
this._routeConfigs.set(moduleName, route)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
routeConfigs() {
|
|
110
|
+
return this._routeConfigs
|
|
111
|
+
}
|
|
112
|
+
|
|
105
113
|
setNavigationComponentWrap(wrap: (moduleName: string) => HOC) {
|
|
106
114
|
this.wrap = wrap
|
|
107
115
|
}
|
|
@@ -142,7 +150,7 @@ export class Navigation implements Navigation {
|
|
|
142
150
|
setResult = <T extends ResultType>(
|
|
143
151
|
sceneId: string,
|
|
144
152
|
resultCode: number,
|
|
145
|
-
data: T = null as
|
|
153
|
+
data: T = null as T,
|
|
146
154
|
): void => NavigationModule.setResult(sceneId, resultCode, data)
|
|
147
155
|
|
|
148
156
|
result<T>(sceneId: string, resultCode: number) {
|
|
@@ -186,16 +194,6 @@ export class Navigation implements Navigation {
|
|
|
186
194
|
return NavigationModule.routeGraph()
|
|
187
195
|
}
|
|
188
196
|
|
|
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
197
|
setDefaultOptions(options: DefaultOptions) {
|
|
200
198
|
GardenModule.setStyle(options)
|
|
201
199
|
}
|
|
@@ -243,29 +241,6 @@ export class Navigation implements Navigation {
|
|
|
243
241
|
GardenModule.setMenuInteractive(sceneId, enabled)
|
|
244
242
|
}
|
|
245
243
|
|
|
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
244
|
setBarButtonClickEventListener(listener: BarButtonClickEventListener) {
|
|
270
245
|
this.buttonHandler.setBarButtonClickEventListener(listener)
|
|
271
246
|
}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import React, { useEffect } from 'react'
|
|
2
|
-
|
|
3
2
|
import type { Garden } from './Garden'
|
|
4
3
|
import type { NavigationItem } from './Options'
|
|
5
|
-
|
|
6
4
|
import { Navigator, NavigationContext } from './Navigator'
|
|
7
5
|
|
|
8
|
-
export interface
|
|
6
|
+
export interface NavigationProps {
|
|
9
7
|
navigator: Navigator
|
|
10
8
|
garden: Garden
|
|
11
9
|
sceneId: string
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
|
-
* @deprecated Use
|
|
13
|
+
* @deprecated Use NavigationProps instead.
|
|
16
14
|
*/
|
|
17
|
-
export type InjectedProps =
|
|
15
|
+
export type InjectedProps = NavigationProps
|
|
18
16
|
|
|
19
17
|
interface NativeProps {
|
|
20
18
|
sceneId: string
|
package/src/Navigator.ts
CHANGED
|
@@ -47,8 +47,13 @@ export class Navigator implements Navigator {
|
|
|
47
47
|
return navigator
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
static async current(): Promise<Navigator> {
|
|
51
|
+
const route = await Navigation.currentRoute()
|
|
52
|
+
return Navigator.of(route.sceneId)
|
|
53
|
+
}
|
|
54
|
+
|
|
50
55
|
/**
|
|
51
|
-
* @deprecated
|
|
56
|
+
* @deprecated Garden is deprecated, use Navigation.findSceneIdByModuleName() instead.
|
|
52
57
|
* @param moduleName
|
|
53
58
|
* @returns
|
|
54
59
|
*/
|
|
@@ -59,11 +64,6 @@ export class Navigator implements Navigator {
|
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
|
|
62
|
-
static async current(): Promise<Navigator> {
|
|
63
|
-
const route = await Navigator.currentRoute()
|
|
64
|
-
return Navigator.of(route.sceneId)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
67
|
/**
|
|
68
68
|
* @deprecated Use Navigation.currentRoute() instead
|
|
69
69
|
* @returns
|
|
@@ -125,6 +125,9 @@ export class Navigator implements Navigator {
|
|
|
125
125
|
|
|
126
126
|
private _garden?: Garden
|
|
127
127
|
|
|
128
|
+
/**
|
|
129
|
+
* @deprecated Garden is deprecated, Use Navigation related methods instead.
|
|
130
|
+
*/
|
|
128
131
|
get garden() {
|
|
129
132
|
if (!this._garden) {
|
|
130
133
|
this._garden = new Garden(this.sceneId)
|
|
@@ -152,7 +155,13 @@ export class Navigator implements Navigator {
|
|
|
152
155
|
props: P = {} as P,
|
|
153
156
|
options: NavigationItem = {},
|
|
154
157
|
) => {
|
|
155
|
-
const success = await Navigation.dispatch(this.sceneId, 'push', {
|
|
158
|
+
const success = await Navigation.dispatch(this.sceneId, 'push', {
|
|
159
|
+
moduleName,
|
|
160
|
+
from: this.moduleName,
|
|
161
|
+
to: moduleName,
|
|
162
|
+
props,
|
|
163
|
+
options,
|
|
164
|
+
})
|
|
156
165
|
if (!success) {
|
|
157
166
|
return [RESULT_CANCEL, null] as [number, T]
|
|
158
167
|
}
|
|
@@ -160,7 +169,10 @@ export class Navigator implements Navigator {
|
|
|
160
169
|
}
|
|
161
170
|
|
|
162
171
|
pushLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
|
|
163
|
-
const success = await Navigation.dispatch(this.sceneId, 'pushLayout', {
|
|
172
|
+
const success = await Navigation.dispatch(this.sceneId, 'pushLayout', {
|
|
173
|
+
from: this.moduleName,
|
|
174
|
+
layout,
|
|
175
|
+
})
|
|
164
176
|
if (!success) {
|
|
165
177
|
return [RESULT_CANCEL, null] as [number, T]
|
|
166
178
|
}
|
|
@@ -193,6 +205,8 @@ export class Navigator implements Navigator {
|
|
|
193
205
|
const requestCode = --tagGenerator
|
|
194
206
|
const success = await Navigation.dispatch(this.sceneId, 'present', {
|
|
195
207
|
moduleName,
|
|
208
|
+
from: this.moduleName,
|
|
209
|
+
to: moduleName,
|
|
196
210
|
props,
|
|
197
211
|
options,
|
|
198
212
|
requestCode,
|
|
@@ -207,6 +221,7 @@ export class Navigator implements Navigator {
|
|
|
207
221
|
const requestCode = --tagGenerator
|
|
208
222
|
const success = await Navigation.dispatch(this.sceneId, 'presentLayout', {
|
|
209
223
|
layout,
|
|
224
|
+
from: this.moduleName,
|
|
210
225
|
requestCode,
|
|
211
226
|
})
|
|
212
227
|
if (!success) {
|
|
@@ -225,6 +240,8 @@ export class Navigator implements Navigator {
|
|
|
225
240
|
const requestCode = --tagGenerator
|
|
226
241
|
const success = await Navigation.dispatch(this.sceneId, 'showModal', {
|
|
227
242
|
moduleName,
|
|
243
|
+
from: this.moduleName,
|
|
244
|
+
to: moduleName,
|
|
228
245
|
props,
|
|
229
246
|
options,
|
|
230
247
|
requestCode,
|
|
@@ -238,6 +255,7 @@ export class Navigator implements Navigator {
|
|
|
238
255
|
showModalLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
|
|
239
256
|
const requestCode = --tagGenerator
|
|
240
257
|
const success = await Navigation.dispatch(this.sceneId, 'showModalLayout', {
|
|
258
|
+
from: this.moduleName,
|
|
241
259
|
layout,
|
|
242
260
|
requestCode,
|
|
243
261
|
})
|
package/src/ReactRegistry.tsx
CHANGED
|
@@ -3,20 +3,23 @@ import type { RouteConfig } from './Route'
|
|
|
3
3
|
|
|
4
4
|
import Navigation, { HOC } from './Navigation'
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
|
|
8
|
+
*/
|
|
6
9
|
export class ReactRegistry {
|
|
7
10
|
/**
|
|
8
11
|
* @deprecated Use Navigation.startRegisterComponent() instead.
|
|
9
12
|
* @param hoc
|
|
10
13
|
*/
|
|
11
14
|
static startRegisterComponent(hoc?: HOC) {
|
|
12
|
-
Navigation.
|
|
15
|
+
Navigation.startRegisterComponent(hoc)
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* @deprecated Use Navigation.endRegisterComponent() instead.
|
|
17
20
|
*/
|
|
18
21
|
static endRegisterComponent() {
|
|
19
|
-
Navigation.
|
|
22
|
+
Navigation.endRegisterComponent()
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
/**
|
|
@@ -31,6 +34,6 @@ export class ReactRegistry {
|
|
|
31
34
|
getComponentFunc: ComponentProvider,
|
|
32
35
|
routeConfig?: RouteConfig,
|
|
33
36
|
) {
|
|
34
|
-
Navigation.
|
|
37
|
+
Navigation.registerComponent(appKey, getComponentFunc, routeConfig)
|
|
35
38
|
}
|
|
36
39
|
}
|
package/src/Route.ts
CHANGED
|
@@ -65,14 +65,6 @@ export interface RouteConfig {
|
|
|
65
65
|
mode?: RouteMode
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
export interface RouteInfo {
|
|
69
|
-
moduleName: string
|
|
70
|
-
dependencies: string[]
|
|
71
|
-
mode: RouteMode
|
|
72
|
-
props: object
|
|
73
|
-
options: object
|
|
74
|
-
}
|
|
75
|
-
|
|
76
68
|
export interface RouteData {
|
|
77
69
|
moduleName: string
|
|
78
70
|
regexp?: RegExp
|
|
@@ -81,8 +73,21 @@ export interface RouteData {
|
|
|
81
73
|
mode: RouteMode
|
|
82
74
|
}
|
|
83
75
|
|
|
76
|
+
export interface RouteInfo {
|
|
77
|
+
moduleName: string
|
|
78
|
+
mode: RouteMode
|
|
79
|
+
dependencies: string[]
|
|
80
|
+
props: object
|
|
81
|
+
options: object
|
|
82
|
+
}
|
|
83
|
+
|
|
84
84
|
export interface RouteHandler {
|
|
85
|
-
|
|
85
|
+
/**
|
|
86
|
+
* @param graph - current RouteGraph to process
|
|
87
|
+
* @param target - route may add to the graph
|
|
88
|
+
* @reurns [boolean, RouteGraph] - if the route is handled, return true and childGraph for next Handler to process, [false, graph] otherwise
|
|
89
|
+
*/
|
|
90
|
+
process: (graph: RouteGraph, target: RouteInfo) => Promise<[boolean, RouteGraph | null]>
|
|
86
91
|
}
|
|
87
92
|
|
|
88
93
|
export type RouteInterceptor = (path: string) => boolean | Promise<boolean>
|
package/src/hooks.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React, { useContext, useEffect, useRef, useState } from 'react'
|
|
2
2
|
import Navigation from './Navigation'
|
|
3
|
-
|
|
4
3
|
import { Navigator, NavigationContext } from './Navigator'
|
|
5
4
|
|
|
6
5
|
export function useVisible() {
|
|
@@ -52,6 +51,10 @@ export function useNavigator(): Navigator {
|
|
|
52
51
|
return useContext<Navigator>(NavigationContext)
|
|
53
52
|
}
|
|
54
53
|
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated Use Navigation related methods instead.
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
55
58
|
export function useGarden() {
|
|
56
59
|
const ctx = useContext<Navigator>(NavigationContext)
|
|
57
60
|
return ctx.garden
|
package/src/index.ts
CHANGED
|
@@ -1,38 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
InjectedProps,
|
|
6
|
-
} from './NavigationComponentWrap'
|
|
7
|
-
|
|
1
|
+
import { Platform } from 'react-native'
|
|
2
|
+
import Event from './Event'
|
|
3
|
+
import GardenModule from './GardenModule'
|
|
4
|
+
import { withNavigation } from './NavigationComponentWrap'
|
|
8
5
|
import Navigation from './Navigation'
|
|
9
6
|
|
|
10
7
|
Navigation.setNavigationComponentWrap(withNavigation)
|
|
11
8
|
|
|
9
|
+
const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT } = GardenModule.getConstants()
|
|
10
|
+
let _statusBarHeight = STATUSBAR_HEIGHT
|
|
11
|
+
if (Platform.OS === 'ios') {
|
|
12
|
+
Event.listenStatusBarHeightChange(height => {
|
|
13
|
+
_statusBarHeight = height
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
function statusBarHeight() {
|
|
13
|
-
return
|
|
18
|
+
return _statusBarHeight
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
function toolbarHeight() {
|
|
17
|
-
return
|
|
22
|
+
return TOOLBAR_HEIGHT
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
function topBarHeight() {
|
|
21
|
-
return
|
|
26
|
+
return statusBarHeight() + toolbarHeight()
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
export default Navigation
|
|
25
|
-
|
|
30
|
+
export { statusBarHeight, toolbarHeight, topBarHeight }
|
|
26
31
|
export { RESULT_OK, RESULT_CANCEL } from './Navigation'
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
withNavigationItem,
|
|
30
|
-
NavigationComponentProps,
|
|
31
|
-
InjectedProps,
|
|
32
|
-
statusBarHeight,
|
|
33
|
-
toolbarHeight,
|
|
34
|
-
topBarHeight,
|
|
35
|
-
}
|
|
32
|
+
export { withNavigationItem, NavigationProps, InjectedProps } from './NavigationComponentWrap'
|
|
36
33
|
|
|
37
34
|
export * from './Navigator'
|
|
38
35
|
export * from './Garden'
|
package/src/router/drawer.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ScreenGraph } from './screen'
|
|
2
|
-
import { Navigator } from '../Navigator'
|
|
1
|
+
import { ScreenGraph, isTargetLocateIn } from './screen'
|
|
3
2
|
import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route'
|
|
3
|
+
import Navigation from '../Navigation'
|
|
4
4
|
|
|
5
5
|
export interface DrawerGraph extends RouteGraph {
|
|
6
6
|
layout: 'drawer'
|
|
@@ -13,22 +13,25 @@ export function isDrawerGraph(graph: RouteGraph): graph is DrawerGraph {
|
|
|
13
13
|
return graph.layout === 'drawer'
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
export class DrawerRouteHandler implements RouteHandler {
|
|
17
|
+
async process(graph: RouteGraph, target: RouteInfo): Promise<[boolean, RouteGraph | null]> {
|
|
18
|
+
if (!isDrawerGraph(graph)) {
|
|
19
|
+
throw new Error(`${graph} is Not a DrawerGraph`)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { children } = graph
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return true
|
|
26
|
-
} else {
|
|
27
|
-
let result = await next(graph.children[0], route, next)
|
|
28
|
-
if (result) {
|
|
29
|
-
const navigator = Navigator.of(sceneId)
|
|
30
|
-
navigator.closeMenu()
|
|
24
|
+
const { moduleName, sceneId } = children[1]
|
|
25
|
+
if (moduleName === target.moduleName) {
|
|
26
|
+
await Navigation.dispatch(sceneId, 'openMenu')
|
|
27
|
+
return [true, null]
|
|
31
28
|
}
|
|
32
|
-
|
|
29
|
+
|
|
30
|
+
if (isTargetLocateIn(children[0], target)) {
|
|
31
|
+
Navigation.dispatch(sceneId, 'closeMenu', { from: moduleName })
|
|
32
|
+
return [true, children[0]]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return [false, graph]
|
|
33
36
|
}
|
|
34
37
|
}
|