hybrid-navigation 2.13.0-beta.3 → 2.13.0-beta.4

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 (42) 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 +46 -6
  5. package/lib/Garden.js +53 -32
  6. package/lib/Navigation.d.ts +74 -0
  7. package/lib/Navigation.js +182 -0
  8. package/lib/NavigationComponentWrap.d.ts +19 -0
  9. package/lib/NavigationComponentWrap.js +46 -0
  10. package/lib/Navigator.d.ts +42 -31
  11. package/lib/Navigator.js +88 -165
  12. package/lib/ReactRegistry.d.ts +16 -13
  13. package/lib/ReactRegistry.js +18 -73
  14. package/lib/handler/BarButtonEventHandler.d.ts +10 -0
  15. package/lib/handler/BarButtonEventHandler.js +38 -0
  16. package/lib/handler/DispatchCommandHandler.d.ts +24 -0
  17. package/lib/handler/DispatchCommandHandler.js +28 -0
  18. package/lib/handler/LayoutCommandHandler.d.ts +11 -0
  19. package/lib/handler/LayoutCommandHandler.js +39 -0
  20. package/lib/handler/ResultEventHandler.d.ts +15 -0
  21. package/lib/handler/ResultEventHandler.js +47 -0
  22. package/lib/handler/VisibilityEventHandler.d.ts +13 -0
  23. package/lib/handler/VisibilityEventHandler.js +32 -0
  24. package/lib/hooks.js +9 -18
  25. package/lib/index.d.ts +8 -1
  26. package/lib/index.js +15 -2
  27. package/lib/router/index.js +12 -0
  28. package/package.json +1 -1
  29. package/src/Event.ts +25 -90
  30. package/src/Garden.ts +56 -38
  31. package/src/Navigation.ts +278 -0
  32. package/src/NavigationComponentWrap.tsx +73 -0
  33. package/src/Navigator.ts +101 -228
  34. package/src/ReactRegistry.tsx +20 -99
  35. package/src/handler/BarButtonEventHandler.ts +50 -0
  36. package/src/handler/DispatchCommandHandler.ts +56 -0
  37. package/src/handler/LayoutCommandHandler.ts +49 -0
  38. package/src/handler/ResultEventHandler.ts +67 -0
  39. package/src/handler/VisibilityEventHandler.ts +44 -0
  40. package/src/hooks.ts +14 -30
  41. package/src/index.ts +36 -4
  42. package/src/router/index.ts +15 -0
@@ -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,50 +1,65 @@
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;
21
+ /**
22
+ * @deprecated Use Navigation.findSceneIdByModuleName() instead.
23
+ * @param moduleName
24
+ * @returns
25
+ */
40
26
  static find(moduleName: string): Promise<Navigator | undefined>;
41
27
  static current(): Promise<Navigator>;
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?;
50
65
  get garden(): Garden;
@@ -53,18 +68,13 @@ export declare class Navigator {
53
68
  setParams: (params: {
54
69
  [index: string]: any;
55
70
  }) => void;
56
- dispatch: (action: string, params?: DispatchParams) => Promise<boolean>;
57
- result: (resultCode: number, data: ResultType) => void;
58
71
  unmount: () => void;
59
- private resultListener;
60
- private waitResult;
61
72
  push: <T extends ResultType, P extends PropsType = {}>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
62
73
  pushLayout: <T extends ResultType>(layout: BuildInLayout | Layout) => Promise<[number, T]>;
63
74
  pop: () => Promise<boolean>;
64
75
  popTo: (moduleName: string, inclusive?: boolean) => Promise<boolean>;
65
76
  popToRoot: () => Promise<boolean>;
66
77
  redirectTo: <P extends PropsType>(moduleName: string, props?: P, options?: NavigationItem) => Promise<boolean>;
67
- isStackRoot: () => Promise<boolean>;
68
78
  present: <T extends ResultType, P extends PropsType = {}>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
69
79
  presentLayout: <T extends ResultType>(layout: BuildInLayout | Layout) => Promise<[number, T]>;
70
80
  dismiss: () => Promise<boolean>;
@@ -76,6 +86,7 @@ export declare class Navigator {
76
86
  toggleMenu: () => Promise<boolean>;
77
87
  openMenu: () => Promise<boolean>;
78
88
  closeMenu: () => Promise<boolean>;
89
+ isStackRoot: () => Promise<boolean>;
79
90
  signalFirstRenderComplete: () => void;
80
91
  }
81
92
  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) => {
7
+ Navigation.addGlobalVisibilityEventListener((sceneId, visibility) => {
39
8
  const navigator = store.getNavigator(sceneId);
40
9
  if (navigator) {
41
- navigator.visibility = 'visible';
42
- }
43
- }, (sceneId) => {
44
- const navigator = store.getNavigator(sceneId);
45
- 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,8 +25,13 @@ export class Navigator {
63
25
  }
64
26
  return navigator;
65
27
  }
28
+ /**
29
+ * @deprecated Use Navigation.findSceneIdByModuleName() instead.
30
+ * @param moduleName
31
+ * @returns
32
+ */
66
33
  static async find(moduleName) {
67
- const sceneId = await NavigationModule.findSceneIdByModuleName(moduleName);
34
+ const sceneId = await Navigation.findSceneIdByModuleName(moduleName);
68
35
  if (sceneId) {
69
36
  return Navigator.of(sceneId);
70
37
  }
@@ -73,55 +40,52 @@ export class Navigator {
73
40
  const route = await Navigator.currentRoute();
74
41
  return Navigator.of(route.sceneId);
75
42
  }
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;
@@ -141,131 +105,90 @@ export class Navigator {
141
105
  setParams = (params) => {
142
106
  this.state.params = { ...this.state.params, ...params };
143
107
  };
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
108
  unmount = () => {
158
- Event.removeBarButtonClickEvent(this.sceneId);
159
109
  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
- }
110
+ Navigation.unmount(this.sceneId);
172
111
  };
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
112
  push = async (moduleName, props = {}, options = {}) => {
196
- const success = await this.dispatch('push', { moduleName, props, options });
113
+ const success = await Navigation.dispatch(this.sceneId, 'push', { moduleName, props, options });
197
114
  if (!success) {
198
- return [RESULT_CANCEL];
115
+ return [RESULT_CANCEL, null];
199
116
  }
200
- return await this.waitResult(0);
117
+ return await Navigation.result(this.sceneId, 0);
201
118
  };
202
119
  pushLayout = async (layout) => {
203
- const success = await this.dispatch('pushLayout', { layout });
120
+ const success = await Navigation.dispatch(this.sceneId, 'pushLayout', { layout });
204
121
  if (!success) {
205
- return [RESULT_CANCEL];
122
+ return [RESULT_CANCEL, null];
206
123
  }
207
- return await this.waitResult(0);
124
+ return await Navigation.result(this.sceneId, 0);
208
125
  };
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', {
126
+ pop = () => Navigation.dispatch(this.sceneId, 'pop');
127
+ popTo = (moduleName, inclusive = false) => Navigation.dispatch(this.sceneId, 'popTo', { moduleName, inclusive });
128
+ popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot');
129
+ redirectTo = (moduleName, props = {}, options = {}) => Navigation.dispatch(this.sceneId, 'redirectTo', {
213
130
  moduleName,
214
131
  props,
215
132
  options,
216
133
  });
217
- isStackRoot = () => NavigationModule.isStackRoot(this.sceneId);
218
134
  present = async (moduleName, props = {}, options = {}) => {
219
135
  const requestCode = --tagGenerator;
220
- const success = await this.dispatch('present', {
136
+ const success = await Navigation.dispatch(this.sceneId, 'present', {
221
137
  moduleName,
222
138
  props,
223
139
  options,
224
140
  requestCode,
225
141
  });
226
142
  if (!success) {
227
- return [RESULT_CANCEL];
143
+ return [RESULT_CANCEL, null];
228
144
  }
229
- return await this.waitResult(requestCode);
145
+ return await Navigation.result(this.sceneId, requestCode);
230
146
  };
231
147
  presentLayout = async (layout) => {
232
148
  const requestCode = --tagGenerator;
233
- const success = await this.dispatch('presentLayout', { layout, requestCode });
149
+ const success = await Navigation.dispatch(this.sceneId, 'presentLayout', {
150
+ layout,
151
+ requestCode,
152
+ });
234
153
  if (!success) {
235
- return [RESULT_CANCEL];
154
+ return [RESULT_CANCEL, null];
236
155
  }
237
- return await this.waitResult(requestCode);
156
+ return await Navigation.result(this.sceneId, requestCode);
238
157
  };
239
- dismiss = () => this.dispatch('dismiss');
158
+ dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss');
240
159
  showModal = async (moduleName, props = {}, options = {}) => {
241
160
  const requestCode = --tagGenerator;
242
- const success = await this.dispatch('showModal', {
161
+ const success = await Navigation.dispatch(this.sceneId, 'showModal', {
243
162
  moduleName,
244
163
  props,
245
164
  options,
246
165
  requestCode,
247
166
  });
248
167
  if (!success) {
249
- return [RESULT_CANCEL];
168
+ return [RESULT_CANCEL, null];
250
169
  }
251
- return await this.waitResult(requestCode);
170
+ return await Navigation.result(this.sceneId, requestCode);
252
171
  };
253
172
  showModalLayout = async (layout) => {
254
173
  const requestCode = --tagGenerator;
255
- const success = await this.dispatch('showModalLayout', { layout, requestCode });
174
+ const success = await Navigation.dispatch(this.sceneId, 'showModalLayout', {
175
+ layout,
176
+ requestCode,
177
+ });
256
178
  if (!success) {
257
- return [RESULT_CANCEL];
179
+ return [RESULT_CANCEL, null];
258
180
  }
259
- return await this.waitResult(requestCode);
181
+ return await Navigation.result(this.sceneId, requestCode);
260
182
  };
261
- hideModal = () => this.dispatch('hideModal');
262
- setResult = (resultCode, data = null) => NavigationModule.setResult(this.sceneId, resultCode, data);
183
+ hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal');
184
+ setResult = (resultCode, data = null) => Navigation.setResult(this.sceneId, resultCode, data);
263
185
  switchTab = async (index, popToRoot = false) => {
264
- const from = await NavigationModule.currentTab(this.sceneId);
265
- return this.dispatch('switchTab', { from, to: index, popToRoot });
186
+ const from = await Navigation.currentTab(this.sceneId);
187
+ return Navigation.dispatch(this.sceneId, 'switchTab', { from, to: index, popToRoot });
266
188
  };
267
- toggleMenu = () => this.dispatch('toggleMenu');
268
- openMenu = () => this.dispatch('openMenu');
269
- closeMenu = () => this.dispatch('closeMenu');
270
- signalFirstRenderComplete = () => NavigationModule.signalFirstRenderComplete(this.sceneId);
189
+ toggleMenu = () => Navigation.dispatch(this.sceneId, 'toggleMenu');
190
+ openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu');
191
+ closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu');
192
+ isStackRoot = () => Navigation.isStackRoot(this.sceneId);
193
+ signalFirstRenderComplete = () => Navigation.signalFirstRenderComplete(this.sceneId);
271
194
  }
@@ -1,19 +1,22 @@
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';
13
4
  export declare class ReactRegistry {
14
- static registerEnded: boolean;
5
+ /**
6
+ * @deprecated Use Navigation.startRegisterComponent() instead.
7
+ * @param hoc
8
+ */
15
9
  static startRegisterComponent(hoc?: HOC): void;
10
+ /**
11
+ * @deprecated Use Navigation.endRegisterComponent() instead.
12
+ */
16
13
  static endRegisterComponent(): void;
14
+ /**
15
+ *
16
+ * @deprecated Use Navigation.registerComponent() instead.
17
+ * @param appKey
18
+ * @param getComponentFunc
19
+ * @param routeConfig
20
+ */
17
21
  static registerComponent(appKey: string, getComponentFunc: ComponentProvider, routeConfig?: RouteConfig): void;
18
22
  }
19
- export declare function withNavigationItem(item: NavigationItem): (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>;
@@ -1,81 +1,26 @@
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';
38
2
  export class ReactRegistry {
39
- static registerEnded;
3
+ /**
4
+ * @deprecated Use Navigation.startRegisterComponent() instead.
5
+ * @param hoc
6
+ */
40
7
  static startRegisterComponent(hoc) {
41
- wrap = hoc;
42
- ReactRegistry.registerEnded = false;
43
- NavigationModule.startRegisterReactComponent();
8
+ Navigation.startRegisterReactComponent(hoc);
44
9
  }
10
+ /**
11
+ * @deprecated Use Navigation.endRegisterComponent() instead.
12
+ */
45
13
  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();
14
+ Navigation.endRegisterReactComponent();
52
15
  }
16
+ /**
17
+ *
18
+ * @deprecated Use Navigation.registerComponent() instead.
19
+ * @param appKey
20
+ * @param getComponentFunc
21
+ * @param routeConfig
22
+ */
53
23
  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);
24
+ Navigation.registerReactComponent(appKey, getComponentFunc, routeConfig);
66
25
  }
67
26
  }
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
- }
@@ -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 {};