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.
Files changed (58) hide show
  1. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +3 -20
  2. package/lib/Event.d.ts +12 -16
  3. package/lib/Event.js +20 -66
  4. package/lib/Garden.d.ts +49 -6
  5. package/lib/Garden.js +56 -32
  6. package/lib/Navigation.d.ts +68 -0
  7. package/lib/Navigation.js +162 -0
  8. package/lib/NavigationComponentWrap.d.ts +19 -0
  9. package/lib/NavigationComponentWrap.js +46 -0
  10. package/lib/Navigator.d.ts +46 -32
  11. package/lib/Navigator.js +110 -169
  12. package/lib/ReactRegistry.d.ts +19 -13
  13. package/lib/ReactRegistry.js +21 -73
  14. package/lib/Route.d.ts +13 -8
  15. package/lib/handler/BarButtonEventHandler.d.ts +10 -0
  16. package/lib/handler/BarButtonEventHandler.js +38 -0
  17. package/lib/handler/DispatchCommandHandler.d.ts +26 -0
  18. package/lib/handler/DispatchCommandHandler.js +28 -0
  19. package/lib/handler/LayoutCommandHandler.d.ts +11 -0
  20. package/lib/handler/LayoutCommandHandler.js +39 -0
  21. package/lib/handler/ResultEventHandler.d.ts +15 -0
  22. package/lib/handler/ResultEventHandler.js +47 -0
  23. package/lib/handler/VisibilityEventHandler.d.ts +13 -0
  24. package/lib/handler/VisibilityEventHandler.js +32 -0
  25. package/lib/hooks.d.ts +4 -0
  26. package/lib/hooks.js +13 -18
  27. package/lib/index.d.ts +8 -1
  28. package/lib/index.js +26 -2
  29. package/lib/router/drawer.d.ts +3 -1
  30. package/lib/router/drawer.js +17 -17
  31. package/lib/router/index.d.ts +19 -15
  32. package/lib/router/index.js +140 -116
  33. package/lib/router/screen.d.ts +5 -1
  34. package/lib/router/screen.js +29 -0
  35. package/lib/router/stack.d.ts +5 -1
  36. package/lib/router/stack.js +59 -46
  37. package/lib/router/tabs.d.ts +3 -1
  38. package/lib/router/tabs.js +18 -28
  39. package/package.json +1 -1
  40. package/src/Event.ts +25 -90
  41. package/src/Garden.ts +60 -38
  42. package/src/Navigation.ts +253 -0
  43. package/src/NavigationComponentWrap.tsx +73 -0
  44. package/src/Navigator.ts +124 -233
  45. package/src/ReactRegistry.tsx +23 -99
  46. package/src/Route.ts +14 -9
  47. package/src/handler/BarButtonEventHandler.ts +50 -0
  48. package/src/handler/DispatchCommandHandler.ts +58 -0
  49. package/src/handler/LayoutCommandHandler.ts +49 -0
  50. package/src/handler/ResultEventHandler.ts +67 -0
  51. package/src/handler/VisibilityEventHandler.ts +44 -0
  52. package/src/hooks.ts +18 -30
  53. package/src/index.ts +38 -4
  54. package/src/router/drawer.ts +20 -17
  55. package/src/router/index.ts +150 -119
  56. package/src/router/screen.ts +34 -1
  57. package/src/router/stack.ts +61 -48
  58. package/src/router/tabs.ts +19 -29
@@ -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,70 +1,83 @@
1
1
  /// <reference types="react" />
2
- import { Visibility, Layout, BuildInLayout, Route, RouteGraph } from './Route';
3
- import { NavigationItem } from './Options';
2
+ import type { Visibility, Layout, BuildInLayout, Route, RouteGraph } from './Route';
3
+ import type { NavigationItem } from './Options';
4
4
  import { Garden } from './Garden';
5
+ import { NavigationInterceptor, DispatchParams, ResultType } from './Navigation';
5
6
  export declare const NavigationContext: import("react").Context<any>;
6
7
  interface NavigationState {
7
8
  params: {
8
9
  readonly [index: string]: any;
9
10
  };
10
11
  }
11
- interface IndexType {
12
- [index: string]: any;
13
- }
14
12
  interface PropsType {
15
13
  [index: string]: any;
16
14
  }
17
- interface DispatchParams {
18
- animated?: boolean;
19
- moduleName?: string;
20
- layout?: BuildInLayout | Layout;
21
- popToRoot?: boolean;
22
- requestCode?: number;
23
- props?: object;
24
- options?: NavigationItem;
25
- [index: string]: any;
26
- }
27
- interface InterceptParams {
28
- sceneId: string;
29
- from?: number | string;
30
- to?: number | string;
31
- }
32
- export interface NavigationInterceptor {
33
- (action: string, params: InterceptParams): boolean | Promise<boolean>;
15
+ export interface Navigator {
34
16
  }
35
- declare type ResultType = IndexType | null;
36
- export declare class Navigator {
17
+ export declare class Navigator implements Navigator {
37
18
  sceneId: string;
38
19
  moduleName?: string | undefined;
39
20
  static of(sceneId: string): Navigator;
40
- static find(moduleName: string): Promise<Navigator | undefined>;
41
21
  static current(): Promise<Navigator>;
22
+ /**
23
+ * @deprecated Garden is deprecated, use Navigation.findSceneIdByModuleName() instead.
24
+ * @param moduleName
25
+ * @returns
26
+ */
27
+ static find(moduleName: string): Promise<Navigator | undefined>;
28
+ /**
29
+ * @deprecated Use Navigation.currentRoute() instead
30
+ * @returns
31
+ */
42
32
  static currentRoute(): Promise<Route>;
33
+ /**
34
+ * @deprecated Use Navigation.routeGraph() instead
35
+ * @returns
36
+ */
43
37
  static routeGraph(): Promise<RouteGraph[]>;
44
- 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
+ */
45
49
  static setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
50
+ /**
51
+ * @deprecated Use Navigation.dispatch() instead
52
+ * @param sceneId
53
+ * @param action
54
+ * @param params
55
+ * @returns
56
+ */
46
57
  static dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<boolean>;
47
- static setInterceptor(interceptFn: NavigationInterceptor): void;
58
+ /**
59
+ * @deprecated Use Navigation.setInterceptor() instead
60
+ * @param interceptor
61
+ */
62
+ static setInterceptor(interceptor: NavigationInterceptor): void;
48
63
  constructor(sceneId: string, moduleName?: string | undefined);
49
64
  private _garden?;
65
+ /**
66
+ * @deprecated Garden is deprecated, Use Navigation related methods instead.
67
+ */
50
68
  get garden(): Garden;
51
69
  visibility: Visibility;
52
70
  readonly state: NavigationState;
53
71
  setParams: (params: {
54
72
  [index: string]: any;
55
73
  }) => void;
56
- dispatch: (action: string, params?: DispatchParams) => Promise<boolean>;
57
- result: (resultCode: number, data: ResultType) => void;
58
74
  unmount: () => void;
59
- private resultListener;
60
- private waitResult;
61
75
  push: <T extends ResultType, P extends PropsType = {}>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
62
76
  pushLayout: <T extends ResultType>(layout: BuildInLayout | Layout) => Promise<[number, T]>;
63
77
  pop: () => Promise<boolean>;
64
78
  popTo: (moduleName: string, inclusive?: boolean) => Promise<boolean>;
65
79
  popToRoot: () => Promise<boolean>;
66
80
  redirectTo: <P extends PropsType>(moduleName: string, props?: P, options?: NavigationItem) => Promise<boolean>;
67
- isStackRoot: () => Promise<boolean>;
68
81
  present: <T extends ResultType, P extends PropsType = {}>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
69
82
  presentLayout: <T extends ResultType>(layout: BuildInLayout | Layout) => Promise<[number, T]>;
70
83
  dismiss: () => Promise<boolean>;
@@ -76,6 +89,7 @@ export declare class Navigator {
76
89
  toggleMenu: () => Promise<boolean>;
77
90
  openMenu: () => Promise<boolean>;
78
91
  closeMenu: () => Promise<boolean>;
92
+ isStackRoot: () => Promise<boolean>;
79
93
  signalFirstRenderComplete: () => void;
80
94
  }
81
95
  export {};
package/lib/Navigator.js CHANGED
@@ -1,56 +1,18 @@
1
1
  import { createContext } from 'react';
2
- import NavigationModule from './NavigationModule';
3
- import Event from './Event';
4
2
  import store from './store';
5
3
  import { Garden } from './Garden';
6
- const { RESULT_CANCEL } = NavigationModule.getConstants();
4
+ import Navigation, { RESULT_CANCEL, } from './Navigation';
7
5
  export const NavigationContext = createContext(null);
8
- let interceptor;
9
- let shouldCallWillSetRootCallback = 0;
10
- let willSetRootCallback;
11
- let didSetRootCallback;
12
6
  let tagGenerator = 0;
13
- Event.listenSetRoot(() => {
14
- if (shouldCallWillSetRootCallback === 0 && willSetRootCallback) {
15
- willSetRootCallback();
16
- }
17
- }, () => {
18
- didSetRootCallback && didSetRootCallback();
19
- shouldCallWillSetRootCallback = 0;
20
- });
21
- Event.listenSwitchTab((sceneId, from, to) => {
22
- Navigator.dispatch(sceneId, 'switchTab', { from, to });
23
- });
24
- const globalResultListeners = new Map();
25
- Event.listenComponentResult((sceneId, requestCode, resultCode, data) => {
26
- if (requestCode < 0) {
27
- const listener = globalResultListeners.get(requestCode);
28
- if (listener) {
29
- globalResultListeners.delete(requestCode);
30
- listener(resultCode, data);
31
- }
32
- }
33
- else {
34
- const navigator = Navigator.of(sceneId);
35
- navigator.result(resultCode, data);
36
- }
37
- });
38
- Event.listenComponentVisibility((sceneId) => {
39
- const navigator = store.getNavigator(sceneId);
40
- if (navigator) {
41
- navigator.visibility = 'visible';
42
- }
43
- }, (sceneId) => {
7
+ Navigation.addGlobalVisibilityEventListener((sceneId, visibility) => {
44
8
  const navigator = store.getNavigator(sceneId);
45
9
  if (navigator) {
46
- navigator.visibility = 'invisible';
10
+ navigator.visibility = visibility;
47
11
  }
48
12
  });
49
- Event.setBarButtonClickHandlerFactory(() => {
50
- return (sceneId, value) => {
51
- const navigator = Navigator.of(sceneId);
52
- value(navigator);
53
- };
13
+ Navigation.setBarButtonClickEventListener((sceneId, value) => {
14
+ const navigator = Navigator.of(sceneId);
15
+ value(navigator);
54
16
  });
55
17
  export class Navigator {
56
18
  sceneId;
@@ -63,71 +25,76 @@ export class Navigator {
63
25
  }
64
26
  return navigator;
65
27
  }
28
+ static async current() {
29
+ const route = await Navigation.currentRoute();
30
+ return Navigator.of(route.sceneId);
31
+ }
32
+ /**
33
+ * @deprecated Garden is deprecated, use Navigation.findSceneIdByModuleName() instead.
34
+ * @param moduleName
35
+ * @returns
36
+ */
66
37
  static async find(moduleName) {
67
- const sceneId = await NavigationModule.findSceneIdByModuleName(moduleName);
38
+ const sceneId = await Navigation.findSceneIdByModuleName(moduleName);
68
39
  if (sceneId) {
69
40
  return Navigator.of(sceneId);
70
41
  }
71
42
  }
72
- static async current() {
73
- const route = await Navigator.currentRoute();
74
- return Navigator.of(route.sceneId);
75
- }
43
+ /**
44
+ * @deprecated Use Navigation.currentRoute() instead
45
+ * @returns
46
+ */
76
47
  static currentRoute() {
77
- return NavigationModule.currentRoute();
48
+ return Navigation.currentRoute();
78
49
  }
50
+ /**
51
+ * @deprecated Use Navigation.routeGraph() instead
52
+ * @returns
53
+ */
79
54
  static routeGraph() {
80
- return NavigationModule.routeGraph();
55
+ return Navigation.routeGraph();
81
56
  }
57
+ /**
58
+ * @deprecated Use Navigation.setRoot() instead
59
+ * @param layout
60
+ * @param sticky
61
+ */
82
62
  static setRoot(layout, sticky = false) {
83
- if (willSetRootCallback) {
84
- shouldCallWillSetRootCallback++;
85
- willSetRootCallback();
86
- }
87
- const flag = --tagGenerator;
88
- NavigationModule.setRoot(layout, sticky, flag);
89
- return new Promise(resolve => {
90
- const subscription = Event.listenSetRoot(() => { }, (tag) => {
91
- if (tag === flag) {
92
- subscription.remove();
93
- resolve();
94
- }
95
- });
96
- });
63
+ Navigation.setRoot(layout, sticky);
97
64
  }
65
+ /**
66
+ * @deprecated Use Navigation.setRootLayoutUpdateListener() instead
67
+ * @param willSetRoot
68
+ * @param didSetRoot
69
+ */
98
70
  static setRootLayoutUpdateListener(willSetRoot = () => { }, didSetRoot = () => { }) {
99
- willSetRootCallback = willSetRoot;
100
- didSetRootCallback = didSetRoot;
101
- }
71
+ Navigation.setRootLayoutUpdateListener(willSetRoot, didSetRoot);
72
+ }
73
+ /**
74
+ * @deprecated Use Navigation.dispatch() instead
75
+ * @param sceneId
76
+ * @param action
77
+ * @param params
78
+ * @returns
79
+ */
102
80
  static async dispatch(sceneId, action, params = {}) {
103
- let intercepted = false;
104
- const { from, to } = params;
105
- if (interceptor) {
106
- const result = interceptor(action, {
107
- sceneId,
108
- from,
109
- to,
110
- });
111
- if (result instanceof Promise) {
112
- intercepted = await result;
113
- }
114
- else {
115
- intercepted = result;
116
- }
117
- }
118
- if (!intercepted) {
119
- return NavigationModule.dispatch(sceneId, action, params);
120
- }
121
- return false;
81
+ return Navigation.dispatch(sceneId, action, params);
122
82
  }
123
- static setInterceptor(interceptFn) {
124
- interceptor = interceptFn;
83
+ /**
84
+ * @deprecated Use Navigation.setInterceptor() instead
85
+ * @param interceptor
86
+ */
87
+ static setInterceptor(interceptor) {
88
+ Navigation.setInterceptor(interceptor);
125
89
  }
126
90
  constructor(sceneId, moduleName) {
127
91
  this.sceneId = sceneId;
128
92
  this.moduleName = moduleName;
129
93
  }
130
94
  _garden;
95
+ /**
96
+ * @deprecated Garden is deprecated, Use Navigation related methods instead.
97
+ */
131
98
  get garden() {
132
99
  if (!this._garden) {
133
100
  this._garden = new Garden(this.sceneId);
@@ -141,131 +108,105 @@ export class Navigator {
141
108
  setParams = (params) => {
142
109
  this.state.params = { ...this.state.params, ...params };
143
110
  };
144
- dispatch = (action, params = {}) => {
145
- return Navigator.dispatch(this.sceneId, action, {
146
- from: this.moduleName,
147
- to: params.moduleName,
148
- ...params,
149
- });
150
- };
151
- result = (resultCode, data) => {
152
- if (this.resultListener) {
153
- this.resultListener(resultCode, data);
154
- this.resultListener = null;
155
- }
156
- };
157
111
  unmount = () => {
158
- Event.removeBarButtonClickEvent(this.sceneId);
159
112
  store.removeNavigator(this.sceneId);
160
- const codes = [];
161
- for (const [requestCode, listener] of globalResultListeners) {
162
- if (listener.sceneId === this.sceneId) {
163
- codes.push(requestCode);
164
- listener.cancel();
165
- }
166
- }
167
- codes.forEach(code => globalResultListeners.delete(code));
168
- if (this.resultListener) {
169
- this.resultListener.cancel();
170
- this.resultListener = null;
171
- }
113
+ Navigation.unmount(this.sceneId);
172
114
  };
173
- resultListener = null;
174
- waitResult(requestCode) {
175
- if (this.resultListener) {
176
- this.resultListener.cancel();
177
- this.resultListener = null;
178
- }
179
- return new Promise(resolve => {
180
- const listener = (resultCode, data) => {
181
- resolve([resultCode, data]);
182
- };
183
- listener.cancel = () => {
184
- resolve([RESULT_CANCEL, null]);
185
- };
186
- listener.sceneId = this.sceneId;
187
- if (requestCode < 0) {
188
- globalResultListeners.set(requestCode, listener);
189
- }
190
- else {
191
- this.resultListener = listener;
192
- }
193
- });
194
- }
195
115
  push = async (moduleName, props = {}, options = {}) => {
196
- const success = await this.dispatch('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
+ });
197
123
  if (!success) {
198
- return [RESULT_CANCEL];
124
+ return [RESULT_CANCEL, null];
199
125
  }
200
- return await this.waitResult(0);
126
+ return await Navigation.result(this.sceneId, 0);
201
127
  };
202
128
  pushLayout = async (layout) => {
203
- const success = await this.dispatch('pushLayout', { layout });
129
+ const success = await Navigation.dispatch(this.sceneId, 'pushLayout', {
130
+ from: this.moduleName,
131
+ layout,
132
+ });
204
133
  if (!success) {
205
- return [RESULT_CANCEL];
134
+ return [RESULT_CANCEL, null];
206
135
  }
207
- return await this.waitResult(0);
136
+ return await Navigation.result(this.sceneId, 0);
208
137
  };
209
- pop = () => this.dispatch('pop');
210
- popTo = (moduleName, inclusive = false) => this.dispatch('popTo', { moduleName, inclusive });
211
- popToRoot = () => this.dispatch('popToRoot');
212
- redirectTo = (moduleName, props = {}, options = {}) => this.dispatch('redirectTo', {
138
+ pop = () => Navigation.dispatch(this.sceneId, 'pop');
139
+ popTo = (moduleName, inclusive = false) => Navigation.dispatch(this.sceneId, 'popTo', { moduleName, inclusive });
140
+ popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot');
141
+ redirectTo = (moduleName, props = {}, options = {}) => Navigation.dispatch(this.sceneId, 'redirectTo', {
213
142
  moduleName,
214
143
  props,
215
144
  options,
216
145
  });
217
- isStackRoot = () => NavigationModule.isStackRoot(this.sceneId);
218
146
  present = async (moduleName, props = {}, options = {}) => {
219
147
  const requestCode = --tagGenerator;
220
- const success = await this.dispatch('present', {
148
+ const success = await Navigation.dispatch(this.sceneId, 'present', {
221
149
  moduleName,
150
+ from: this.moduleName,
151
+ to: moduleName,
222
152
  props,
223
153
  options,
224
154
  requestCode,
225
155
  });
226
156
  if (!success) {
227
- return [RESULT_CANCEL];
157
+ return [RESULT_CANCEL, null];
228
158
  }
229
- return await this.waitResult(requestCode);
159
+ return await Navigation.result(this.sceneId, requestCode);
230
160
  };
231
161
  presentLayout = async (layout) => {
232
162
  const requestCode = --tagGenerator;
233
- const success = await this.dispatch('presentLayout', { layout, requestCode });
163
+ const success = await Navigation.dispatch(this.sceneId, 'presentLayout', {
164
+ layout,
165
+ from: this.moduleName,
166
+ requestCode,
167
+ });
234
168
  if (!success) {
235
- return [RESULT_CANCEL];
169
+ return [RESULT_CANCEL, null];
236
170
  }
237
- return await this.waitResult(requestCode);
171
+ return await Navigation.result(this.sceneId, requestCode);
238
172
  };
239
- dismiss = () => this.dispatch('dismiss');
173
+ dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss');
240
174
  showModal = async (moduleName, props = {}, options = {}) => {
241
175
  const requestCode = --tagGenerator;
242
- const success = await this.dispatch('showModal', {
176
+ const success = await Navigation.dispatch(this.sceneId, 'showModal', {
243
177
  moduleName,
178
+ from: this.moduleName,
179
+ to: moduleName,
244
180
  props,
245
181
  options,
246
182
  requestCode,
247
183
  });
248
184
  if (!success) {
249
- return [RESULT_CANCEL];
185
+ return [RESULT_CANCEL, null];
250
186
  }
251
- return await this.waitResult(requestCode);
187
+ return await Navigation.result(this.sceneId, requestCode);
252
188
  };
253
189
  showModalLayout = async (layout) => {
254
190
  const requestCode = --tagGenerator;
255
- const success = await this.dispatch('showModalLayout', { layout, requestCode });
191
+ const success = await Navigation.dispatch(this.sceneId, 'showModalLayout', {
192
+ from: this.moduleName,
193
+ layout,
194
+ requestCode,
195
+ });
256
196
  if (!success) {
257
- return [RESULT_CANCEL];
197
+ return [RESULT_CANCEL, null];
258
198
  }
259
- return await this.waitResult(requestCode);
199
+ return await Navigation.result(this.sceneId, requestCode);
260
200
  };
261
- hideModal = () => this.dispatch('hideModal');
262
- setResult = (resultCode, data = null) => NavigationModule.setResult(this.sceneId, resultCode, data);
201
+ hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal');
202
+ setResult = (resultCode, data = null) => Navigation.setResult(this.sceneId, resultCode, data);
263
203
  switchTab = async (index, popToRoot = false) => {
264
- const from = await NavigationModule.currentTab(this.sceneId);
265
- return this.dispatch('switchTab', { from, to: index, popToRoot });
204
+ const from = await Navigation.currentTab(this.sceneId);
205
+ return Navigation.dispatch(this.sceneId, 'switchTab', { from, to: index, popToRoot });
266
206
  };
267
- toggleMenu = () => this.dispatch('toggleMenu');
268
- openMenu = () => this.dispatch('openMenu');
269
- closeMenu = () => this.dispatch('closeMenu');
270
- signalFirstRenderComplete = () => NavigationModule.signalFirstRenderComplete(this.sceneId);
207
+ toggleMenu = () => Navigation.dispatch(this.sceneId, 'toggleMenu');
208
+ openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu');
209
+ closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu');
210
+ isStackRoot = () => Navigation.isStackRoot(this.sceneId);
211
+ signalFirstRenderComplete = () => Navigation.signalFirstRenderComplete(this.sceneId);
271
212
  }
@@ -1,19 +1,25 @@
1
1
  import { ComponentProvider } from 'react-native';
2
- import React from 'react';
3
- import { Navigator } from './Navigator';
4
- import { Garden } from './Garden';
5
- import { NavigationItem } from './Options';
6
- import { RouteConfig } from './Route';
7
- export interface InjectedProps {
8
- navigator: Navigator;
9
- garden: Garden;
10
- sceneId: string;
11
- }
12
- export declare type HOC = (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>;
2
+ import type { RouteConfig } from './Route';
3
+ import { HOC } from './Navigation';
4
+ /**
5
+ * @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
6
+ */
13
7
  export declare class ReactRegistry {
14
- static registerEnded: boolean;
8
+ /**
9
+ * @deprecated Use Navigation.startRegisterComponent() instead.
10
+ * @param hoc
11
+ */
15
12
  static startRegisterComponent(hoc?: HOC): void;
13
+ /**
14
+ * @deprecated Use Navigation.endRegisterComponent() instead.
15
+ */
16
16
  static endRegisterComponent(): void;
17
+ /**
18
+ *
19
+ * @deprecated Use Navigation.registerComponent() instead.
20
+ * @param appKey
21
+ * @param getComponentFunc
22
+ * @param routeConfig
23
+ */
17
24
  static registerComponent(appKey: string, getComponentFunc: ComponentProvider, routeConfig?: RouteConfig): void;
18
25
  }
19
- export declare function withNavigationItem(item: NavigationItem): (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>;
@@ -1,81 +1,29 @@
1
- import { AppRegistry } from 'react-native';
2
- import React, { useEffect } from 'react';
3
- import { Navigator, NavigationContext } from './Navigator';
4
- import { router } from './router';
5
- import NavigationModule from './NavigationModule';
6
- import Event from './Event';
7
- function getDisplayName(WrappedComponent) {
8
- return WrappedComponent.displayName || WrappedComponent.name || 'Component';
9
- }
10
- function withNavigation(moduleName) {
11
- return function (WrappedComponent) {
12
- const FC = React.forwardRef((props, ref) => {
13
- const { sceneId } = props;
14
- const navigator = Navigator.of(sceneId);
15
- if (navigator.moduleName === undefined) {
16
- navigator.moduleName = moduleName;
17
- }
18
- const garden = navigator.garden;
19
- useEffect(() => {
20
- navigator.signalFirstRenderComplete();
21
- return () => {
22
- navigator.unmount();
23
- };
24
- }, [navigator]);
25
- const injected = {
26
- garden,
27
- navigator,
28
- };
29
- return (<NavigationContext.Provider value={navigator}>
30
- <WrappedComponent ref={ref} {...props} {...injected}/>
31
- </NavigationContext.Provider>);
32
- });
33
- FC.displayName = `withNavigation(${getDisplayName(WrappedComponent)})`;
34
- return FC;
35
- };
36
- }
37
- let wrap;
1
+ import Navigation from './Navigation';
2
+ /**
3
+ * @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
4
+ */
38
5
  export class ReactRegistry {
39
- static registerEnded;
6
+ /**
7
+ * @deprecated Use Navigation.startRegisterComponent() instead.
8
+ * @param hoc
9
+ */
40
10
  static startRegisterComponent(hoc) {
41
- wrap = hoc;
42
- ReactRegistry.registerEnded = false;
43
- NavigationModule.startRegisterReactComponent();
11
+ Navigation.startRegisterComponent(hoc);
44
12
  }
13
+ /**
14
+ * @deprecated Use Navigation.endRegisterComponent() instead.
15
+ */
45
16
  static endRegisterComponent() {
46
- if (ReactRegistry.registerEnded) {
47
- console.warn(`Please don't call ReactRegistry#endRegisterComponent multiple times.`);
48
- return;
49
- }
50
- ReactRegistry.registerEnded = true;
51
- NavigationModule.endRegisterReactComponent();
17
+ Navigation.endRegisterComponent();
52
18
  }
19
+ /**
20
+ *
21
+ * @deprecated Use Navigation.registerComponent() instead.
22
+ * @param appKey
23
+ * @param getComponentFunc
24
+ * @param routeConfig
25
+ */
53
26
  static registerComponent(appKey, getComponentFunc, routeConfig) {
54
- if (routeConfig) {
55
- router.registerRoute(appKey, routeConfig);
56
- }
57
- let WrappedComponent = getComponentFunc();
58
- if (wrap) {
59
- WrappedComponent = wrap(WrappedComponent);
60
- }
61
- // build static options
62
- let options = Event.bindBarButtonClickEvent('permanent', WrappedComponent.navigationItem) || {};
63
- NavigationModule.registerReactComponent(appKey, options);
64
- let RootComponent = withNavigation(appKey)(WrappedComponent);
65
- AppRegistry.registerComponent(appKey, () => RootComponent);
27
+ Navigation.registerComponent(appKey, getComponentFunc, routeConfig);
66
28
  }
67
29
  }
68
- export function withNavigationItem(item) {
69
- return function (WrappedComponent) {
70
- let navigationItem = WrappedComponent.navigationItem;
71
- if (navigationItem) {
72
- ;
73
- WrappedComponent.navigationItem = { ...navigationItem, ...item };
74
- }
75
- else {
76
- ;
77
- WrappedComponent.navigationItem = item;
78
- }
79
- return WrappedComponent;
80
- };
81
- }