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.
Files changed (80) hide show
  1. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +3 -20
  2. package/ios/HybridNavigation/HBDUtils.h +3 -6
  3. package/ios/HybridNavigation/HBDUtils.m +10 -0
  4. package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +7 -2
  5. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +1 -1
  6. package/ios/HybridNavigation/View/HBDRootView.m +9 -3
  7. package/ios/HybridNavigation/ViewController/HBDNavigationController.m +0 -30
  8. package/ios/HybridNavigation/ViewController/HBDViewController.m +7 -3
  9. package/ios/HybridNavigation/ViewController/UINavigationController+HBD.m +0 -3
  10. package/lib/Event.d.ts +18 -0
  11. package/lib/Event.js +71 -0
  12. package/lib/Garden.d.ts +46 -68
  13. package/lib/Garden.js +53 -70
  14. package/lib/GardenModule.d.ts +20 -0
  15. package/lib/GardenModule.js +3 -0
  16. package/lib/Navigation.d.ts +74 -0
  17. package/lib/Navigation.js +182 -0
  18. package/lib/NavigationComponentWrap.d.ts +19 -0
  19. package/lib/NavigationComponentWrap.js +46 -0
  20. package/lib/NavigationModule.d.ts +33 -22
  21. package/lib/NavigationModule.js +79 -22
  22. package/lib/Navigator.d.ts +55 -28
  23. package/lib/Navigator.js +122 -263
  24. package/lib/{typing.d.ts → Options.d.ts} +46 -50
  25. package/lib/{typing.js → Options.js} +0 -0
  26. package/lib/ReactRegistry.d.ts +16 -14
  27. package/lib/ReactRegistry.js +18 -93
  28. package/lib/Route.d.ts +74 -0
  29. package/lib/{router/typing.js → Route.js} +0 -0
  30. package/lib/handler/BarButtonEventHandler.d.ts +10 -0
  31. package/lib/handler/BarButtonEventHandler.js +38 -0
  32. package/lib/handler/DispatchCommandHandler.d.ts +24 -0
  33. package/lib/handler/DispatchCommandHandler.js +28 -0
  34. package/lib/handler/LayoutCommandHandler.d.ts +11 -0
  35. package/lib/handler/LayoutCommandHandler.js +39 -0
  36. package/lib/handler/ResultEventHandler.d.ts +15 -0
  37. package/lib/handler/ResultEventHandler.js +47 -0
  38. package/lib/handler/VisibilityEventHandler.d.ts +13 -0
  39. package/lib/handler/VisibilityEventHandler.js +32 -0
  40. package/lib/hooks.d.ts +0 -1
  41. package/lib/hooks.js +14 -29
  42. package/lib/index.d.ts +10 -2
  43. package/lib/index.js +17 -2
  44. package/lib/router/drawer.d.ts +1 -1
  45. package/lib/router/index.d.ts +4 -7
  46. package/lib/router/index.js +13 -6
  47. package/lib/router/screen.d.ts +1 -1
  48. package/lib/router/stack.d.ts +1 -1
  49. package/lib/router/tabs.d.ts +1 -1
  50. package/lib/store.d.ts +0 -9
  51. package/lib/store.js +0 -22
  52. package/package.json +1 -1
  53. package/src/Event.ts +123 -0
  54. package/src/Garden.ts +63 -149
  55. package/src/GardenModule.ts +24 -0
  56. package/src/Navigation.ts +278 -0
  57. package/src/NavigationComponentWrap.tsx +73 -0
  58. package/src/NavigationModule.ts +118 -29
  59. package/src/Navigator.ts +147 -319
  60. package/src/{typing.ts → Options.ts} +51 -57
  61. package/src/ReactRegistry.tsx +25 -127
  62. package/src/Route.ts +88 -0
  63. package/src/handler/BarButtonEventHandler.ts +50 -0
  64. package/src/handler/DispatchCommandHandler.ts +56 -0
  65. package/src/handler/LayoutCommandHandler.ts +49 -0
  66. package/src/handler/ResultEventHandler.ts +67 -0
  67. package/src/handler/VisibilityEventHandler.ts +44 -0
  68. package/src/hooks.ts +13 -38
  69. package/src/index.ts +38 -3
  70. package/src/router/drawer.ts +1 -1
  71. package/src/router/index.ts +36 -12
  72. package/src/router/screen.ts +1 -1
  73. package/src/router/stack.ts +1 -1
  74. package/src/router/tabs.ts +1 -1
  75. package/src/store.ts +0 -28
  76. package/lib/router/typing.d.ts +0 -37
  77. package/lib/utils.d.ts +0 -9
  78. package/lib/utils.js +0 -50
  79. package/src/router/typing.ts +0 -45
  80. package/src/utils.ts +0 -83
@@ -0,0 +1,74 @@
1
+ import type React from 'react';
2
+ import { ComponentProvider } from 'react-native';
3
+ import type { BarButtonItem, DefaultOptions, NavigationOption, TabBarStyle, TabItemInfo, TitleItem } from './Options';
4
+ import type { BuildInLayout, Layout, Route, RouteGraph, RouteConfig } from './Route';
5
+ import { ResultType } from './handler/ResultEventHandler';
6
+ import { GlobalVisibilityEventListener, VisibilityEventListener } from './handler/VisibilityEventHandler';
7
+ export type { ResultType } from './handler/ResultEventHandler';
8
+ import type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
9
+ export type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
10
+ declare type BarButtonClickEventListener = (sceneId: string, value: Function) => void;
11
+ declare type Nullable<T> = {
12
+ [P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P];
13
+ };
14
+ export declare const RESULT_CANCEL: number, RESULT_OK: number;
15
+ export declare type NavigationSubscription = {
16
+ remove: () => void;
17
+ };
18
+ export declare type HOC = (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>;
19
+ export interface Navigation {
20
+ }
21
+ export declare class Navigation implements Navigation {
22
+ private dispatchHandler;
23
+ private resultHandler;
24
+ private buttonHandler;
25
+ private layoutHandler;
26
+ private visibilityHandler;
27
+ constructor();
28
+ private wrap?;
29
+ private hoc?;
30
+ private registerEnded;
31
+ startRegisterComponent(hoc?: HOC): void;
32
+ endRegisterComponent(): void;
33
+ registerComponent(appKey: string, getComponentFunc: ComponentProvider, routeConfig?: RouteConfig): void;
34
+ setNavigationComponentWrap(wrap: (moduleName: string) => HOC): void;
35
+ addGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener): NavigationSubscription;
36
+ addVisibilityEventListener(sceneId: string, listener: VisibilityEventListener): NavigationSubscription;
37
+ dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<boolean>;
38
+ private handleTabSwitch;
39
+ setInterceptor(interceptor: NavigationInterceptor): void;
40
+ setResult: <T extends ResultType>(sceneId: string, resultCode: number, data?: T) => void;
41
+ result<T>(sceneId: string, resultCode: number): Promise<[number, T]>;
42
+ unmount(sceneId: string): void;
43
+ setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<void>;
44
+ setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
45
+ currentTab(sceneId: string): Promise<number>;
46
+ findSceneIdByModuleName(moduleName: string): Promise<string | null>;
47
+ isStackRoot(sceneId: string): Promise<boolean>;
48
+ signalFirstRenderComplete(sceneId: string): void;
49
+ currentRoute(): Promise<Route>;
50
+ routeGraph(): Promise<RouteGraph[]>;
51
+ private _routeConfigs;
52
+ private registerRoute;
53
+ routeConfigs(): Map<string, RouteConfig>;
54
+ setDefaultOptions(options: DefaultOptions): void;
55
+ setLeftBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void;
56
+ setRightBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void;
57
+ setLeftBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null): void;
58
+ setRightBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null): void;
59
+ setTitleItem(sceneId: string, titleItem: TitleItem): void;
60
+ updateOptions(sceneId: string, options: NavigationOption): void;
61
+ updateTabBar(sceneId: string, options: TabBarStyle): void;
62
+ setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]): void;
63
+ setMenuInteractive(sceneId: string, enabled: boolean): void;
64
+ private _statusBarHeight;
65
+ private _toolbarHeight;
66
+ private handleStatusBarHeightChange;
67
+ statusBarHeight(): number;
68
+ toolbarHeight(): number;
69
+ topBarHeight(): number;
70
+ setBarButtonClickEventListener(listener: BarButtonClickEventListener): void;
71
+ private bindBarButtonClickEvent;
72
+ }
73
+ declare const _default: Navigation;
74
+ export default _default;
@@ -0,0 +1,182 @@
1
+ import { AppRegistry, Platform } from 'react-native';
2
+ import BarButtonEventHandler from './handler/BarButtonEventHandler';
3
+ import LayoutCommandHandler from './handler/LayoutCommandHandler';
4
+ import DispatchCommandHandler from './handler/DispatchCommandHandler';
5
+ import ResultEventHandler from './handler/ResultEventHandler';
6
+ import VisibilityEventHandler from './handler/VisibilityEventHandler';
7
+ import Event from './Event';
8
+ import GardenModule from './GardenModule';
9
+ import NavigationModule from './NavigationModule';
10
+ const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT } = GardenModule.getConstants();
11
+ export const { RESULT_CANCEL, RESULT_OK } = NavigationModule.getConstants();
12
+ export class Navigation {
13
+ dispatchHandler = new DispatchCommandHandler();
14
+ resultHandler = new ResultEventHandler();
15
+ buttonHandler = new BarButtonEventHandler();
16
+ layoutHandler = new LayoutCommandHandler();
17
+ visibilityHandler = new VisibilityEventHandler();
18
+ constructor() {
19
+ this.handleStatusBarHeightChange();
20
+ this.handleTabSwitch();
21
+ this.layoutHandler.handleRootLayoutChange();
22
+ this.visibilityHandler.handleComponentVisibility();
23
+ this.resultHandler.handleComponentResult();
24
+ }
25
+ wrap;
26
+ hoc;
27
+ registerEnded = false;
28
+ startRegisterComponent(hoc) {
29
+ this.hoc = hoc;
30
+ this.registerEnded = false;
31
+ NavigationModule.startRegisterReactComponent();
32
+ }
33
+ endRegisterComponent() {
34
+ if (this.registerEnded) {
35
+ console.warn(`Please don't call ReactRegistry#endRegisterComponent multiple times.`);
36
+ return;
37
+ }
38
+ this.registerEnded = true;
39
+ NavigationModule.endRegisterReactComponent();
40
+ }
41
+ registerComponent(appKey, getComponentFunc, routeConfig) {
42
+ if (routeConfig) {
43
+ this.registerRoute(appKey, routeConfig);
44
+ }
45
+ let WrappedComponent = getComponentFunc();
46
+ if (this.hoc) {
47
+ WrappedComponent = this.hoc(WrappedComponent);
48
+ }
49
+ // build static options
50
+ let options = this.bindBarButtonClickEvent('permanent', WrappedComponent.navigationItem) || {};
51
+ NavigationModule.registerReactComponent(appKey, options);
52
+ let RootComponent = this.wrap(appKey)(WrappedComponent);
53
+ AppRegistry.registerComponent(appKey, () => RootComponent);
54
+ }
55
+ setNavigationComponentWrap(wrap) {
56
+ this.wrap = wrap;
57
+ }
58
+ addGlobalVisibilityEventListener(listener) {
59
+ this.visibilityHandler.addGlobalVisibilityEventListener(listener);
60
+ return {
61
+ remove: () => this.visibilityHandler.removeGlobalVisibilityEventListener(listener),
62
+ };
63
+ }
64
+ addVisibilityEventListener(sceneId, listener) {
65
+ this.visibilityHandler.addVisibilityEventListener(sceneId, listener);
66
+ return {
67
+ remove: () => this.visibilityHandler.removeVisibilityEventListener(sceneId, listener),
68
+ };
69
+ }
70
+ dispatch(sceneId, action, params = {}) {
71
+ return this.dispatchHandler.dispatch(sceneId, action, params);
72
+ }
73
+ handleTabSwitch() {
74
+ Event.listenTabSwitch((sceneId, from, to) => {
75
+ this.dispatch(sceneId, 'switchTab', { from, to });
76
+ });
77
+ }
78
+ setInterceptor(interceptor) {
79
+ this.dispatchHandler.setInterceptor(interceptor);
80
+ }
81
+ setResult = (sceneId, resultCode, data = null) => NavigationModule.setResult(sceneId, resultCode, data);
82
+ result(sceneId, resultCode) {
83
+ return this.resultHandler.waitResult(sceneId, resultCode);
84
+ }
85
+ unmount(sceneId) {
86
+ this.resultHandler.invalidateResultEventListener(sceneId);
87
+ this.buttonHandler.unbindBarButtonClickEvent(sceneId);
88
+ }
89
+ setRoot(layout, sticky = false) {
90
+ return this.layoutHandler.setRoot(layout, sticky);
91
+ }
92
+ setRootLayoutUpdateListener(willSetRoot = () => { }, didSetRoot = () => { }) {
93
+ this.layoutHandler.setRootLayoutUpdateListener(willSetRoot, didSetRoot);
94
+ }
95
+ currentTab(sceneId) {
96
+ return NavigationModule.currentTab(sceneId);
97
+ }
98
+ findSceneIdByModuleName(moduleName) {
99
+ return NavigationModule.findSceneIdByModuleName(moduleName);
100
+ }
101
+ isStackRoot(sceneId) {
102
+ return NavigationModule.isStackRoot(sceneId);
103
+ }
104
+ signalFirstRenderComplete(sceneId) {
105
+ NavigationModule.signalFirstRenderComplete(sceneId);
106
+ }
107
+ currentRoute() {
108
+ return NavigationModule.currentRoute();
109
+ }
110
+ routeGraph() {
111
+ return NavigationModule.routeGraph();
112
+ }
113
+ _routeConfigs = new Map();
114
+ registerRoute(moduleName, route) {
115
+ this._routeConfigs.set(moduleName, route);
116
+ }
117
+ routeConfigs() {
118
+ return this._routeConfigs;
119
+ }
120
+ setDefaultOptions(options) {
121
+ GardenModule.setStyle(options);
122
+ }
123
+ setLeftBarButtonItem(sceneId, buttonItem) {
124
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItem);
125
+ GardenModule.setLeftBarButtonItem(sceneId, options);
126
+ }
127
+ setRightBarButtonItem(sceneId, buttonItem) {
128
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItem);
129
+ GardenModule.setRightBarButtonItem(sceneId, options);
130
+ }
131
+ setLeftBarButtonItems(sceneId, buttonItems) {
132
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
133
+ GardenModule.setLeftBarButtonItems(sceneId, options);
134
+ }
135
+ setRightBarButtonItems(sceneId, buttonItems) {
136
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
137
+ GardenModule.setRightBarButtonItems(sceneId, options);
138
+ }
139
+ setTitleItem(sceneId, titleItem) {
140
+ GardenModule.setTitleItem(sceneId, titleItem);
141
+ }
142
+ updateOptions(sceneId, options) {
143
+ GardenModule.updateOptions(sceneId, options);
144
+ }
145
+ updateTabBar(sceneId, options) {
146
+ GardenModule.updateTabBar(sceneId, options);
147
+ }
148
+ setTabItem(sceneId, item) {
149
+ if (!Array.isArray(item)) {
150
+ item = [item];
151
+ }
152
+ GardenModule.setTabItem(sceneId, item);
153
+ }
154
+ setMenuInteractive(sceneId, enabled) {
155
+ GardenModule.setMenuInteractive(sceneId, enabled);
156
+ }
157
+ _statusBarHeight = STATUSBAR_HEIGHT;
158
+ _toolbarHeight = TOOLBAR_HEIGHT;
159
+ handleStatusBarHeightChange() {
160
+ if (Platform.OS === 'ios') {
161
+ Event.listenStatusBarHeightChange(statusBarHeight => {
162
+ this._statusBarHeight = statusBarHeight;
163
+ });
164
+ }
165
+ }
166
+ statusBarHeight() {
167
+ return this._statusBarHeight;
168
+ }
169
+ toolbarHeight() {
170
+ return this._toolbarHeight;
171
+ }
172
+ topBarHeight() {
173
+ return this.statusBarHeight() + this.toolbarHeight();
174
+ }
175
+ setBarButtonClickEventListener(listener) {
176
+ this.buttonHandler.setBarButtonClickEventListener(listener);
177
+ }
178
+ bindBarButtonClickEvent(sceneId, item) {
179
+ return this.buttonHandler.bindBarButtonClickEvent(sceneId, item);
180
+ }
181
+ }
182
+ export default new Navigation();
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import type { Garden } from './Garden';
3
+ import type { NavigationItem } from './Options';
4
+ import { Navigator } from './Navigator';
5
+ export interface NavigationProps {
6
+ navigator: Navigator;
7
+ garden: Garden;
8
+ sceneId: string;
9
+ }
10
+ /**
11
+ * @deprecated Use NavigationComponentProps instead.
12
+ */
13
+ export declare type InjectedProps = NavigationProps;
14
+ interface NativeProps {
15
+ sceneId: string;
16
+ }
17
+ export declare function withNavigation(moduleName: string): (WrappedComponent: React.ComponentType<any>) => React.ForwardRefExoticComponent<NativeProps & React.RefAttributes<React.ComponentClass<any, any> | React.FunctionComponent<any>>>;
18
+ export declare function withNavigationItem(item: NavigationItem): (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>;
19
+ export {};
@@ -0,0 +1,46 @@
1
+ import React, { useEffect } from 'react';
2
+ import { Navigator, NavigationContext } from './Navigator';
3
+ function getDisplayName(WrappedComponent) {
4
+ return WrappedComponent.displayName || WrappedComponent.name || 'Component';
5
+ }
6
+ export function withNavigation(moduleName) {
7
+ return function (WrappedComponent) {
8
+ const FC = React.forwardRef((props, ref) => {
9
+ const { sceneId } = props;
10
+ const navigator = Navigator.of(sceneId);
11
+ if (navigator.moduleName === undefined) {
12
+ navigator.moduleName = moduleName;
13
+ }
14
+ const garden = navigator.garden;
15
+ useEffect(() => {
16
+ navigator.signalFirstRenderComplete();
17
+ return () => {
18
+ navigator.unmount();
19
+ };
20
+ }, [navigator]);
21
+ const injected = {
22
+ garden,
23
+ navigator,
24
+ };
25
+ return (<NavigationContext.Provider value={navigator}>
26
+ <WrappedComponent ref={ref} {...props} {...injected}/>
27
+ </NavigationContext.Provider>);
28
+ });
29
+ FC.displayName = `withNavigation(${getDisplayName(WrappedComponent)})`;
30
+ return FC;
31
+ };
32
+ }
33
+ export function withNavigationItem(item) {
34
+ return function (WrappedComponent) {
35
+ let navigationItem = WrappedComponent.navigationItem;
36
+ if (navigationItem) {
37
+ ;
38
+ WrappedComponent.navigationItem = { ...navigationItem, ...item };
39
+ }
40
+ else {
41
+ ;
42
+ WrappedComponent.navigationItem = item;
43
+ }
44
+ return WrappedComponent;
45
+ };
46
+ }
@@ -1,22 +1,33 @@
1
- import { NativeEventEmitter } from 'react-native';
2
- declare const NavigationModule: any;
3
- declare const EventEmitter: NativeEventEmitter;
4
- export declare const EVENT_SWITCH_TAB: string;
5
- export declare const EVENT_NAVIGATION: string;
6
- export declare const EVENT_WILL_SET_ROOT: string;
7
- export declare const EVENT_DID_SET_ROOT: string;
8
- export declare const ON_COMPONENT_RESULT: string;
9
- export declare const ON_BAR_BUTTON_ITEM_CLICK: string;
10
- export declare const ON_COMPONENT_APPEAR: string;
11
- export declare const ON_COMPONENT_DISAPPEAR: string;
12
- export declare const KEY_ON: string;
13
- export declare const KEY_REQUEST_CODE: string;
14
- export declare const KEY_RESULT_CODE: string;
15
- export declare const KEY_RESULT_DATA: string;
16
- export declare const KEY_SCENE_ID: string;
17
- export declare const KEY_MODULE_NAME: string;
18
- export declare const KEY_INDEX: string;
19
- export declare const KEY_ACTION: string;
20
- export declare const RESULT_OK: number;
21
- export declare const RESULT_CANCEL: number;
22
- export { EventEmitter, NavigationModule };
1
+ import { Route, RouteGraph } from './Route';
2
+ declare function getConstants(): {
3
+ RESULT_OK: number;
4
+ RESULT_CANCEL: number;
5
+ };
6
+ declare function startRegisterReactComponent(): void;
7
+ declare function endRegisterReactComponent(): void;
8
+ declare function registerReactComponent(appKey: string, options: object): void;
9
+ declare function signalFirstRenderComplete(sceneId: string): void;
10
+ declare function setResult(sceneId: string, resultCode: number, data: object | null): void;
11
+ declare function setRoot(layout: object, sticky: boolean, tag: number): void;
12
+ declare function dispatch(sceneId: string, action: string, params: object): Promise<boolean>;
13
+ declare function currentTab(sceneId: string): Promise<number>;
14
+ declare function isStackRoot(sceneId: string): Promise<boolean>;
15
+ declare function findSceneIdByModuleName(moduleName: string): Promise<string | null>;
16
+ declare function currentRoute(): Promise<Route>;
17
+ declare function routeGraph(): Promise<RouteGraph[]>;
18
+ declare const _default: {
19
+ getConstants: typeof getConstants;
20
+ startRegisterReactComponent: typeof startRegisterReactComponent;
21
+ endRegisterReactComponent: typeof endRegisterReactComponent;
22
+ registerReactComponent: typeof registerReactComponent;
23
+ signalFirstRenderComplete: typeof signalFirstRenderComplete;
24
+ setResult: typeof setResult;
25
+ setRoot: typeof setRoot;
26
+ dispatch: typeof dispatch;
27
+ currentTab: typeof currentTab;
28
+ isStackRoot: typeof isStackRoot;
29
+ findSceneIdByModuleName: typeof findSceneIdByModuleName;
30
+ currentRoute: typeof currentRoute;
31
+ routeGraph: typeof routeGraph;
32
+ };
33
+ export default _default;
@@ -1,23 +1,80 @@
1
- import { NativeModules, NativeEventEmitter } from 'react-native';
1
+ import { NativeModules } from 'react-native';
2
2
  const NavigationModule = NativeModules.NavigationModule;
3
- const HBDEventEmitter = NativeModules.HBDEventEmitter;
4
- const EventEmitter = new NativeEventEmitter(HBDEventEmitter);
5
- export const EVENT_SWITCH_TAB = HBDEventEmitter.EVENT_SWITCH_TAB;
6
- export const EVENT_NAVIGATION = HBDEventEmitter.EVENT_NAVIGATION;
7
- export const EVENT_WILL_SET_ROOT = HBDEventEmitter.EVENT_WILL_SET_ROOT;
8
- export const EVENT_DID_SET_ROOT = HBDEventEmitter.EVENT_DID_SET_ROOT;
9
- export const ON_COMPONENT_RESULT = HBDEventEmitter.ON_COMPONENT_RESULT;
10
- export const ON_BAR_BUTTON_ITEM_CLICK = HBDEventEmitter.ON_BAR_BUTTON_ITEM_CLICK;
11
- export const ON_COMPONENT_APPEAR = HBDEventEmitter.ON_COMPONENT_APPEAR;
12
- export const ON_COMPONENT_DISAPPEAR = HBDEventEmitter.ON_COMPONENT_DISAPPEAR;
13
- export const KEY_ON = HBDEventEmitter.KEY_ON;
14
- export const KEY_REQUEST_CODE = HBDEventEmitter.KEY_REQUEST_CODE;
15
- export const KEY_RESULT_CODE = HBDEventEmitter.KEY_RESULT_CODE;
16
- export const KEY_RESULT_DATA = HBDEventEmitter.KEY_RESULT_DATA;
17
- export const KEY_SCENE_ID = HBDEventEmitter.KEY_SCENE_ID;
18
- export const KEY_MODULE_NAME = HBDEventEmitter.KEY_MODULE_NAME;
19
- export const KEY_INDEX = HBDEventEmitter.KEY_INDEX;
20
- export const KEY_ACTION = HBDEventEmitter.KEY_ACTION;
21
- export const RESULT_OK = NavigationModule.RESULT_OK;
22
- export const RESULT_CANCEL = NavigationModule.RESULT_CANCEL;
23
- export { EventEmitter, NavigationModule };
3
+ function getConstants() {
4
+ return NavigationModule.getConstants();
5
+ }
6
+ function startRegisterReactComponent() {
7
+ NavigationModule.startRegisterReactComponent();
8
+ }
9
+ function endRegisterReactComponent() {
10
+ NavigationModule.endRegisterReactComponent();
11
+ }
12
+ function registerReactComponent(appKey, options) {
13
+ NavigationModule.registerReactComponent(appKey, options);
14
+ }
15
+ function signalFirstRenderComplete(sceneId) {
16
+ NavigationModule.signalFirstRenderComplete(sceneId);
17
+ }
18
+ function setResult(sceneId, resultCode, data) {
19
+ NavigationModule.setResult(sceneId, resultCode, data);
20
+ }
21
+ function setRoot(layout, sticky, tag) {
22
+ NavigationModule.setRoot(layout, sticky, tag);
23
+ }
24
+ function dispatch(sceneId, action, params) {
25
+ return new Promise(resolve => {
26
+ NavigationModule.dispatch(sceneId, action, params, (_, result) => {
27
+ resolve(result);
28
+ });
29
+ });
30
+ }
31
+ function currentTab(sceneId) {
32
+ return new Promise(resolve => {
33
+ NavigationModule.currentTab(sceneId, (_, result) => {
34
+ resolve(result);
35
+ });
36
+ });
37
+ }
38
+ function isStackRoot(sceneId) {
39
+ return new Promise(resolve => {
40
+ NavigationModule.isStackRoot(sceneId, (_, result) => {
41
+ resolve(result);
42
+ });
43
+ });
44
+ }
45
+ function findSceneIdByModuleName(moduleName) {
46
+ return new Promise(resolve => {
47
+ NavigationModule.findSceneIdByModuleName(moduleName, (_, result) => {
48
+ resolve(result);
49
+ });
50
+ });
51
+ }
52
+ function currentRoute() {
53
+ return new Promise(resolve => {
54
+ NavigationModule.currentRoute((_, result) => {
55
+ resolve(result);
56
+ });
57
+ });
58
+ }
59
+ function routeGraph() {
60
+ return new Promise(resolve => {
61
+ NavigationModule.routeGraph((_, result) => {
62
+ resolve(result);
63
+ });
64
+ });
65
+ }
66
+ export default {
67
+ getConstants,
68
+ startRegisterReactComponent,
69
+ endRegisterReactComponent,
70
+ registerReactComponent,
71
+ signalFirstRenderComplete,
72
+ setResult,
73
+ setRoot,
74
+ dispatch,
75
+ currentTab,
76
+ isStackRoot,
77
+ findSceneIdByModuleName,
78
+ currentRoute,
79
+ routeGraph,
80
+ };
@@ -1,58 +1,84 @@
1
- import { RouteGraph, Route } from './router';
2
- import { Visibility } from './hooks';
3
- import { IndexType, ResultType, NavigationInterceptor, Layout, BuildInLayout, NavigationItem, PropsType } from './typing';
1
+ /// <reference types="react" />
2
+ import type { Visibility, Layout, BuildInLayout, Route, RouteGraph } from './Route';
3
+ import type { NavigationItem } from './Options';
4
4
  import { Garden } from './Garden';
5
- interface Params {
6
- animated?: boolean;
7
- moduleName?: string;
8
- layout?: BuildInLayout | Layout;
9
- popToRoot?: boolean;
10
- requestCode?: number;
11
- props?: IndexType;
12
- options?: NavigationItem;
13
- [index: string]: any;
14
- }
5
+ import { NavigationInterceptor, DispatchParams, ResultType } from './Navigation';
6
+ export declare const NavigationContext: import("react").Context<any>;
15
7
  interface NavigationState {
16
8
  params: {
17
9
  readonly [index: string]: any;
18
10
  };
19
11
  }
20
- export declare class Navigator {
12
+ interface PropsType {
13
+ [index: string]: any;
14
+ }
15
+ export interface Navigator {
16
+ }
17
+ export declare class Navigator implements Navigator {
21
18
  sceneId: string;
22
19
  moduleName?: string | undefined;
23
20
  static of(sceneId: string): Navigator;
21
+ /**
22
+ * @deprecated Use Navigation.findSceneIdByModuleName() instead.
23
+ * @param moduleName
24
+ * @returns
25
+ */
24
26
  static find(moduleName: string): Promise<Navigator | undefined>;
25
27
  static current(): Promise<Navigator>;
28
+ /**
29
+ * @deprecated Use Navigation.currentRoute() instead
30
+ * @returns
31
+ */
26
32
  static currentRoute(): Promise<Route>;
33
+ /**
34
+ * @deprecated Use Navigation.routeGraph() instead
35
+ * @returns
36
+ */
27
37
  static routeGraph(): Promise<RouteGraph[]>;
28
- static setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<void>;
38
+ /**
39
+ * @deprecated Use Navigation.setRoot() instead
40
+ * @param layout
41
+ * @param sticky
42
+ */
43
+ static setRoot(layout: BuildInLayout | Layout, sticky?: boolean): void;
44
+ /**
45
+ * @deprecated Use Navigation.setRootLayoutUpdateListener() instead
46
+ * @param willSetRoot
47
+ * @param didSetRoot
48
+ */
29
49
  static setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
30
- static dispatch(sceneId: string, action: string, params?: Params): Promise<boolean>;
31
- static setInterceptor(interceptFn: NavigationInterceptor): void;
50
+ /**
51
+ * @deprecated Use Navigation.dispatch() instead
52
+ * @param sceneId
53
+ * @param action
54
+ * @param params
55
+ * @returns
56
+ */
57
+ static dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<boolean>;
58
+ /**
59
+ * @deprecated Use Navigation.setInterceptor() instead
60
+ * @param interceptor
61
+ */
62
+ static setInterceptor(interceptor: NavigationInterceptor): void;
32
63
  constructor(sceneId: string, moduleName?: string | undefined);
64
+ private _garden?;
65
+ get garden(): Garden;
33
66
  visibility: Visibility;
34
67
  readonly state: NavigationState;
35
68
  setParams: (params: {
36
69
  [index: string]: any;
37
70
  }) => void;
38
- dispatch: (action: string, params?: Params) => Promise<boolean>;
39
- result: (resultCode: number, data: ResultType) => void;
40
71
  unmount: () => void;
41
- private _garden?;
42
- get garden(): Garden;
43
- private resultListener;
44
- private waitResult;
45
- push: <T extends ResultType, P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
72
+ push: <T extends ResultType, P extends PropsType = {}>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
46
73
  pushLayout: <T extends ResultType>(layout: BuildInLayout | Layout) => Promise<[number, T]>;
47
74
  pop: () => Promise<boolean>;
48
75
  popTo: (moduleName: string, inclusive?: boolean) => Promise<boolean>;
49
76
  popToRoot: () => Promise<boolean>;
50
- redirectTo: <P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem) => Promise<boolean>;
51
- isStackRoot: () => Promise<boolean>;
52
- present: <T extends ResultType, P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
77
+ redirectTo: <P extends PropsType>(moduleName: string, props?: P, options?: NavigationItem) => Promise<boolean>;
78
+ present: <T extends ResultType, P extends PropsType = {}>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
53
79
  presentLayout: <T extends ResultType>(layout: BuildInLayout | Layout) => Promise<[number, T]>;
54
80
  dismiss: () => Promise<boolean>;
55
- showModal: <T extends ResultType, P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
81
+ showModal: <T extends ResultType, P extends PropsType = {}>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
56
82
  showModalLayout: <T extends ResultType>(layout: BuildInLayout | Layout) => Promise<[number, T]>;
57
83
  hideModal: () => Promise<boolean>;
58
84
  setResult: <T extends ResultType>(resultCode: number, data?: T) => void;
@@ -60,6 +86,7 @@ export declare class Navigator {
60
86
  toggleMenu: () => Promise<boolean>;
61
87
  openMenu: () => Promise<boolean>;
62
88
  closeMenu: () => Promise<boolean>;
89
+ isStackRoot: () => Promise<boolean>;
63
90
  signalFirstRenderComplete: () => void;
64
91
  }
65
92
  export {};