hybrid-navigation 2.13.0 → 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/lib/Garden.d.ts CHANGED
@@ -4,6 +4,9 @@ declare type Nullable<T> = {
4
4
  };
5
5
  export interface Garden {
6
6
  }
7
+ /**
8
+ * @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
9
+ */
7
10
  export declare class Garden implements Garden {
8
11
  sceneId: string;
9
12
  /**
package/lib/Garden.js CHANGED
@@ -1,4 +1,7 @@
1
1
  import Navigation from './Navigation';
2
+ /**
3
+ * @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
4
+ */
2
5
  export class Garden {
3
6
  sceneId;
4
7
  /**
@@ -31,6 +31,9 @@ export declare class Navigation implements Navigation {
31
31
  startRegisterComponent(hoc?: HOC): void;
32
32
  endRegisterComponent(): void;
33
33
  registerComponent(appKey: string, getComponentFunc: ComponentProvider, routeConfig?: RouteConfig): void;
34
+ private _routeConfigs;
35
+ private registerRoute;
36
+ routeConfigs(): Map<string, RouteConfig>;
34
37
  setNavigationComponentWrap(wrap: (moduleName: string) => HOC): void;
35
38
  addGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener): NavigationSubscription;
36
39
  addVisibilityEventListener(sceneId: string, listener: VisibilityEventListener): NavigationSubscription;
@@ -48,9 +51,6 @@ export declare class Navigation implements Navigation {
48
51
  signalFirstRenderComplete(sceneId: string): void;
49
52
  currentRoute(): Promise<Route>;
50
53
  routeGraph(): Promise<RouteGraph[]>;
51
- private _routeConfigs;
52
- private registerRoute;
53
- routeConfigs(): Map<string, RouteConfig>;
54
54
  setDefaultOptions(options: DefaultOptions): void;
55
55
  setLeftBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void;
56
56
  setRightBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void;
@@ -61,12 +61,6 @@ export declare class Navigation implements Navigation {
61
61
  updateTabBar(sceneId: string, options: TabBarStyle): void;
62
62
  setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]): void;
63
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
64
  setBarButtonClickEventListener(listener: BarButtonClickEventListener): void;
71
65
  private bindBarButtonClickEvent;
72
66
  }
package/lib/Navigation.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AppRegistry, Platform } from 'react-native';
1
+ import { AppRegistry } from 'react-native';
2
2
  import BarButtonEventHandler from './handler/BarButtonEventHandler';
3
3
  import LayoutCommandHandler from './handler/LayoutCommandHandler';
4
4
  import DispatchCommandHandler from './handler/DispatchCommandHandler';
@@ -7,7 +7,6 @@ import VisibilityEventHandler from './handler/VisibilityEventHandler';
7
7
  import Event from './Event';
8
8
  import GardenModule from './GardenModule';
9
9
  import NavigationModule from './NavigationModule';
10
- const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT } = GardenModule.getConstants();
11
10
  export const { RESULT_CANCEL, RESULT_OK } = NavigationModule.getConstants();
12
11
  export class Navigation {
13
12
  dispatchHandler = new DispatchCommandHandler();
@@ -16,7 +15,6 @@ export class Navigation {
16
15
  layoutHandler = new LayoutCommandHandler();
17
16
  visibilityHandler = new VisibilityEventHandler();
18
17
  constructor() {
19
- this.handleStatusBarHeightChange();
20
18
  this.handleTabSwitch();
21
19
  this.layoutHandler.handleRootLayoutChange();
22
20
  this.visibilityHandler.handleComponentVisibility();
@@ -52,6 +50,13 @@ export class Navigation {
52
50
  let RootComponent = this.wrap(appKey)(WrappedComponent);
53
51
  AppRegistry.registerComponent(appKey, () => RootComponent);
54
52
  }
53
+ _routeConfigs = new Map();
54
+ registerRoute(moduleName, route) {
55
+ this._routeConfigs.set(moduleName, route);
56
+ }
57
+ routeConfigs() {
58
+ return this._routeConfigs;
59
+ }
55
60
  setNavigationComponentWrap(wrap) {
56
61
  this.wrap = wrap;
57
62
  }
@@ -110,13 +115,6 @@ export class Navigation {
110
115
  routeGraph() {
111
116
  return NavigationModule.routeGraph();
112
117
  }
113
- _routeConfigs = new Map();
114
- registerRoute(moduleName, route) {
115
- this._routeConfigs.set(moduleName, route);
116
- }
117
- routeConfigs() {
118
- return this._routeConfigs;
119
- }
120
118
  setDefaultOptions(options) {
121
119
  GardenModule.setStyle(options);
122
120
  }
@@ -154,24 +152,6 @@ export class Navigation {
154
152
  setMenuInteractive(sceneId, enabled) {
155
153
  GardenModule.setMenuInteractive(sceneId, enabled);
156
154
  }
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
155
  setBarButtonClickEventListener(listener) {
176
156
  this.buttonHandler.setBarButtonClickEventListener(listener);
177
157
  }
@@ -8,7 +8,7 @@ export interface NavigationProps {
8
8
  sceneId: string;
9
9
  }
10
10
  /**
11
- * @deprecated Use NavigationComponentProps instead.
11
+ * @deprecated Use NavigationProps instead.
12
12
  */
13
13
  export declare type InjectedProps = NavigationProps;
14
14
  interface NativeProps {
@@ -18,13 +18,13 @@ export declare class Navigator implements Navigator {
18
18
  sceneId: string;
19
19
  moduleName?: string | undefined;
20
20
  static of(sceneId: string): Navigator;
21
+ static current(): Promise<Navigator>;
21
22
  /**
22
- * @deprecated Use Navigation.findSceneIdByModuleName() instead.
23
+ * @deprecated Garden is deprecated, use Navigation.findSceneIdByModuleName() instead.
23
24
  * @param moduleName
24
25
  * @returns
25
26
  */
26
27
  static find(moduleName: string): Promise<Navigator | undefined>;
27
- static current(): Promise<Navigator>;
28
28
  /**
29
29
  * @deprecated Use Navigation.currentRoute() instead
30
30
  * @returns
@@ -62,6 +62,9 @@ export declare class Navigator implements Navigator {
62
62
  static setInterceptor(interceptor: NavigationInterceptor): void;
63
63
  constructor(sceneId: string, moduleName?: string | undefined);
64
64
  private _garden?;
65
+ /**
66
+ * @deprecated Garden is deprecated, Use Navigation related methods instead.
67
+ */
65
68
  get garden(): Garden;
66
69
  visibility: Visibility;
67
70
  readonly state: NavigationState;
package/lib/Navigator.js CHANGED
@@ -25,8 +25,12 @@ export class Navigator {
25
25
  }
26
26
  return navigator;
27
27
  }
28
+ static async current() {
29
+ const route = await Navigation.currentRoute();
30
+ return Navigator.of(route.sceneId);
31
+ }
28
32
  /**
29
- * @deprecated Use Navigation.findSceneIdByModuleName() instead.
33
+ * @deprecated Garden is deprecated, use Navigation.findSceneIdByModuleName() instead.
30
34
  * @param moduleName
31
35
  * @returns
32
36
  */
@@ -36,10 +40,6 @@ export class Navigator {
36
40
  return Navigator.of(sceneId);
37
41
  }
38
42
  }
39
- static async current() {
40
- const route = await Navigator.currentRoute();
41
- return Navigator.of(route.sceneId);
42
- }
43
43
  /**
44
44
  * @deprecated Use Navigation.currentRoute() instead
45
45
  * @returns
@@ -92,6 +92,9 @@ export class Navigator {
92
92
  this.moduleName = moduleName;
93
93
  }
94
94
  _garden;
95
+ /**
96
+ * @deprecated Garden is deprecated, Use Navigation related methods instead.
97
+ */
95
98
  get garden() {
96
99
  if (!this._garden) {
97
100
  this._garden = new Garden(this.sceneId);
@@ -110,14 +113,23 @@ export class Navigator {
110
113
  Navigation.unmount(this.sceneId);
111
114
  };
112
115
  push = async (moduleName, props = {}, options = {}) => {
113
- const success = await Navigation.dispatch(this.sceneId, 'push', { moduleName, props, options });
116
+ const success = await Navigation.dispatch(this.sceneId, 'push', {
117
+ moduleName,
118
+ from: this.moduleName,
119
+ to: moduleName,
120
+ props,
121
+ options,
122
+ });
114
123
  if (!success) {
115
124
  return [RESULT_CANCEL, null];
116
125
  }
117
126
  return await Navigation.result(this.sceneId, 0);
118
127
  };
119
128
  pushLayout = async (layout) => {
120
- const success = await Navigation.dispatch(this.sceneId, 'pushLayout', { layout });
129
+ const success = await Navigation.dispatch(this.sceneId, 'pushLayout', {
130
+ from: this.moduleName,
131
+ layout,
132
+ });
121
133
  if (!success) {
122
134
  return [RESULT_CANCEL, null];
123
135
  }
@@ -135,6 +147,8 @@ export class Navigator {
135
147
  const requestCode = --tagGenerator;
136
148
  const success = await Navigation.dispatch(this.sceneId, 'present', {
137
149
  moduleName,
150
+ from: this.moduleName,
151
+ to: moduleName,
138
152
  props,
139
153
  options,
140
154
  requestCode,
@@ -148,6 +162,7 @@ export class Navigator {
148
162
  const requestCode = --tagGenerator;
149
163
  const success = await Navigation.dispatch(this.sceneId, 'presentLayout', {
150
164
  layout,
165
+ from: this.moduleName,
151
166
  requestCode,
152
167
  });
153
168
  if (!success) {
@@ -160,6 +175,8 @@ export class Navigator {
160
175
  const requestCode = --tagGenerator;
161
176
  const success = await Navigation.dispatch(this.sceneId, 'showModal', {
162
177
  moduleName,
178
+ from: this.moduleName,
179
+ to: moduleName,
163
180
  props,
164
181
  options,
165
182
  requestCode,
@@ -172,6 +189,7 @@ export class Navigator {
172
189
  showModalLayout = async (layout) => {
173
190
  const requestCode = --tagGenerator;
174
191
  const success = await Navigation.dispatch(this.sceneId, 'showModalLayout', {
192
+ from: this.moduleName,
175
193
  layout,
176
194
  requestCode,
177
195
  });
@@ -1,6 +1,9 @@
1
1
  import { ComponentProvider } from 'react-native';
2
2
  import type { RouteConfig } from './Route';
3
3
  import { HOC } from './Navigation';
4
+ /**
5
+ * @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
6
+ */
4
7
  export declare class ReactRegistry {
5
8
  /**
6
9
  * @deprecated Use Navigation.startRegisterComponent() instead.
@@ -1,4 +1,7 @@
1
1
  import Navigation from './Navigation';
2
+ /**
3
+ * @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
4
+ */
2
5
  export class ReactRegistry {
3
6
  /**
4
7
  * @deprecated Use Navigation.startRegisterComponent() instead.
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
- (graph: RouteGraph, route: RouteInfo, next: RouteHandler): Promise<boolean>;
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>;
@@ -3,6 +3,8 @@ import { BuildInLayout, Layout } from '../Route';
3
3
  export interface DispatchParams {
4
4
  animated?: boolean;
5
5
  moduleName?: string;
6
+ from?: string | number;
7
+ to?: string | number;
6
8
  layout?: BuildInLayout | Layout;
7
9
  popToRoot?: boolean;
8
10
  requestCode?: number;
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
@@ -42,6 +42,10 @@ export function useVisibleEffect(effect) {
42
42
  export function useNavigator() {
43
43
  return useContext(NavigationContext);
44
44
  }
45
+ /**
46
+ * @deprecated Use Navigation related methods instead.
47
+ * @returns
48
+ */
45
49
  export function useGarden() {
46
50
  const ctx = useContext(NavigationContext);
47
51
  return ctx.garden;
package/lib/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { withNavigationItem, NavigationProps, InjectedProps } from './NavigationComponentWrap';
2
1
  import Navigation from './Navigation';
3
2
  declare function statusBarHeight(): number;
4
3
  declare function toolbarHeight(): number;
5
4
  declare function topBarHeight(): number;
6
5
  export default Navigation;
6
+ export { statusBarHeight, toolbarHeight, topBarHeight };
7
7
  export { RESULT_OK, RESULT_CANCEL } from './Navigation';
8
- export { withNavigationItem, NavigationProps, InjectedProps, statusBarHeight, toolbarHeight, topBarHeight, };
8
+ export { withNavigation, withNavigationItem, NavigationProps, InjectedProps, } from './NavigationComponentWrap';
9
9
  export * from './Navigator';
10
10
  export * from './Garden';
11
11
  export * from './ReactRegistry';
package/lib/index.js CHANGED
@@ -1,18 +1,29 @@
1
- import { withNavigation, withNavigationItem, } from './NavigationComponentWrap';
1
+ import { Platform } from 'react-native';
2
2
  import Navigation from './Navigation';
3
+ import Event from './Event';
4
+ import GardenModule from './GardenModule';
5
+ import { withNavigation } from './NavigationComponentWrap';
3
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
+ }
4
14
  function statusBarHeight() {
5
- return Navigation.statusBarHeight();
15
+ return _statusBarHeight;
6
16
  }
7
17
  function toolbarHeight() {
8
- return Navigation.toolbarHeight();
18
+ return TOOLBAR_HEIGHT;
9
19
  }
10
20
  function topBarHeight() {
11
- return Navigation.topBarHeight();
21
+ return statusBarHeight() + toolbarHeight();
12
22
  }
13
23
  export default Navigation;
24
+ export { statusBarHeight, toolbarHeight, topBarHeight };
14
25
  export { RESULT_OK, RESULT_CANCEL } from './Navigation';
15
- export { withNavigationItem, statusBarHeight, toolbarHeight, topBarHeight, };
26
+ export { withNavigation, withNavigationItem, } from './NavigationComponentWrap';
16
27
  export * from './Navigator';
17
28
  export * from './Garden';
18
29
  export * from './ReactRegistry';
@@ -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 function drawerRouteHandler(graph: RouteGraph, route: RouteInfo, next: RouteHandler): Promise<boolean>;
10
+ export declare class DrawerRouteHandler implements RouteHandler {
11
+ process(graph: RouteGraph, target: RouteInfo): Promise<[boolean, RouteGraph | null]>;
12
+ }
@@ -1,23 +1,23 @@
1
- import { Navigator } from '../Navigator';
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 async function drawerRouteHandler(graph, route, next) {
6
- if (!isDrawerGraph(graph)) {
7
- return false;
8
- }
9
- const { moduleName, sceneId } = graph.children[1];
10
- if (moduleName === route.moduleName) {
11
- const navigator = Navigator.of(sceneId);
12
- navigator.openMenu();
13
- return true;
14
- }
15
- else {
16
- let result = await next(graph.children[0], route, next);
17
- if (result) {
18
- const navigator = Navigator.of(sceneId);
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 result;
21
+ return [false, graph];
22
22
  }
23
23
  }
@@ -1,19 +1,23 @@
1
- import { RouteConfig, RouteHandler, RouteInfo, RouteInterceptor } from '../Route';
1
+ import { RouteHandler, RouteInterceptor } from '../Route';
2
2
  import { NavigationItem } from '../Options';
3
- declare function addInterceptor(func: RouteInterceptor): void;
4
- declare function removeInterceptor(func: RouteInterceptor): void;
5
- declare function use(handler: RouteHandler): void;
6
- declare function registerRoute(moduleName: string, route: RouteConfig): void;
7
- declare function open(path: string, props?: object, options?: NavigationItem): Promise<void>;
8
- declare function pathToRoute(path: string, props: object, options: NavigationItem): RouteInfo | undefined;
9
- export declare const router: {
10
- addInterceptor: typeof addInterceptor;
11
- removeInterceptor: typeof removeInterceptor;
12
- registerRoute: typeof registerRoute;
13
- use: typeof use;
14
- open: typeof open;
15
- pathToRoute: typeof pathToRoute;
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';