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/lib/ReactRegistry.js
CHANGED
|
@@ -1,101 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import React, { useEffect, createContext } from 'react';
|
|
3
|
-
import { Navigator } from './Navigator';
|
|
4
|
-
import { NavigationModule, EventEmitter, EVENT_NAVIGATION, KEY_SCENE_ID, KEY_ON, ON_COMPONENT_APPEAR, ON_COMPONENT_DISAPPEAR, } from './NavigationModule';
|
|
5
|
-
import { router } from './router';
|
|
6
|
-
import store from './store';
|
|
7
|
-
import { bindBarButtonItemClickEvent, removeBarButtonItemClickEvent } from './utils';
|
|
8
|
-
function getDisplayName(WrappedComponent) {
|
|
9
|
-
return WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
10
|
-
}
|
|
11
|
-
export const NavigationContext = createContext(null);
|
|
12
|
-
function withNavigator(moduleName) {
|
|
13
|
-
return function (WrappedComponent) {
|
|
14
|
-
const FC = React.forwardRef((props, ref) => {
|
|
15
|
-
const { sceneId } = props;
|
|
16
|
-
const navigator = Navigator.of(sceneId);
|
|
17
|
-
if (navigator.moduleName === undefined) {
|
|
18
|
-
navigator.moduleName = moduleName;
|
|
19
|
-
}
|
|
20
|
-
const garden = navigator.garden;
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
navigator.signalFirstRenderComplete();
|
|
23
|
-
return () => {
|
|
24
|
-
removeBarButtonItemClickEvent(navigator.sceneId);
|
|
25
|
-
store.removeNavigator(navigator.sceneId);
|
|
26
|
-
navigator.unmount();
|
|
27
|
-
};
|
|
28
|
-
}, [navigator]);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
const subscription = EventEmitter.addListener(EVENT_NAVIGATION, data => {
|
|
31
|
-
if (navigator.sceneId === data[KEY_SCENE_ID]) {
|
|
32
|
-
if (data[KEY_ON] === ON_COMPONENT_APPEAR) {
|
|
33
|
-
navigator.visibility = 'visible';
|
|
34
|
-
}
|
|
35
|
-
else if (data[KEY_ON] === ON_COMPONENT_DISAPPEAR) {
|
|
36
|
-
navigator.visibility = 'invisible';
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
return () => {
|
|
41
|
-
subscription.remove();
|
|
42
|
-
};
|
|
43
|
-
}, [navigator]);
|
|
44
|
-
const injected = {
|
|
45
|
-
garden,
|
|
46
|
-
navigator,
|
|
47
|
-
};
|
|
48
|
-
return (<NavigationContext.Provider value={navigator}>
|
|
49
|
-
<WrappedComponent ref={ref} {...props} {...injected}/>
|
|
50
|
-
</NavigationContext.Provider>);
|
|
51
|
-
});
|
|
52
|
-
FC.displayName = `withNavigator(${getDisplayName(WrappedComponent)})`;
|
|
53
|
-
return FC;
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
let wrap;
|
|
1
|
+
import Navigation from './Navigation';
|
|
57
2
|
export class ReactRegistry {
|
|
58
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Use Navigation.startRegisterComponent() instead.
|
|
5
|
+
* @param hoc
|
|
6
|
+
*/
|
|
59
7
|
static startRegisterComponent(hoc) {
|
|
60
|
-
|
|
61
|
-
wrap = hoc;
|
|
62
|
-
ReactRegistry.registerEnded = false;
|
|
63
|
-
NavigationModule.startRegisterReactComponent();
|
|
8
|
+
Navigation.startRegisterComponent(hoc);
|
|
64
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use Navigation.endRegisterComponent() instead.
|
|
12
|
+
*/
|
|
65
13
|
static endRegisterComponent() {
|
|
66
|
-
|
|
67
|
-
console.warn(`Please don't call ReactRegistry#endRegisterComponent multiple times.`);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
ReactRegistry.registerEnded = true;
|
|
71
|
-
NavigationModule.endRegisterReactComponent();
|
|
14
|
+
Navigation.endRegisterComponent();
|
|
72
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @deprecated Use Navigation.registerComponent() instead.
|
|
19
|
+
* @param appKey
|
|
20
|
+
* @param getComponentFunc
|
|
21
|
+
* @param routeConfig
|
|
22
|
+
*/
|
|
73
23
|
static registerComponent(appKey, getComponentFunc, routeConfig) {
|
|
74
|
-
|
|
75
|
-
router.registerRoute(appKey, routeConfig);
|
|
76
|
-
}
|
|
77
|
-
let WrappedComponent = getComponentFunc();
|
|
78
|
-
if (wrap) {
|
|
79
|
-
WrappedComponent = wrap(WrappedComponent);
|
|
80
|
-
}
|
|
81
|
-
// build static options
|
|
82
|
-
let options = bindBarButtonItemClickEvent(WrappedComponent.navigationItem) || {};
|
|
83
|
-
NavigationModule.registerReactComponent(appKey, options);
|
|
84
|
-
let RootComponent = withNavigator(appKey)(WrappedComponent);
|
|
85
|
-
AppRegistry.registerComponent(appKey, () => RootComponent);
|
|
24
|
+
Navigation.registerComponent(appKey, getComponentFunc, routeConfig);
|
|
86
25
|
}
|
|
87
26
|
}
|
|
88
|
-
export function withNavigationItem(item) {
|
|
89
|
-
return function (WrappedComponent) {
|
|
90
|
-
let navigationItem = WrappedComponent.navigationItem;
|
|
91
|
-
if (navigationItem) {
|
|
92
|
-
;
|
|
93
|
-
WrappedComponent.navigationItem = { ...navigationItem, ...item };
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
;
|
|
97
|
-
WrappedComponent.navigationItem = item;
|
|
98
|
-
}
|
|
99
|
-
return WrappedComponent;
|
|
100
|
-
};
|
|
101
|
-
}
|
package/lib/Route.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export declare type Visibility = 'visible' | 'invisible' | 'pending';
|
|
2
|
+
export interface Screen extends Layout {
|
|
3
|
+
screen: {
|
|
4
|
+
moduleName: string;
|
|
5
|
+
props?: object;
|
|
6
|
+
options?: {};
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface Stack extends Layout {
|
|
10
|
+
stack: {
|
|
11
|
+
children: Array<BuildInLayout | Layout>;
|
|
12
|
+
options?: {};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface Tabs extends Layout {
|
|
16
|
+
tabs: {
|
|
17
|
+
children: Array<BuildInLayout | Layout>;
|
|
18
|
+
options?: {
|
|
19
|
+
selectedIndex?: number;
|
|
20
|
+
tabBarModuleName?: string;
|
|
21
|
+
sizeIndeterminate?: boolean;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface Drawer extends Layout {
|
|
26
|
+
drawer: {
|
|
27
|
+
children: [BuildInLayout | Layout, BuildInLayout | Layout];
|
|
28
|
+
options?: {
|
|
29
|
+
maxDrawerWidth?: number;
|
|
30
|
+
minDrawerMargin?: number;
|
|
31
|
+
menuInteractive?: boolean;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export declare type BuildInLayout = Screen | Stack | Tabs | Drawer;
|
|
36
|
+
export interface Layout {
|
|
37
|
+
[index: string]: {};
|
|
38
|
+
}
|
|
39
|
+
export declare type RouteMode = 'modal' | 'present' | 'push';
|
|
40
|
+
export declare type LayoutMode = 'modal' | 'present' | 'normal';
|
|
41
|
+
export interface Route {
|
|
42
|
+
sceneId: string;
|
|
43
|
+
moduleName: string;
|
|
44
|
+
mode: LayoutMode;
|
|
45
|
+
}
|
|
46
|
+
export interface RouteGraph {
|
|
47
|
+
layout: string;
|
|
48
|
+
sceneId: string;
|
|
49
|
+
mode: LayoutMode;
|
|
50
|
+
children?: RouteGraph[];
|
|
51
|
+
}
|
|
52
|
+
export interface RouteConfig {
|
|
53
|
+
path?: string;
|
|
54
|
+
dependency?: string;
|
|
55
|
+
mode?: RouteMode;
|
|
56
|
+
}
|
|
57
|
+
export interface RouteInfo {
|
|
58
|
+
moduleName: string;
|
|
59
|
+
dependencies: string[];
|
|
60
|
+
mode: RouteMode;
|
|
61
|
+
props: object;
|
|
62
|
+
options: object;
|
|
63
|
+
}
|
|
64
|
+
export interface RouteData {
|
|
65
|
+
moduleName: string;
|
|
66
|
+
regexp?: RegExp;
|
|
67
|
+
path?: string;
|
|
68
|
+
dependency?: string;
|
|
69
|
+
mode: RouteMode;
|
|
70
|
+
}
|
|
71
|
+
export interface RouteHandler {
|
|
72
|
+
(graph: RouteGraph, route: RouteInfo, next: RouteHandler): Promise<boolean>;
|
|
73
|
+
}
|
|
74
|
+
export declare type RouteInterceptor = (path: string) => boolean | Promise<boolean>;
|
|
File without changes
|
|
@@ -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,24 @@
|
|
|
1
|
+
import { NavigationItem } from '../Options';
|
|
2
|
+
import { BuildInLayout, Layout } from '../Route';
|
|
3
|
+
export interface DispatchParams {
|
|
4
|
+
animated?: boolean;
|
|
5
|
+
moduleName?: string;
|
|
6
|
+
layout?: BuildInLayout | Layout;
|
|
7
|
+
popToRoot?: boolean;
|
|
8
|
+
requestCode?: number;
|
|
9
|
+
props?: object;
|
|
10
|
+
options?: NavigationItem;
|
|
11
|
+
[index: string]: any;
|
|
12
|
+
}
|
|
13
|
+
interface InterceptParams {
|
|
14
|
+
sceneId: string;
|
|
15
|
+
from?: number | string;
|
|
16
|
+
to?: number | string;
|
|
17
|
+
}
|
|
18
|
+
export declare type NavigationInterceptor = (action: string, params: InterceptParams) => boolean | Promise<boolean>;
|
|
19
|
+
export default class DispatchCommandHandler {
|
|
20
|
+
private interceptor;
|
|
21
|
+
dispatch(sceneId: string, action: string, params: DispatchParams): Promise<boolean>;
|
|
22
|
+
setInterceptor(interceptor: NavigationInterceptor): void;
|
|
23
|
+
}
|
|
24
|
+
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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Navigator } from './Navigator';
|
|
3
|
-
export declare type Visibility = 'visible' | 'invisible' | 'pending';
|
|
4
3
|
export declare function useVisible(): boolean;
|
|
5
4
|
export declare function useVisibility(): "visible" | "invisible" | "pending";
|
|
6
5
|
export declare function useVisibleEffect(effect: React.EffectCallback): void;
|
package/lib/hooks.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useContext, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import
|
|
3
|
-
import { NavigationContext } from './
|
|
2
|
+
import Navigation from './Navigation';
|
|
3
|
+
import { NavigationContext } from './Navigator';
|
|
4
4
|
export function useVisible() {
|
|
5
5
|
const visibility = useVisibility();
|
|
6
6
|
return visibility === 'visible';
|
|
@@ -9,19 +9,10 @@ export function useVisibility() {
|
|
|
9
9
|
const navigator = useNavigator();
|
|
10
10
|
const [visibility, setVisibility] = useState(navigator.visibility);
|
|
11
11
|
useEffect(() => {
|
|
12
|
-
const subscription =
|
|
13
|
-
|
|
14
|
-
if (data[KEY_ON] === ON_COMPONENT_APPEAR) {
|
|
15
|
-
setVisibility('visible');
|
|
16
|
-
}
|
|
17
|
-
else if (data[KEY_ON] === ON_COMPONENT_DISAPPEAR) {
|
|
18
|
-
setVisibility('invisible');
|
|
19
|
-
}
|
|
20
|
-
}
|
|
12
|
+
const subscription = Navigation.addVisibilityEventListener(navigator.sceneId, v => {
|
|
13
|
+
setVisibility(v);
|
|
21
14
|
});
|
|
22
|
-
return () =>
|
|
23
|
-
subscription.remove();
|
|
24
|
-
};
|
|
15
|
+
return () => subscription.remove();
|
|
25
16
|
}, [navigator]);
|
|
26
17
|
return visibility;
|
|
27
18
|
}
|
|
@@ -32,24 +23,18 @@ export function useVisibleEffect(effect) {
|
|
|
32
23
|
if (navigator.visibility === 'visible') {
|
|
33
24
|
destructor.current = effect();
|
|
34
25
|
}
|
|
35
|
-
const subscription =
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
destructor.current = effect();
|
|
39
|
-
}
|
|
40
|
-
else if (data[KEY_ON] === ON_COMPONENT_DISAPPEAR) {
|
|
41
|
-
if (destructor.current) {
|
|
42
|
-
destructor.current();
|
|
43
|
-
destructor.current = undefined;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
26
|
+
const subscription = Navigation.addVisibilityEventListener(navigator.sceneId, visibility => {
|
|
27
|
+
if (visibility === 'visible') {
|
|
28
|
+
destructor.current = effect();
|
|
46
29
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (destructor.current) {
|
|
50
|
-
destructor.current();
|
|
30
|
+
else {
|
|
31
|
+
destructor.current && destructor.current();
|
|
51
32
|
destructor.current = undefined;
|
|
52
33
|
}
|
|
34
|
+
});
|
|
35
|
+
return () => {
|
|
36
|
+
destructor.current && destructor.current();
|
|
37
|
+
destructor.current = undefined;
|
|
53
38
|
subscription.remove();
|
|
54
39
|
};
|
|
55
40
|
}, [effect, navigator]);
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
import { withNavigationItem, NavigationProps, InjectedProps } from './NavigationComponentWrap';
|
|
2
|
+
import Navigation from './Navigation';
|
|
3
|
+
declare function statusBarHeight(): number;
|
|
4
|
+
declare function toolbarHeight(): number;
|
|
5
|
+
declare function topBarHeight(): number;
|
|
6
|
+
export default Navigation;
|
|
7
|
+
export { RESULT_OK, RESULT_CANCEL } from './Navigation';
|
|
8
|
+
export { withNavigationItem, NavigationProps, InjectedProps, statusBarHeight, toolbarHeight, topBarHeight, };
|
|
1
9
|
export * from './Navigator';
|
|
2
10
|
export * from './Garden';
|
|
3
11
|
export * from './ReactRegistry';
|
|
4
12
|
export * from './hooks';
|
|
5
13
|
export * from './router';
|
|
6
14
|
export * from './DeepLink';
|
|
7
|
-
export * from './
|
|
8
|
-
export
|
|
15
|
+
export * from './Route';
|
|
16
|
+
export * from './Options';
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
import { withNavigation, withNavigationItem, } from './NavigationComponentWrap';
|
|
2
|
+
import Navigation from './Navigation';
|
|
3
|
+
Navigation.setNavigationComponentWrap(withNavigation);
|
|
4
|
+
function statusBarHeight() {
|
|
5
|
+
return Navigation.statusBarHeight();
|
|
6
|
+
}
|
|
7
|
+
function toolbarHeight() {
|
|
8
|
+
return Navigation.toolbarHeight();
|
|
9
|
+
}
|
|
10
|
+
function topBarHeight() {
|
|
11
|
+
return Navigation.topBarHeight();
|
|
12
|
+
}
|
|
13
|
+
export default Navigation;
|
|
14
|
+
export { RESULT_OK, RESULT_CANCEL } from './Navigation';
|
|
15
|
+
export { withNavigationItem, statusBarHeight, toolbarHeight, topBarHeight, };
|
|
1
16
|
export * from './Navigator';
|
|
2
17
|
export * from './Garden';
|
|
3
18
|
export * from './ReactRegistry';
|
|
4
19
|
export * from './hooks';
|
|
5
20
|
export * from './router';
|
|
6
21
|
export * from './DeepLink';
|
|
7
|
-
export * from './
|
|
8
|
-
export
|
|
22
|
+
export * from './Route';
|
|
23
|
+
export * from './Options';
|
package/lib/router/drawer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RouteGraph, LayoutMode, RouteInfo, RouteHandler } from './typing';
|
|
2
1
|
import { ScreenGraph } from './screen';
|
|
2
|
+
import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route';
|
|
3
3
|
export interface DrawerGraph extends RouteGraph {
|
|
4
4
|
layout: 'drawer';
|
|
5
5
|
sceneId: string;
|
package/lib/router/index.d.ts
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import { RouteConfig, RouteInfo, RouteInterceptor
|
|
2
|
-
import {
|
|
1
|
+
import { RouteConfig, RouteHandler, RouteInfo, RouteInterceptor } from '../Route';
|
|
2
|
+
import { NavigationItem } from '../Options';
|
|
3
3
|
declare function addInterceptor(func: RouteInterceptor): void;
|
|
4
4
|
declare function removeInterceptor(func: RouteInterceptor): void;
|
|
5
|
-
declare function addRouteHandler(handler: RouteHandler): void;
|
|
6
5
|
declare function use(handler: RouteHandler): void;
|
|
7
6
|
declare function registerRoute(moduleName: string, route: RouteConfig): void;
|
|
8
|
-
declare function open(path: string, props?:
|
|
9
|
-
declare function pathToRoute(path: string, props:
|
|
7
|
+
declare function open(path: string, props?: object, options?: NavigationItem): Promise<void>;
|
|
8
|
+
declare function pathToRoute(path: string, props: object, options: NavigationItem): RouteInfo | undefined;
|
|
10
9
|
export declare const router: {
|
|
11
10
|
addInterceptor: typeof addInterceptor;
|
|
12
11
|
removeInterceptor: typeof removeInterceptor;
|
|
13
|
-
addRouteHandler: typeof addRouteHandler;
|
|
14
12
|
registerRoute: typeof registerRoute;
|
|
15
13
|
use: typeof use;
|
|
16
14
|
open: typeof open;
|
|
17
15
|
pathToRoute: typeof pathToRoute;
|
|
18
16
|
};
|
|
19
|
-
export * from './typing';
|
|
20
17
|
export * from './drawer';
|
|
21
18
|
export * from './screen';
|
|
22
19
|
export * from './stack';
|
package/lib/router/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Navigator } from '../Navigator';
|
|
2
1
|
import { pathToRegexp, match } from 'path-to-regexp';
|
|
3
2
|
import { stackRouteHandler } from './stack';
|
|
4
3
|
import { tabsRouteHandler } from './tabs';
|
|
5
4
|
import { drawerRouteHandler } from './drawer';
|
|
5
|
+
import { Navigator } from '../Navigator';
|
|
6
|
+
import Navigation from '../Navigation';
|
|
6
7
|
let routeDatas = new Map();
|
|
7
8
|
let interceptors = new Set();
|
|
8
9
|
let handlers = new Set([drawerRouteHandler, tabsRouteHandler, stackRouteHandler]);
|
|
@@ -20,9 +21,6 @@ function addInterceptor(func) {
|
|
|
20
21
|
function removeInterceptor(func) {
|
|
21
22
|
interceptors.delete(func);
|
|
22
23
|
}
|
|
23
|
-
function addRouteHandler(handler) {
|
|
24
|
-
handlers.add(handler);
|
|
25
|
-
}
|
|
26
24
|
function use(handler) {
|
|
27
25
|
handlers.add(handler);
|
|
28
26
|
}
|
|
@@ -38,7 +36,18 @@ function registerRoute(moduleName, route) {
|
|
|
38
36
|
mode = mode || 'push';
|
|
39
37
|
routeDatas.set(moduleName, { moduleName, mode, path, regexp, dependency });
|
|
40
38
|
}
|
|
39
|
+
let isRouteConfigInflated = false;
|
|
40
|
+
function inflateRouteConfigs() {
|
|
41
|
+
const routeConfigs = Navigation.routeConfigs();
|
|
42
|
+
for (const [moduleName, config] of routeConfigs) {
|
|
43
|
+
registerRoute(moduleName, config);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
41
46
|
async function open(path, props = {}, options = {}) {
|
|
47
|
+
if (!isRouteConfigInflated) {
|
|
48
|
+
inflateRouteConfigs();
|
|
49
|
+
isRouteConfigInflated = true;
|
|
50
|
+
}
|
|
42
51
|
let intercepted = false;
|
|
43
52
|
for (let interceptor of interceptors.values()) {
|
|
44
53
|
const result = interceptor(path);
|
|
@@ -135,13 +144,11 @@ function routeDependencies(routeData) {
|
|
|
135
144
|
export const router = {
|
|
136
145
|
addInterceptor,
|
|
137
146
|
removeInterceptor,
|
|
138
|
-
addRouteHandler,
|
|
139
147
|
registerRoute,
|
|
140
148
|
use,
|
|
141
149
|
open,
|
|
142
150
|
pathToRoute,
|
|
143
151
|
};
|
|
144
|
-
export * from './typing';
|
|
145
152
|
export * from './drawer';
|
|
146
153
|
export * from './screen';
|
|
147
154
|
export * from './stack';
|