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
@@ -28,7 +28,6 @@ import com.facebook.react.bridge.ReactContext;
28
28
  import com.facebook.react.common.LifecycleState;
29
29
  import com.navigation.androidx.FragmentHelper;
30
30
  import com.navigation.androidx.Style;
31
- import com.navigation.androidx.TransitionAnimation;
32
31
 
33
32
  public class ReactFragment extends HybridFragment implements ReactRootViewHolder.VisibilityObserver, ReactBridgeManager.ReactBridgeReloadListener {
34
33
 
@@ -49,11 +48,8 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
49
48
  reactRootViewHolder = (ReactRootViewHolder) containerLayout;
50
49
  reactRootViewHolder.setVisibilityObserver(this);
51
50
  }
52
-
51
+
53
52
  if (!FragmentHelper.isHidden(this) || getShowsDialog()) {
54
- if (getAnimation() != TransitionAnimation.None) {
55
- postponeEnterTransition();
56
- }
57
53
  initReactRootView();
58
54
  }
59
55
 
@@ -201,8 +197,7 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
201
197
  return;
202
198
  }
203
199
  firstRenderCompleted = true;
204
- startPostponedEnterTransition();
205
-
200
+
206
201
  if (isViewReady() && isResumed()) {
207
202
  sendViewAppearEvent(true);
208
203
  reactRootView.addOnGlobalLayoutListener();
@@ -301,17 +296,5 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
301
296
  }
302
297
  return new Toolbar.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, Gravity.CENTER);
303
298
  }
304
-
305
- @Override
306
- public void postponeEnterTransition() {
307
- super.postponeEnterTransition();
308
- requireActivity().supportPostponeEnterTransition();
309
- }
310
-
311
- @Override
312
- public void startPostponedEnterTransition() {
313
- super.startPostponedEnterTransition();
314
- requireActivity().supportStartPostponedEnterTransition();
315
- }
316
-
299
+
317
300
  }
package/lib/Event.d.ts CHANGED
@@ -1,22 +1,18 @@
1
- declare function listenStatusBarHeightChanged(listener: (statusBarHeight: number) => void): import("react-native").EmitterSubscription;
1
+ import type { Visibility } from './Route';
2
+ declare function listenStatusBarHeightChange(listener: (statusBarHeight: number) => void): import("react-native").EmitterSubscription;
2
3
  declare function listenComponentResult(listener: (sceneId: string, requestCode: number, resultCode: number, resultData: object) => void): import("react-native").EmitterSubscription;
3
- declare function listenComponentVisibility(componentDidAppear: (sceneId: string) => void, componentDidDisappear: (sceneId: string) => void): import("react-native").EmitterSubscription;
4
- declare function listenSwitchTab(listener: (sceneId: string, from: number, to: number) => void): import("react-native").EmitterSubscription;
5
- declare function listenSetRoot(willSetRoot: () => void, didSetRoot: (tag: number) => void): {
6
- remove: () => void;
7
- };
8
- declare let barButtonClickHandlerFactory: () => (sceneId: string, value: Function) => void;
9
- declare function setBarButtonClickHandlerFactory(generator: typeof barButtonClickHandlerFactory): void;
10
- declare function bindBarButtonClickEvent(sceneId: string, item: object | null | undefined): object | null;
11
- declare function removeBarButtonClickEvent(sceneId: string): void;
4
+ declare function listenComponentVisibility(listener: (sceneId: string, visibility: Visibility) => void): import("react-native").EmitterSubscription;
5
+ declare function listenBarButtonItemClick(listener: (sceneId: string, action: string) => void): import("react-native").EmitterSubscription;
6
+ declare function listenTabSwitch(listener: (sceneId: string, from: number, to: number) => void): import("react-native").EmitterSubscription;
7
+ declare function listenWillSetRoot(willSetRoot: () => void): import("react-native").EmitterSubscription;
8
+ declare function listenDidSetRoot(didSetRoot: (tag: number) => void): import("react-native").EmitterSubscription;
12
9
  declare const _default: {
13
- listenStatusBarHeightChanged: typeof listenStatusBarHeightChanged;
10
+ listenStatusBarHeightChange: typeof listenStatusBarHeightChange;
11
+ listenBarButtonItemClick: typeof listenBarButtonItemClick;
14
12
  listenComponentResult: typeof listenComponentResult;
15
13
  listenComponentVisibility: typeof listenComponentVisibility;
16
- listenSwitchTab: typeof listenSwitchTab;
17
- listenSetRoot: typeof listenSetRoot;
18
- bindBarButtonClickEvent: typeof bindBarButtonClickEvent;
19
- removeBarButtonClickEvent: typeof removeBarButtonClickEvent;
20
- setBarButtonClickHandlerFactory: typeof setBarButtonClickHandlerFactory;
14
+ listenTabSwitch: typeof listenTabSwitch;
15
+ listenWillSetRoot: typeof listenWillSetRoot;
16
+ listenDidSetRoot: typeof listenDidSetRoot;
21
17
  };
22
18
  export default _default;
package/lib/Event.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { NativeModules, NativeEventEmitter } from 'react-native';
2
2
  import GardenModule from './GardenModule';
3
- function listenStatusBarHeightChanged(listener) {
3
+ function listenStatusBarHeightChange(listener) {
4
4
  const GardenEventReceiver = new NativeEventEmitter(GardenModule);
5
5
  const { EVENT_STATUSBAR_FRAME_CHANGE } = GardenModule.getConstants();
6
6
  return GardenEventReceiver.addListener(EVENT_STATUSBAR_FRAME_CHANGE, ({ statusBarHeight }) => {
@@ -21,14 +21,14 @@ function listenComponentResult(listener) {
21
21
  }
22
22
  });
23
23
  }
24
- function listenComponentVisibility(componentDidAppear, componentDidDisappear) {
24
+ function listenComponentVisibility(listener) {
25
25
  const { EVENT_NAVIGATION, KEY_ON, ON_COMPONENT_APPEAR, ON_COMPONENT_DISAPPEAR, KEY_SCENE_ID } = HBDEventEmitter.getConstants();
26
26
  return HBDEventReceiver.addListener(EVENT_NAVIGATION, data => {
27
27
  if (data[KEY_ON] === ON_COMPONENT_APPEAR) {
28
- componentDidAppear(data[KEY_SCENE_ID]);
28
+ listener(data[KEY_SCENE_ID], 'visible');
29
29
  }
30
- else if (data[KEY_ON] === ON_COMPONENT_DISAPPEAR) {
31
- componentDidDisappear(data[KEY_SCENE_ID]);
30
+ if (data[KEY_ON] === ON_COMPONENT_DISAPPEAR) {
31
+ listener(data[KEY_SCENE_ID], 'invisible');
32
32
  }
33
33
  });
34
34
  }
@@ -40,7 +40,7 @@ function listenBarButtonItemClick(listener) {
40
40
  }
41
41
  }, {});
42
42
  }
43
- function listenSwitchTab(listener) {
43
+ function listenTabSwitch(listener) {
44
44
  const { EVENT_SWITCH_TAB, KEY_INDEX, KEY_SCENE_ID } = HBDEventEmitter.getConstants();
45
45
  return HBDEventReceiver.addListener(EVENT_SWITCH_TAB, event => {
46
46
  const index = event[KEY_INDEX];
@@ -48,70 +48,24 @@ function listenSwitchTab(listener) {
48
48
  listener(event[KEY_SCENE_ID], parseInt(from, 10), parseInt(to, 10));
49
49
  });
50
50
  }
51
- function listenSetRoot(willSetRoot, didSetRoot) {
52
- const { EVENT_WILL_SET_ROOT, EVENT_DID_SET_ROOT } = HBDEventEmitter.getConstants();
53
- const subscriptions = [];
54
- subscriptions.push(HBDEventReceiver.addListener(EVENT_WILL_SET_ROOT, _ => {
51
+ function listenWillSetRoot(willSetRoot) {
52
+ const { EVENT_WILL_SET_ROOT } = HBDEventEmitter.getConstants();
53
+ return HBDEventReceiver.addListener(EVENT_WILL_SET_ROOT, _ => {
55
54
  willSetRoot();
56
- }));
57
- subscriptions.push(HBDEventReceiver.addListener(EVENT_DID_SET_ROOT, (event) => {
58
- didSetRoot(event.tag);
59
- }));
60
- return {
61
- remove: () => {
62
- subscriptions.forEach(subscription => subscription.remove());
63
- },
64
- };
65
- }
66
- const actions = {};
67
- const keyPairs = {};
68
- let actionIdGenerator = 0;
69
- let barButtonClickHandlerFactory = () => {
70
- return (sceneId, value) => {
71
- console.warn(`barButtonClickHandlerFactory 没有正确绑定`, sceneId, value);
72
- };
73
- };
74
- function setBarButtonClickHandlerFactory(generator) {
75
- barButtonClickHandlerFactory = generator;
76
- }
77
- function bindBarButtonClickEvent(sceneId, item) {
78
- if (item === null || item === undefined) {
79
- return null;
80
- }
81
- return JSON.parse(JSON.stringify(item, (key, value) => {
82
- if (key !== 'action' || typeof value !== 'function') {
83
- return value;
84
- }
85
- const actionKey = 'ON_BAR_BUTTON_ITEM_CLICK_' + actionIdGenerator++;
86
- if (!keyPairs[sceneId]) {
87
- keyPairs[sceneId] = [];
88
- }
89
- keyPairs[sceneId].push(actionKey);
90
- actions[actionKey] = value;
91
- return actionKey;
92
- }));
55
+ });
93
56
  }
94
- function removeBarButtonClickEvent(sceneId) {
95
- const keys = keyPairs[sceneId];
96
- delete keyPairs[sceneId];
97
- if (keys) {
98
- keys.forEach(key => delete actions[key]);
99
- }
57
+ function listenDidSetRoot(didSetRoot) {
58
+ const { EVENT_DID_SET_ROOT } = HBDEventEmitter.getConstants();
59
+ return HBDEventReceiver.addListener(EVENT_DID_SET_ROOT, (event) => {
60
+ didSetRoot(event.tag);
61
+ });
100
62
  }
101
- listenBarButtonItemClick((sceneId, action) => {
102
- const listeners = actions;
103
- if (listeners[action]) {
104
- const handler = barButtonClickHandlerFactory();
105
- handler(sceneId, listeners[action]);
106
- }
107
- });
108
63
  export default {
109
- listenStatusBarHeightChanged,
64
+ listenStatusBarHeightChange,
65
+ listenBarButtonItemClick,
110
66
  listenComponentResult,
111
67
  listenComponentVisibility,
112
- listenSwitchTab,
113
- listenSetRoot,
114
- bindBarButtonClickEvent,
115
- removeBarButtonClickEvent,
116
- setBarButtonClickHandlerFactory,
68
+ listenTabSwitch,
69
+ listenWillSetRoot,
70
+ listenDidSetRoot,
117
71
  };
package/lib/Garden.d.ts CHANGED
@@ -1,22 +1,65 @@
1
- import { BarButtonItem, DefaultOptions, NavigationOption, TabBarStyle, TabItemInfo, TitleItem } from './Options';
1
+ import type { BarButtonItem, DefaultOptions, NavigationOption, TabBarStyle, TabItemInfo, TitleItem } from './Options';
2
2
  declare type Nullable<T> = {
3
3
  [P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P];
4
4
  };
5
- export declare class Garden {
5
+ export interface Garden {
6
+ }
7
+ /**
8
+ * @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
9
+ */
10
+ export declare class Garden implements Garden {
6
11
  sceneId: string;
7
- static setStyle(style?: DefaultOptions): void;
8
- static statusBarHeight: number;
9
- static toolbarHeight: number;
10
- static topBarHeight: number;
12
+ /**
13
+ * @deprecated Use Navigation.setDefaultOptions() instead.
14
+ * @param style
15
+ */
16
+ static setStyle(style: DefaultOptions): void;
11
17
  constructor(sceneId: string);
18
+ /**
19
+ * @deprecated Use Navigation.setLeftBarButtonItem() instead.
20
+ * @param buttonItem
21
+ */
12
22
  setLeftBarButtonItem(buttonItem: Nullable<BarButtonItem> | null): void;
23
+ /**
24
+ * @deprecated Use Navigation.setRightBarButtonItem() instead.
25
+ * @param buttonItem
26
+ */
13
27
  setRightBarButtonItem(buttonItem: Nullable<BarButtonItem> | null): void;
28
+ /**
29
+ *
30
+ * @deprecated Use Navigation.setLeftBarButtonItems() instead.
31
+ * @param buttonItems
32
+ */
14
33
  setLeftBarButtonItems(buttonItems: Array<Nullable<BarButtonItem>> | null): void;
34
+ /**
35
+ * @deprecated Use Navigation.setRightBarButtonItems() instead.
36
+ * @param buttonItems
37
+ */
15
38
  setRightBarButtonItems(buttonItems: Array<Nullable<BarButtonItem>> | null): void;
39
+ /**
40
+ * @deprecated Use Navigation.setTitleItem() instead.
41
+ * @param titleItem
42
+ */
16
43
  setTitleItem(titleItem: TitleItem): void;
44
+ /**
45
+ * @deprecated Use Navigation.updateOptions() instead.
46
+ * @param options
47
+ */
17
48
  updateOptions(options: NavigationOption): void;
49
+ /**
50
+ * @deprecated Use Navigation.updateTabBar() instead.
51
+ * @param options
52
+ */
18
53
  updateTabBar(options: TabBarStyle): void;
54
+ /**
55
+ * @deprecated Use Navigation.setTabItem() instead.
56
+ * @param item
57
+ */
19
58
  setTabItem(item: TabItemInfo | TabItemInfo[]): void;
59
+ /**
60
+ * @deprecated Use Navigation.setMenuInteractive() instead.
61
+ * @param enabled
62
+ */
20
63
  setMenuInteractive(enabled: boolean): void;
21
64
  }
22
65
  export {};
package/lib/Garden.js CHANGED
@@ -1,57 +1,81 @@
1
- import { Platform } from 'react-native';
2
- import GardenModule from './GardenModule';
3
- import Event from './Event';
4
- const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT } = GardenModule.getConstants();
5
- if (Platform.OS === 'ios') {
6
- Event.listenStatusBarHeightChanged(statusBarHeight => {
7
- Garden.statusBarHeight = statusBarHeight;
8
- Garden.topBarHeight = statusBarHeight + TOOLBAR_HEIGHT;
9
- });
10
- }
1
+ import Navigation from './Navigation';
2
+ /**
3
+ * @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
4
+ */
11
5
  export class Garden {
12
6
  sceneId;
13
- static setStyle(style = {}) {
14
- GardenModule.setStyle(style);
7
+ /**
8
+ * @deprecated Use Navigation.setDefaultOptions() instead.
9
+ * @param style
10
+ */
11
+ static setStyle(style) {
12
+ Navigation.setDefaultOptions(style);
15
13
  }
16
- static statusBarHeight = STATUSBAR_HEIGHT;
17
- static toolbarHeight = TOOLBAR_HEIGHT;
18
- static topBarHeight = TOOLBAR_HEIGHT + STATUSBAR_HEIGHT;
19
14
  constructor(sceneId) {
20
15
  this.sceneId = sceneId;
21
16
  }
22
- // --------------- instance method --------------
17
+ /**
18
+ * @deprecated Use Navigation.setLeftBarButtonItem() instead.
19
+ * @param buttonItem
20
+ */
23
21
  setLeftBarButtonItem(buttonItem) {
24
- const options = Event.bindBarButtonClickEvent(this.sceneId, buttonItem);
25
- GardenModule.setLeftBarButtonItem(this.sceneId, options);
22
+ Navigation.setLeftBarButtonItem(this.sceneId, buttonItem);
26
23
  }
24
+ /**
25
+ * @deprecated Use Navigation.setRightBarButtonItem() instead.
26
+ * @param buttonItem
27
+ */
27
28
  setRightBarButtonItem(buttonItem) {
28
- const options = Event.bindBarButtonClickEvent(this.sceneId, buttonItem);
29
- GardenModule.setRightBarButtonItem(this.sceneId, options);
29
+ Navigation.setRightBarButtonItem(this.sceneId, buttonItem);
30
30
  }
31
+ /**
32
+ *
33
+ * @deprecated Use Navigation.setLeftBarButtonItems() instead.
34
+ * @param buttonItems
35
+ */
31
36
  setLeftBarButtonItems(buttonItems) {
32
- const options = Event.bindBarButtonClickEvent(this.sceneId, buttonItems);
33
- GardenModule.setLeftBarButtonItems(this.sceneId, options);
37
+ Navigation.setLeftBarButtonItems(this.sceneId, buttonItems);
34
38
  }
39
+ /**
40
+ * @deprecated Use Navigation.setRightBarButtonItems() instead.
41
+ * @param buttonItems
42
+ */
35
43
  setRightBarButtonItems(buttonItems) {
36
- const options = Event.bindBarButtonClickEvent(this.sceneId, buttonItems);
37
- GardenModule.setRightBarButtonItems(this.sceneId, options);
44
+ Navigation.setRightBarButtonItems(this.sceneId, buttonItems);
38
45
  }
46
+ /**
47
+ * @deprecated Use Navigation.setTitleItem() instead.
48
+ * @param titleItem
49
+ */
39
50
  setTitleItem(titleItem) {
40
- GardenModule.setTitleItem(this.sceneId, titleItem);
51
+ Navigation.setTitleItem(this.sceneId, titleItem);
41
52
  }
53
+ /**
54
+ * @deprecated Use Navigation.updateOptions() instead.
55
+ * @param options
56
+ */
42
57
  updateOptions(options) {
43
- GardenModule.updateOptions(this.sceneId, options);
58
+ Navigation.updateOptions(this.sceneId, options);
44
59
  }
60
+ /**
61
+ * @deprecated Use Navigation.updateTabBar() instead.
62
+ * @param options
63
+ */
45
64
  updateTabBar(options) {
46
- GardenModule.updateTabBar(this.sceneId, options);
65
+ Navigation.updateTabBar(this.sceneId, options);
47
66
  }
67
+ /**
68
+ * @deprecated Use Navigation.setTabItem() instead.
69
+ * @param item
70
+ */
48
71
  setTabItem(item) {
49
- if (!Array.isArray(item)) {
50
- item = [item];
51
- }
52
- GardenModule.setTabItem(this.sceneId, item);
72
+ Navigation.setTabItem(this.sceneId, item);
53
73
  }
74
+ /**
75
+ * @deprecated Use Navigation.setMenuInteractive() instead.
76
+ * @param enabled
77
+ */
54
78
  setMenuInteractive(enabled) {
55
- GardenModule.setMenuInteractive(this.sceneId, enabled);
79
+ Navigation.setMenuInteractive(this.sceneId, enabled);
56
80
  }
57
81
  }
@@ -0,0 +1,68 @@
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
+ private _routeConfigs;
35
+ private registerRoute;
36
+ routeConfigs(): Map<string, RouteConfig>;
37
+ setNavigationComponentWrap(wrap: (moduleName: string) => HOC): void;
38
+ addGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener): NavigationSubscription;
39
+ addVisibilityEventListener(sceneId: string, listener: VisibilityEventListener): NavigationSubscription;
40
+ dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<boolean>;
41
+ private handleTabSwitch;
42
+ setInterceptor(interceptor: NavigationInterceptor): void;
43
+ setResult: <T extends ResultType>(sceneId: string, resultCode: number, data?: T) => void;
44
+ result<T>(sceneId: string, resultCode: number): Promise<[number, T]>;
45
+ unmount(sceneId: string): void;
46
+ setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<void>;
47
+ setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
48
+ currentTab(sceneId: string): Promise<number>;
49
+ findSceneIdByModuleName(moduleName: string): Promise<string | null>;
50
+ isStackRoot(sceneId: string): Promise<boolean>;
51
+ signalFirstRenderComplete(sceneId: string): void;
52
+ currentRoute(): Promise<Route>;
53
+ routeGraph(): Promise<RouteGraph[]>;
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
+ setBarButtonClickEventListener(listener: BarButtonClickEventListener): void;
65
+ private bindBarButtonClickEvent;
66
+ }
67
+ declare const _default: Navigation;
68
+ export default _default;
@@ -0,0 +1,162 @@
1
+ import { AppRegistry } 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
+ export const { RESULT_CANCEL, RESULT_OK } = NavigationModule.getConstants();
11
+ export class Navigation {
12
+ dispatchHandler = new DispatchCommandHandler();
13
+ resultHandler = new ResultEventHandler();
14
+ buttonHandler = new BarButtonEventHandler();
15
+ layoutHandler = new LayoutCommandHandler();
16
+ visibilityHandler = new VisibilityEventHandler();
17
+ constructor() {
18
+ this.handleTabSwitch();
19
+ this.layoutHandler.handleRootLayoutChange();
20
+ this.visibilityHandler.handleComponentVisibility();
21
+ this.resultHandler.handleComponentResult();
22
+ }
23
+ wrap;
24
+ hoc;
25
+ registerEnded = false;
26
+ startRegisterComponent(hoc) {
27
+ this.hoc = hoc;
28
+ this.registerEnded = false;
29
+ NavigationModule.startRegisterReactComponent();
30
+ }
31
+ endRegisterComponent() {
32
+ if (this.registerEnded) {
33
+ console.warn(`Please don't call ReactRegistry#endRegisterComponent multiple times.`);
34
+ return;
35
+ }
36
+ this.registerEnded = true;
37
+ NavigationModule.endRegisterReactComponent();
38
+ }
39
+ registerComponent(appKey, getComponentFunc, routeConfig) {
40
+ if (routeConfig) {
41
+ this.registerRoute(appKey, routeConfig);
42
+ }
43
+ let WrappedComponent = getComponentFunc();
44
+ if (this.hoc) {
45
+ WrappedComponent = this.hoc(WrappedComponent);
46
+ }
47
+ // build static options
48
+ let options = this.bindBarButtonClickEvent('permanent', WrappedComponent.navigationItem) || {};
49
+ NavigationModule.registerReactComponent(appKey, options);
50
+ let RootComponent = this.wrap(appKey)(WrappedComponent);
51
+ AppRegistry.registerComponent(appKey, () => RootComponent);
52
+ }
53
+ _routeConfigs = new Map();
54
+ registerRoute(moduleName, route) {
55
+ this._routeConfigs.set(moduleName, route);
56
+ }
57
+ routeConfigs() {
58
+ return this._routeConfigs;
59
+ }
60
+ setNavigationComponentWrap(wrap) {
61
+ this.wrap = wrap;
62
+ }
63
+ addGlobalVisibilityEventListener(listener) {
64
+ this.visibilityHandler.addGlobalVisibilityEventListener(listener);
65
+ return {
66
+ remove: () => this.visibilityHandler.removeGlobalVisibilityEventListener(listener),
67
+ };
68
+ }
69
+ addVisibilityEventListener(sceneId, listener) {
70
+ this.visibilityHandler.addVisibilityEventListener(sceneId, listener);
71
+ return {
72
+ remove: () => this.visibilityHandler.removeVisibilityEventListener(sceneId, listener),
73
+ };
74
+ }
75
+ dispatch(sceneId, action, params = {}) {
76
+ return this.dispatchHandler.dispatch(sceneId, action, params);
77
+ }
78
+ handleTabSwitch() {
79
+ Event.listenTabSwitch((sceneId, from, to) => {
80
+ this.dispatch(sceneId, 'switchTab', { from, to });
81
+ });
82
+ }
83
+ setInterceptor(interceptor) {
84
+ this.dispatchHandler.setInterceptor(interceptor);
85
+ }
86
+ setResult = (sceneId, resultCode, data = null) => NavigationModule.setResult(sceneId, resultCode, data);
87
+ result(sceneId, resultCode) {
88
+ return this.resultHandler.waitResult(sceneId, resultCode);
89
+ }
90
+ unmount(sceneId) {
91
+ this.resultHandler.invalidateResultEventListener(sceneId);
92
+ this.buttonHandler.unbindBarButtonClickEvent(sceneId);
93
+ }
94
+ setRoot(layout, sticky = false) {
95
+ return this.layoutHandler.setRoot(layout, sticky);
96
+ }
97
+ setRootLayoutUpdateListener(willSetRoot = () => { }, didSetRoot = () => { }) {
98
+ this.layoutHandler.setRootLayoutUpdateListener(willSetRoot, didSetRoot);
99
+ }
100
+ currentTab(sceneId) {
101
+ return NavigationModule.currentTab(sceneId);
102
+ }
103
+ findSceneIdByModuleName(moduleName) {
104
+ return NavigationModule.findSceneIdByModuleName(moduleName);
105
+ }
106
+ isStackRoot(sceneId) {
107
+ return NavigationModule.isStackRoot(sceneId);
108
+ }
109
+ signalFirstRenderComplete(sceneId) {
110
+ NavigationModule.signalFirstRenderComplete(sceneId);
111
+ }
112
+ currentRoute() {
113
+ return NavigationModule.currentRoute();
114
+ }
115
+ routeGraph() {
116
+ return NavigationModule.routeGraph();
117
+ }
118
+ setDefaultOptions(options) {
119
+ GardenModule.setStyle(options);
120
+ }
121
+ setLeftBarButtonItem(sceneId, buttonItem) {
122
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItem);
123
+ GardenModule.setLeftBarButtonItem(sceneId, options);
124
+ }
125
+ setRightBarButtonItem(sceneId, buttonItem) {
126
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItem);
127
+ GardenModule.setRightBarButtonItem(sceneId, options);
128
+ }
129
+ setLeftBarButtonItems(sceneId, buttonItems) {
130
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
131
+ GardenModule.setLeftBarButtonItems(sceneId, options);
132
+ }
133
+ setRightBarButtonItems(sceneId, buttonItems) {
134
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
135
+ GardenModule.setRightBarButtonItems(sceneId, options);
136
+ }
137
+ setTitleItem(sceneId, titleItem) {
138
+ GardenModule.setTitleItem(sceneId, titleItem);
139
+ }
140
+ updateOptions(sceneId, options) {
141
+ GardenModule.updateOptions(sceneId, options);
142
+ }
143
+ updateTabBar(sceneId, options) {
144
+ GardenModule.updateTabBar(sceneId, options);
145
+ }
146
+ setTabItem(sceneId, item) {
147
+ if (!Array.isArray(item)) {
148
+ item = [item];
149
+ }
150
+ GardenModule.setTabItem(sceneId, item);
151
+ }
152
+ setMenuInteractive(sceneId, enabled) {
153
+ GardenModule.setMenuInteractive(sceneId, enabled);
154
+ }
155
+ setBarButtonClickEventListener(listener) {
156
+ this.buttonHandler.setBarButtonClickEventListener(listener);
157
+ }
158
+ bindBarButtonClickEvent(sceneId, item) {
159
+ return this.buttonHandler.bindBarButtonClickEvent(sceneId, item);
160
+ }
161
+ }
162
+ 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 NavigationProps 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 {};