hybrid-navigation 2.13.0-beta.3 → 2.13.1
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/lib/Event.d.ts +12 -16
- package/lib/Event.js +20 -66
- package/lib/Garden.d.ts +49 -6
- package/lib/Garden.js +56 -32
- package/lib/Navigation.d.ts +68 -0
- package/lib/Navigation.js +162 -0
- package/lib/NavigationComponentWrap.d.ts +19 -0
- package/lib/NavigationComponentWrap.js +46 -0
- package/lib/Navigator.d.ts +46 -32
- package/lib/Navigator.js +110 -169
- package/lib/ReactRegistry.d.ts +19 -13
- package/lib/ReactRegistry.js +21 -73
- package/lib/Route.d.ts +13 -8
- package/lib/handler/BarButtonEventHandler.d.ts +10 -0
- package/lib/handler/BarButtonEventHandler.js +38 -0
- package/lib/handler/DispatchCommandHandler.d.ts +26 -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 +4 -0
- package/lib/hooks.js +13 -18
- package/lib/index.d.ts +8 -1
- package/lib/index.js +26 -2
- 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 +140 -116
- 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/Event.ts +25 -90
- package/src/Garden.ts +60 -38
- package/src/Navigation.ts +253 -0
- package/src/NavigationComponentWrap.tsx +73 -0
- package/src/Navigator.ts +124 -233
- package/src/ReactRegistry.tsx +23 -99
- package/src/Route.ts +14 -9
- package/src/handler/BarButtonEventHandler.ts +50 -0
- package/src/handler/DispatchCommandHandler.ts +58 -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 +18 -30
- package/src/index.ts +38 -4
- package/src/router/drawer.ts +20 -17
- package/src/router/index.ts +150 -119
- package/src/router/screen.ts +34 -1
- package/src/router/stack.ts +61 -48
- package/src/router/tabs.ts +19 -29
package/lib/Route.d.ts
CHANGED
|
@@ -54,13 +54,6 @@ export interface RouteConfig {
|
|
|
54
54
|
dependency?: string;
|
|
55
55
|
mode?: RouteMode;
|
|
56
56
|
}
|
|
57
|
-
export interface RouteInfo {
|
|
58
|
-
moduleName: string;
|
|
59
|
-
dependencies: string[];
|
|
60
|
-
mode: RouteMode;
|
|
61
|
-
props: object;
|
|
62
|
-
options: object;
|
|
63
|
-
}
|
|
64
57
|
export interface RouteData {
|
|
65
58
|
moduleName: string;
|
|
66
59
|
regexp?: RegExp;
|
|
@@ -68,7 +61,19 @@ export interface RouteData {
|
|
|
68
61
|
dependency?: string;
|
|
69
62
|
mode: RouteMode;
|
|
70
63
|
}
|
|
64
|
+
export interface RouteInfo {
|
|
65
|
+
moduleName: string;
|
|
66
|
+
mode: RouteMode;
|
|
67
|
+
dependencies: string[];
|
|
68
|
+
props: object;
|
|
69
|
+
options: object;
|
|
70
|
+
}
|
|
71
71
|
export interface RouteHandler {
|
|
72
|
-
|
|
72
|
+
/**
|
|
73
|
+
* @param graph - current RouteGraph to process
|
|
74
|
+
* @param target - route may add to the graph
|
|
75
|
+
* @reurns [boolean, RouteGraph] - if the route is handled, return true and childGraph for next Handler to process, [false, graph] otherwise
|
|
76
|
+
*/
|
|
77
|
+
process: (graph: RouteGraph, target: RouteInfo) => Promise<[boolean, RouteGraph | null]>;
|
|
73
78
|
}
|
|
74
79
|
export declare type RouteInterceptor = (path: string) => boolean | Promise<boolean>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare type BarButtonClickEventListener = (sceneId: string, value: Function) => void;
|
|
2
|
+
export default class BarButtonEventHandler {
|
|
3
|
+
private actions;
|
|
4
|
+
private keyPairs;
|
|
5
|
+
private actionIdGenerator;
|
|
6
|
+
bindBarButtonClickEvent(sceneId: string, item: object | null | undefined): object | null;
|
|
7
|
+
unbindBarButtonClickEvent(sceneId: string): void;
|
|
8
|
+
setBarButtonClickEventListener(handler: BarButtonClickEventListener): void;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import Event from '../Event';
|
|
2
|
+
export default class BarButtonEventHandler {
|
|
3
|
+
actions = {};
|
|
4
|
+
keyPairs = {};
|
|
5
|
+
actionIdGenerator = 0;
|
|
6
|
+
bindBarButtonClickEvent(sceneId, item) {
|
|
7
|
+
if (item === null || item === undefined) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return JSON.parse(JSON.stringify(item, (key, value) => {
|
|
11
|
+
if (key !== 'action' || typeof value !== 'function') {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
const actionKey = 'ON_BAR_BUTTON_ITEM_CLICK_' + this.actionIdGenerator++;
|
|
15
|
+
if (!this.keyPairs[sceneId]) {
|
|
16
|
+
this.keyPairs[sceneId] = [];
|
|
17
|
+
}
|
|
18
|
+
this.keyPairs[sceneId].push(actionKey);
|
|
19
|
+
this.actions[actionKey] = value;
|
|
20
|
+
return actionKey;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
unbindBarButtonClickEvent(sceneId) {
|
|
24
|
+
const keys = this.keyPairs[sceneId];
|
|
25
|
+
delete this.keyPairs[sceneId];
|
|
26
|
+
if (keys) {
|
|
27
|
+
keys.forEach(key => delete this.actions[key]);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
setBarButtonClickEventListener(handler) {
|
|
31
|
+
Event.listenBarButtonItemClick((sceneId, action) => {
|
|
32
|
+
const listeners = this.actions;
|
|
33
|
+
if (listeners[action]) {
|
|
34
|
+
handler(sceneId, listeners[action]);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { NavigationItem } from '../Options';
|
|
2
|
+
import { BuildInLayout, Layout } from '../Route';
|
|
3
|
+
export interface DispatchParams {
|
|
4
|
+
animated?: boolean;
|
|
5
|
+
moduleName?: string;
|
|
6
|
+
from?: string | number;
|
|
7
|
+
to?: string | number;
|
|
8
|
+
layout?: BuildInLayout | Layout;
|
|
9
|
+
popToRoot?: boolean;
|
|
10
|
+
requestCode?: number;
|
|
11
|
+
props?: object;
|
|
12
|
+
options?: NavigationItem;
|
|
13
|
+
[index: string]: any;
|
|
14
|
+
}
|
|
15
|
+
interface InterceptParams {
|
|
16
|
+
sceneId: string;
|
|
17
|
+
from?: number | string;
|
|
18
|
+
to?: number | string;
|
|
19
|
+
}
|
|
20
|
+
export declare type NavigationInterceptor = (action: string, params: InterceptParams) => boolean | Promise<boolean>;
|
|
21
|
+
export default class DispatchCommandHandler {
|
|
22
|
+
private interceptor;
|
|
23
|
+
dispatch(sceneId: string, action: string, params: DispatchParams): Promise<boolean>;
|
|
24
|
+
setInterceptor(interceptor: NavigationInterceptor): void;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import NavigationModule from '../NavigationModule';
|
|
2
|
+
export default class DispatchCommandHandler {
|
|
3
|
+
interceptor = () => false;
|
|
4
|
+
async dispatch(sceneId, action, params) {
|
|
5
|
+
let intercepted = false;
|
|
6
|
+
const { from, to } = params;
|
|
7
|
+
if (this.interceptor) {
|
|
8
|
+
const result = this.interceptor(action, {
|
|
9
|
+
sceneId,
|
|
10
|
+
from,
|
|
11
|
+
to,
|
|
12
|
+
});
|
|
13
|
+
if (result instanceof Promise) {
|
|
14
|
+
intercepted = await result;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
intercepted = result;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (!intercepted) {
|
|
21
|
+
return NavigationModule.dispatch(sceneId, action, params);
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
setInterceptor(interceptor) {
|
|
26
|
+
this.interceptor = interceptor;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BuildInLayout, Layout } from '../Route';
|
|
2
|
+
export default class LayoutCommandHandler {
|
|
3
|
+
private willSetRoot;
|
|
4
|
+
private didSetRoot;
|
|
5
|
+
private canInvokeWillSetRoot;
|
|
6
|
+
private tagGenerator;
|
|
7
|
+
constructor();
|
|
8
|
+
handleRootLayoutChange(): void;
|
|
9
|
+
setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<void>;
|
|
10
|
+
setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import Event from '../Event';
|
|
2
|
+
import NavigationModule from '../NavigationModule';
|
|
3
|
+
export default class LayoutCommandHandler {
|
|
4
|
+
willSetRoot = () => { };
|
|
5
|
+
didSetRoot = () => { };
|
|
6
|
+
canInvokeWillSetRoot = true;
|
|
7
|
+
tagGenerator = 0;
|
|
8
|
+
constructor() { }
|
|
9
|
+
handleRootLayoutChange() {
|
|
10
|
+
Event.listenWillSetRoot(() => {
|
|
11
|
+
if (this.canInvokeWillSetRoot) {
|
|
12
|
+
this.willSetRoot();
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
Event.listenDidSetRoot(() => {
|
|
16
|
+
this.didSetRoot();
|
|
17
|
+
this.canInvokeWillSetRoot = true;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
setRoot(layout, sticky = false) {
|
|
21
|
+
this.willSetRoot();
|
|
22
|
+
this.canInvokeWillSetRoot = false;
|
|
23
|
+
const flag = this.tagGenerator++;
|
|
24
|
+
NavigationModule.setRoot(layout, sticky, flag);
|
|
25
|
+
return new Promise(resolve => {
|
|
26
|
+
const subscription = Event.listenDidSetRoot((tag) => {
|
|
27
|
+
// FIXME: 此处恐有内存泄漏
|
|
28
|
+
if (tag === flag) {
|
|
29
|
+
subscription.remove();
|
|
30
|
+
resolve();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
setRootLayoutUpdateListener(willSetRoot = () => { }, didSetRoot = () => { }) {
|
|
36
|
+
this.willSetRoot = willSetRoot;
|
|
37
|
+
this.didSetRoot = didSetRoot;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface IndexType {
|
|
2
|
+
[index: string]: any;
|
|
3
|
+
}
|
|
4
|
+
export declare type ResultType = IndexType | null;
|
|
5
|
+
export declare type ResultEventListener<T extends ResultType> = (resultCode: number, data: T) => void;
|
|
6
|
+
export default class ResultEventHandler {
|
|
7
|
+
private listeners;
|
|
8
|
+
constructor();
|
|
9
|
+
handleComponentResult(): void;
|
|
10
|
+
private addResultEventListener;
|
|
11
|
+
private removeResultEventListener;
|
|
12
|
+
invalidateResultEventListener(sceneId: string): void;
|
|
13
|
+
waitResult<T extends ResultType>(sceneId: string, requestCode: number): Promise<[number, T]>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Event from '../Event';
|
|
2
|
+
import NavigationModule from '../NavigationModule';
|
|
3
|
+
const { RESULT_CANCEL } = NavigationModule.getConstants();
|
|
4
|
+
export default class ResultEventHandler {
|
|
5
|
+
listeners = {};
|
|
6
|
+
constructor() { }
|
|
7
|
+
handleComponentResult() {
|
|
8
|
+
Event.listenComponentResult((sceneId, requestCode, resultCode, data) => {
|
|
9
|
+
const listener = this.listeners[sceneId]?.[requestCode];
|
|
10
|
+
if (listener) {
|
|
11
|
+
delete this.listeners[sceneId][requestCode];
|
|
12
|
+
listener(resultCode, data);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
addResultEventListener(sceneId, requestCode, listener) {
|
|
17
|
+
if (!this.listeners[sceneId]) {
|
|
18
|
+
this.listeners[sceneId] = {};
|
|
19
|
+
}
|
|
20
|
+
const previousListener = this.listeners[sceneId][requestCode];
|
|
21
|
+
if (previousListener) {
|
|
22
|
+
previousListener(RESULT_CANCEL, null);
|
|
23
|
+
}
|
|
24
|
+
this.listeners[sceneId][requestCode] = listener;
|
|
25
|
+
}
|
|
26
|
+
removeResultEventListener(sceneId, requestCode) {
|
|
27
|
+
if (this.listeners[sceneId]) {
|
|
28
|
+
delete this.listeners[sceneId][requestCode];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
invalidateResultEventListener(sceneId) {
|
|
32
|
+
const listeners = this.listeners[sceneId];
|
|
33
|
+
if (listeners) {
|
|
34
|
+
Object.values(listeners).forEach(listener => listener(RESULT_CANCEL, null));
|
|
35
|
+
}
|
|
36
|
+
delete this.listeners[sceneId];
|
|
37
|
+
}
|
|
38
|
+
waitResult(sceneId, requestCode) {
|
|
39
|
+
return new Promise(resolve => {
|
|
40
|
+
const listener = (resultCode, data) => {
|
|
41
|
+
this.removeResultEventListener(sceneId, requestCode);
|
|
42
|
+
resolve([resultCode, data]);
|
|
43
|
+
};
|
|
44
|
+
this.addResultEventListener(sceneId, requestCode, listener);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Visibility } from '../Route';
|
|
2
|
+
export declare type VisibilityEventListener = (visibility: Visibility) => void;
|
|
3
|
+
export declare type GlobalVisibilityEventListener = (sceneId: string, visibility: Visibility) => void;
|
|
4
|
+
export default class VisibilityEventHandler {
|
|
5
|
+
private listeners;
|
|
6
|
+
private globalListeners;
|
|
7
|
+
constructor();
|
|
8
|
+
handleComponentVisibility(): void;
|
|
9
|
+
addGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener): void;
|
|
10
|
+
removeGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener): void;
|
|
11
|
+
addVisibilityEventListener(sceneId: string, listener: VisibilityEventListener): void;
|
|
12
|
+
removeVisibilityEventListener(sceneId: string, listener: VisibilityEventListener): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import Event from '../Event';
|
|
2
|
+
export default class VisibilityEventHandler {
|
|
3
|
+
listeners = {};
|
|
4
|
+
globalListeners = [];
|
|
5
|
+
constructor() { }
|
|
6
|
+
handleComponentVisibility() {
|
|
7
|
+
Event.listenComponentVisibility((sceneId, visibility) => {
|
|
8
|
+
const listeners = this.listeners[sceneId];
|
|
9
|
+
if (listeners) {
|
|
10
|
+
listeners.forEach(listener => listener(visibility));
|
|
11
|
+
}
|
|
12
|
+
this.globalListeners.forEach(listener => listener(sceneId, visibility));
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
addGlobalVisibilityEventListener(listener) {
|
|
16
|
+
this.globalListeners.push(listener);
|
|
17
|
+
}
|
|
18
|
+
removeGlobalVisibilityEventListener(listener) {
|
|
19
|
+
this.globalListeners = this.globalListeners.filter(l => l !== listener);
|
|
20
|
+
}
|
|
21
|
+
addVisibilityEventListener(sceneId, listener) {
|
|
22
|
+
if (!this.listeners[sceneId]) {
|
|
23
|
+
this.listeners[sceneId] = [];
|
|
24
|
+
}
|
|
25
|
+
this.listeners[sceneId].push(listener);
|
|
26
|
+
}
|
|
27
|
+
removeVisibilityEventListener(sceneId, listener) {
|
|
28
|
+
if (this.listeners[sceneId]) {
|
|
29
|
+
this.listeners[sceneId] = this.listeners[sceneId].filter(l => l !== listener);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
package/lib/hooks.d.ts
CHANGED
|
@@ -4,4 +4,8 @@ export declare function useVisible(): boolean;
|
|
|
4
4
|
export declare function useVisibility(): "visible" | "invisible" | "pending";
|
|
5
5
|
export declare function useVisibleEffect(effect: React.EffectCallback): void;
|
|
6
6
|
export declare function useNavigator(): Navigator;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use Navigation related methods instead.
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
7
11
|
export declare function useGarden(): import("./Garden").Garden;
|
package/lib/hooks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useContext, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import Navigation from './Navigation';
|
|
3
3
|
import { NavigationContext } from './Navigator';
|
|
4
4
|
export function useVisible() {
|
|
5
5
|
const visibility = useVisibility();
|
|
@@ -9,14 +9,8 @@ export function useVisibility() {
|
|
|
9
9
|
const navigator = useNavigator();
|
|
10
10
|
const [visibility, setVisibility] = useState(navigator.visibility);
|
|
11
11
|
useEffect(() => {
|
|
12
|
-
const subscription =
|
|
13
|
-
|
|
14
|
-
setVisibility('visible');
|
|
15
|
-
}
|
|
16
|
-
}, (sceneId) => {
|
|
17
|
-
if (sceneId === navigator.sceneId) {
|
|
18
|
-
setVisibility('invisible');
|
|
19
|
-
}
|
|
12
|
+
const subscription = Navigation.addVisibilityEventListener(navigator.sceneId, v => {
|
|
13
|
+
setVisibility(v);
|
|
20
14
|
});
|
|
21
15
|
return () => subscription.remove();
|
|
22
16
|
}, [navigator]);
|
|
@@ -29,21 +23,18 @@ export function useVisibleEffect(effect) {
|
|
|
29
23
|
if (navigator.visibility === 'visible') {
|
|
30
24
|
destructor.current = effect();
|
|
31
25
|
}
|
|
32
|
-
const subscription =
|
|
33
|
-
if (
|
|
26
|
+
const subscription = Navigation.addVisibilityEventListener(navigator.sceneId, visibility => {
|
|
27
|
+
if (visibility === 'visible') {
|
|
34
28
|
destructor.current = effect();
|
|
35
29
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
destructor.current();
|
|
30
|
+
else {
|
|
31
|
+
destructor.current && destructor.current();
|
|
39
32
|
destructor.current = undefined;
|
|
40
33
|
}
|
|
41
34
|
});
|
|
42
35
|
return () => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
destructor.current = undefined;
|
|
46
|
-
}
|
|
36
|
+
destructor.current && destructor.current();
|
|
37
|
+
destructor.current = undefined;
|
|
47
38
|
subscription.remove();
|
|
48
39
|
};
|
|
49
40
|
}, [effect, navigator]);
|
|
@@ -51,6 +42,10 @@ export function useVisibleEffect(effect) {
|
|
|
51
42
|
export function useNavigator() {
|
|
52
43
|
return useContext(NavigationContext);
|
|
53
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Use Navigation related methods instead.
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
54
49
|
export function useGarden() {
|
|
55
50
|
const ctx = useContext(NavigationContext);
|
|
56
51
|
return ctx.garden;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import Navigation from './Navigation';
|
|
2
|
+
declare function statusBarHeight(): number;
|
|
3
|
+
declare function toolbarHeight(): number;
|
|
4
|
+
declare function topBarHeight(): number;
|
|
5
|
+
export default Navigation;
|
|
6
|
+
export { statusBarHeight, toolbarHeight, topBarHeight };
|
|
7
|
+
export { RESULT_OK, RESULT_CANCEL } from './Navigation';
|
|
8
|
+
export { withNavigation, withNavigationItem, NavigationProps, InjectedProps, } from './NavigationComponentWrap';
|
|
1
9
|
export * from './Navigator';
|
|
2
10
|
export * from './Garden';
|
|
3
11
|
export * from './ReactRegistry';
|
|
@@ -6,4 +14,3 @@ export * from './router';
|
|
|
6
14
|
export * from './DeepLink';
|
|
7
15
|
export * from './Route';
|
|
8
16
|
export * from './Options';
|
|
9
|
-
export declare const RESULT_OK: number, RESULT_CANCEL: number;
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import Navigation from './Navigation';
|
|
3
|
+
import Event from './Event';
|
|
4
|
+
import GardenModule from './GardenModule';
|
|
5
|
+
import { withNavigation } from './NavigationComponentWrap';
|
|
6
|
+
Navigation.setNavigationComponentWrap(withNavigation);
|
|
7
|
+
const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT } = GardenModule.getConstants();
|
|
8
|
+
let _statusBarHeight = STATUSBAR_HEIGHT;
|
|
9
|
+
if (Platform.OS === 'ios') {
|
|
10
|
+
Event.listenStatusBarHeightChange(height => {
|
|
11
|
+
_statusBarHeight = height;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function statusBarHeight() {
|
|
15
|
+
return _statusBarHeight;
|
|
16
|
+
}
|
|
17
|
+
function toolbarHeight() {
|
|
18
|
+
return TOOLBAR_HEIGHT;
|
|
19
|
+
}
|
|
20
|
+
function topBarHeight() {
|
|
21
|
+
return statusBarHeight() + toolbarHeight();
|
|
22
|
+
}
|
|
23
|
+
export default Navigation;
|
|
24
|
+
export { statusBarHeight, toolbarHeight, topBarHeight };
|
|
25
|
+
export { RESULT_OK, RESULT_CANCEL } from './Navigation';
|
|
26
|
+
export { withNavigation, withNavigationItem, } from './NavigationComponentWrap';
|
|
1
27
|
export * from './Navigator';
|
|
2
28
|
export * from './Garden';
|
|
3
29
|
export * from './ReactRegistry';
|
|
@@ -6,5 +32,3 @@ export * from './router';
|
|
|
6
32
|
export * from './DeepLink';
|
|
7
33
|
export * from './Route';
|
|
8
34
|
export * from './Options';
|
|
9
|
-
import NavigationModule from './NavigationModule';
|
|
10
|
-
export const { RESULT_OK, RESULT_CANCEL } = NavigationModule.getConstants();
|
package/lib/router/drawer.d.ts
CHANGED
|
@@ -7,4 +7,6 @@ export interface DrawerGraph extends RouteGraph {
|
|
|
7
7
|
children: [RouteGraph, ScreenGraph];
|
|
8
8
|
}
|
|
9
9
|
export declare function isDrawerGraph(graph: RouteGraph): graph is DrawerGraph;
|
|
10
|
-
export declare
|
|
10
|
+
export declare class DrawerRouteHandler implements RouteHandler {
|
|
11
|
+
process(graph: RouteGraph, target: RouteInfo): Promise<[boolean, RouteGraph | null]>;
|
|
12
|
+
}
|
package/lib/router/drawer.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isTargetLocateIn } from './screen';
|
|
2
|
+
import Navigation from '../Navigation';
|
|
2
3
|
export function isDrawerGraph(graph) {
|
|
3
4
|
return graph.layout === 'drawer';
|
|
4
5
|
}
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
navigator.closeMenu();
|
|
6
|
+
export class DrawerRouteHandler {
|
|
7
|
+
async process(graph, target) {
|
|
8
|
+
if (!isDrawerGraph(graph)) {
|
|
9
|
+
throw new Error(`${graph} is Not a DrawerGraph`);
|
|
10
|
+
}
|
|
11
|
+
const { children } = graph;
|
|
12
|
+
const { moduleName, sceneId } = children[1];
|
|
13
|
+
if (moduleName === target.moduleName) {
|
|
14
|
+
await Navigation.dispatch(sceneId, 'openMenu');
|
|
15
|
+
return [true, null];
|
|
16
|
+
}
|
|
17
|
+
if (isTargetLocateIn(children[0], target)) {
|
|
18
|
+
Navigation.dispatch(sceneId, 'closeMenu', { from: moduleName });
|
|
19
|
+
return [true, children[0]];
|
|
20
20
|
}
|
|
21
|
-
return
|
|
21
|
+
return [false, graph];
|
|
22
22
|
}
|
|
23
23
|
}
|
package/lib/router/index.d.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RouteHandler, RouteInterceptor } from '../Route';
|
|
2
2
|
import { NavigationItem } from '../Options';
|
|
3
|
-
declare
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
declare class Router {
|
|
4
|
+
constructor();
|
|
5
|
+
private handlers;
|
|
6
|
+
registerRouteHandler(layout: string, handler: RouteHandler): void;
|
|
7
|
+
private convertConfigToData;
|
|
8
|
+
private isRouteConfigInflated;
|
|
9
|
+
private routeDatas;
|
|
10
|
+
private inflateRouteData;
|
|
11
|
+
private interceptors;
|
|
12
|
+
addInterceptor(interceptor: RouteInterceptor): void;
|
|
13
|
+
removeInterceptor(interceptor: RouteInterceptor): void;
|
|
14
|
+
private intercept;
|
|
15
|
+
private pathToRoute;
|
|
16
|
+
private routeDependencies;
|
|
17
|
+
private processRoute;
|
|
18
|
+
open(path: string, props?: object, options?: NavigationItem): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare const router: Router;
|
|
17
21
|
export * from './drawer';
|
|
18
22
|
export * from './screen';
|
|
19
23
|
export * from './stack';
|