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
@@ -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,62 @@
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
+ export declare class Garden implements Garden {
6
8
  sceneId: string;
7
- static setStyle(style?: DefaultOptions): void;
8
- static statusBarHeight: number;
9
- static toolbarHeight: number;
10
- static topBarHeight: number;
9
+ /**
10
+ * @deprecated Use Navigation.setDefaultOptions() instead.
11
+ * @param style
12
+ */
13
+ static setStyle(style: DefaultOptions): void;
11
14
  constructor(sceneId: string);
15
+ /**
16
+ * @deprecated Use Navigation.setLeftBarButtonItem() instead.
17
+ * @param buttonItem
18
+ */
12
19
  setLeftBarButtonItem(buttonItem: Nullable<BarButtonItem> | null): void;
20
+ /**
21
+ * @deprecated Use Navigation.setRightBarButtonItem() instead.
22
+ * @param buttonItem
23
+ */
13
24
  setRightBarButtonItem(buttonItem: Nullable<BarButtonItem> | null): void;
25
+ /**
26
+ *
27
+ * @deprecated Use Navigation.setLeftBarButtonItems() instead.
28
+ * @param buttonItems
29
+ */
14
30
  setLeftBarButtonItems(buttonItems: Array<Nullable<BarButtonItem>> | null): void;
31
+ /**
32
+ * @deprecated Use Navigation.setRightBarButtonItems() instead.
33
+ * @param buttonItems
34
+ */
15
35
  setRightBarButtonItems(buttonItems: Array<Nullable<BarButtonItem>> | null): void;
36
+ /**
37
+ * @deprecated Use Navigation.setTitleItem() instead.
38
+ * @param titleItem
39
+ */
16
40
  setTitleItem(titleItem: TitleItem): void;
41
+ /**
42
+ * @deprecated Use Navigation.updateOptions() instead.
43
+ * @param options
44
+ */
17
45
  updateOptions(options: NavigationOption): void;
46
+ /**
47
+ * @deprecated Use Navigation.updateTabBar() instead.
48
+ * @param options
49
+ */
18
50
  updateTabBar(options: TabBarStyle): void;
51
+ /**
52
+ * @deprecated Use Navigation.setTabItem() instead.
53
+ * @param item
54
+ */
19
55
  setTabItem(item: TabItemInfo | TabItemInfo[]): void;
56
+ /**
57
+ * @deprecated Use Navigation.setMenuInteractive() instead.
58
+ * @param enabled
59
+ */
20
60
  setMenuInteractive(enabled: boolean): void;
21
61
  }
22
62
  export {};
package/lib/Garden.js CHANGED
@@ -1,57 +1,78 @@
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';
11
2
  export class Garden {
12
3
  sceneId;
13
- static setStyle(style = {}) {
14
- GardenModule.setStyle(style);
4
+ /**
5
+ * @deprecated Use Navigation.setDefaultOptions() instead.
6
+ * @param style
7
+ */
8
+ static setStyle(style) {
9
+ Navigation.setDefaultOptions(style);
15
10
  }
16
- static statusBarHeight = STATUSBAR_HEIGHT;
17
- static toolbarHeight = TOOLBAR_HEIGHT;
18
- static topBarHeight = TOOLBAR_HEIGHT + STATUSBAR_HEIGHT;
19
11
  constructor(sceneId) {
20
12
  this.sceneId = sceneId;
21
13
  }
22
- // --------------- instance method --------------
14
+ /**
15
+ * @deprecated Use Navigation.setLeftBarButtonItem() instead.
16
+ * @param buttonItem
17
+ */
23
18
  setLeftBarButtonItem(buttonItem) {
24
- const options = Event.bindBarButtonClickEvent(this.sceneId, buttonItem);
25
- GardenModule.setLeftBarButtonItem(this.sceneId, options);
19
+ Navigation.setLeftBarButtonItem(this.sceneId, buttonItem);
26
20
  }
21
+ /**
22
+ * @deprecated Use Navigation.setRightBarButtonItem() instead.
23
+ * @param buttonItem
24
+ */
27
25
  setRightBarButtonItem(buttonItem) {
28
- const options = Event.bindBarButtonClickEvent(this.sceneId, buttonItem);
29
- GardenModule.setRightBarButtonItem(this.sceneId, options);
26
+ Navigation.setRightBarButtonItem(this.sceneId, buttonItem);
30
27
  }
28
+ /**
29
+ *
30
+ * @deprecated Use Navigation.setLeftBarButtonItems() instead.
31
+ * @param buttonItems
32
+ */
31
33
  setLeftBarButtonItems(buttonItems) {
32
- const options = Event.bindBarButtonClickEvent(this.sceneId, buttonItems);
33
- GardenModule.setLeftBarButtonItems(this.sceneId, options);
34
+ Navigation.setLeftBarButtonItems(this.sceneId, buttonItems);
34
35
  }
36
+ /**
37
+ * @deprecated Use Navigation.setRightBarButtonItems() instead.
38
+ * @param buttonItems
39
+ */
35
40
  setRightBarButtonItems(buttonItems) {
36
- const options = Event.bindBarButtonClickEvent(this.sceneId, buttonItems);
37
- GardenModule.setRightBarButtonItems(this.sceneId, options);
41
+ Navigation.setRightBarButtonItems(this.sceneId, buttonItems);
38
42
  }
43
+ /**
44
+ * @deprecated Use Navigation.setTitleItem() instead.
45
+ * @param titleItem
46
+ */
39
47
  setTitleItem(titleItem) {
40
- GardenModule.setTitleItem(this.sceneId, titleItem);
48
+ Navigation.setTitleItem(this.sceneId, titleItem);
41
49
  }
50
+ /**
51
+ * @deprecated Use Navigation.updateOptions() instead.
52
+ * @param options
53
+ */
42
54
  updateOptions(options) {
43
- GardenModule.updateOptions(this.sceneId, options);
55
+ Navigation.updateOptions(this.sceneId, options);
44
56
  }
57
+ /**
58
+ * @deprecated Use Navigation.updateTabBar() instead.
59
+ * @param options
60
+ */
45
61
  updateTabBar(options) {
46
- GardenModule.updateTabBar(this.sceneId, options);
62
+ Navigation.updateTabBar(this.sceneId, options);
47
63
  }
64
+ /**
65
+ * @deprecated Use Navigation.setTabItem() instead.
66
+ * @param item
67
+ */
48
68
  setTabItem(item) {
49
- if (!Array.isArray(item)) {
50
- item = [item];
51
- }
52
- GardenModule.setTabItem(this.sceneId, item);
69
+ Navigation.setTabItem(this.sceneId, item);
53
70
  }
71
+ /**
72
+ * @deprecated Use Navigation.setMenuInteractive() instead.
73
+ * @param enabled
74
+ */
54
75
  setMenuInteractive(enabled) {
55
- GardenModule.setMenuInteractive(this.sceneId, enabled);
76
+ Navigation.setMenuInteractive(this.sceneId, enabled);
56
77
  }
57
78
  }
@@ -0,0 +1,74 @@
1
+ import type React from 'react';
2
+ import { ComponentProvider } from 'react-native';
3
+ import type { BarButtonItem, DefaultOptions, NavigationOption, TabBarStyle, TabItemInfo, TitleItem } from './Options';
4
+ import type { BuildInLayout, Layout, Route, RouteGraph, RouteConfig } from './Route';
5
+ import { ResultType } from './handler/ResultEventHandler';
6
+ import { GlobalVisibilityEventListener, VisibilityEventListener } from './handler/VisibilityEventHandler';
7
+ export type { ResultType } from './handler/ResultEventHandler';
8
+ import type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
9
+ export type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
10
+ declare type BarButtonClickEventListener = (sceneId: string, value: Function) => void;
11
+ declare type Nullable<T> = {
12
+ [P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P];
13
+ };
14
+ export declare const RESULT_CANCEL: number, RESULT_OK: number;
15
+ export declare type NavigationSubscription = {
16
+ remove: () => void;
17
+ };
18
+ export declare type HOC = (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>;
19
+ export interface Navigation {
20
+ }
21
+ export declare class Navigation implements Navigation {
22
+ private dispatchHandler;
23
+ private resultHandler;
24
+ private buttonHandler;
25
+ private layoutHandler;
26
+ private visibilityHandler;
27
+ constructor();
28
+ private wrap?;
29
+ private hoc?;
30
+ private registerEnded;
31
+ startRegisterReactComponent(hoc?: HOC): void;
32
+ endRegisterReactComponent(): void;
33
+ registerReactComponent(appKey: string, getComponentFunc: ComponentProvider, routeConfig?: RouteConfig): void;
34
+ setNavigationComponentWrap(wrap: (moduleName: string) => HOC): void;
35
+ addGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener): NavigationSubscription;
36
+ addVisibilityEventListener(sceneId: string, listener: VisibilityEventListener): NavigationSubscription;
37
+ dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<boolean>;
38
+ private handleTabSwitch;
39
+ setInterceptor(interceptor: NavigationInterceptor): void;
40
+ setResult: <T extends ResultType>(sceneId: string, resultCode: number, data?: T) => void;
41
+ result<T>(sceneId: string, resultCode: number): Promise<[number, T]>;
42
+ unmount(sceneId: string): void;
43
+ setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<void>;
44
+ setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
45
+ currentTab(sceneId: string): Promise<number>;
46
+ findSceneIdByModuleName(moduleName: string): Promise<string | null>;
47
+ isStackRoot(sceneId: string): Promise<boolean>;
48
+ signalFirstRenderComplete(sceneId: string): void;
49
+ currentRoute(): Promise<Route>;
50
+ routeGraph(): Promise<RouteGraph[]>;
51
+ private _routeConfigs;
52
+ private registerRoute;
53
+ routeConfigs(): Map<string, RouteConfig>;
54
+ setDefaultOptions(options: DefaultOptions): void;
55
+ setLeftBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void;
56
+ setRightBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void;
57
+ setLeftBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null): void;
58
+ setRightBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null): void;
59
+ setTitleItem(sceneId: string, titleItem: TitleItem): void;
60
+ updateOptions(sceneId: string, options: NavigationOption): void;
61
+ updateTabBar(sceneId: string, options: TabBarStyle): void;
62
+ setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]): void;
63
+ setMenuInteractive(sceneId: string, enabled: boolean): void;
64
+ private _statusBarHeight;
65
+ private _toolbarHeight;
66
+ private handleStatusBarHeightChange;
67
+ statusBarHeight(): number;
68
+ toolbarHeight(): number;
69
+ topBarHeight(): number;
70
+ setBarButtonClickEventListener(listener: BarButtonClickEventListener): void;
71
+ private bindBarButtonClickEvent;
72
+ }
73
+ declare const _default: Navigation;
74
+ export default _default;
@@ -0,0 +1,182 @@
1
+ import { AppRegistry, Platform } from 'react-native';
2
+ import BarButtonEventHandler from './handler/BarButtonEventHandler';
3
+ import LayoutCommandHandler from './handler/LayoutCommandHandler';
4
+ import DispatchCommandHandler from './handler/DispatchCommandHandler';
5
+ import ResultEventHandler from './handler/ResultEventHandler';
6
+ import VisibilityEventHandler from './handler/VisibilityEventHandler';
7
+ import Event from './Event';
8
+ import GardenModule from './GardenModule';
9
+ import NavigationModule from './NavigationModule';
10
+ const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT } = GardenModule.getConstants();
11
+ export const { RESULT_CANCEL, RESULT_OK } = NavigationModule.getConstants();
12
+ export class Navigation {
13
+ dispatchHandler = new DispatchCommandHandler();
14
+ resultHandler = new ResultEventHandler();
15
+ buttonHandler = new BarButtonEventHandler();
16
+ layoutHandler = new LayoutCommandHandler();
17
+ visibilityHandler = new VisibilityEventHandler();
18
+ constructor() {
19
+ this.handleStatusBarHeightChange();
20
+ this.handleTabSwitch();
21
+ this.layoutHandler.handleRootLayoutChange();
22
+ this.visibilityHandler.handleComponentVisibility();
23
+ this.resultHandler.handleComponentResult();
24
+ }
25
+ wrap;
26
+ hoc;
27
+ registerEnded = false;
28
+ startRegisterReactComponent(hoc) {
29
+ this.hoc = hoc;
30
+ this.registerEnded = false;
31
+ NavigationModule.startRegisterReactComponent();
32
+ }
33
+ endRegisterReactComponent() {
34
+ if (this.registerEnded) {
35
+ console.warn(`Please don't call ReactRegistry#endRegisterComponent multiple times.`);
36
+ return;
37
+ }
38
+ this.registerEnded = true;
39
+ NavigationModule.endRegisterReactComponent();
40
+ }
41
+ registerReactComponent(appKey, getComponentFunc, routeConfig) {
42
+ if (routeConfig) {
43
+ this.registerRoute(appKey, routeConfig);
44
+ }
45
+ let WrappedComponent = getComponentFunc();
46
+ if (this.hoc) {
47
+ WrappedComponent = this.hoc(WrappedComponent);
48
+ }
49
+ // build static options
50
+ let options = this.bindBarButtonClickEvent('permanent', WrappedComponent.navigationItem) || {};
51
+ NavigationModule.registerReactComponent(appKey, options);
52
+ let RootComponent = this.wrap(appKey)(WrappedComponent);
53
+ AppRegistry.registerComponent(appKey, () => RootComponent);
54
+ }
55
+ setNavigationComponentWrap(wrap) {
56
+ this.wrap = wrap;
57
+ }
58
+ addGlobalVisibilityEventListener(listener) {
59
+ this.visibilityHandler.addGlobalVisibilityEventListener(listener);
60
+ return {
61
+ remove: () => this.visibilityHandler.removeGlobalVisibilityEventListener(listener),
62
+ };
63
+ }
64
+ addVisibilityEventListener(sceneId, listener) {
65
+ this.visibilityHandler.addVisibilityEventListener(sceneId, listener);
66
+ return {
67
+ remove: () => this.visibilityHandler.removeVisibilityEventListener(sceneId, listener),
68
+ };
69
+ }
70
+ dispatch(sceneId, action, params = {}) {
71
+ return this.dispatchHandler.dispatch(sceneId, action, params);
72
+ }
73
+ handleTabSwitch() {
74
+ Event.listenTabSwitch((sceneId, from, to) => {
75
+ this.dispatch(sceneId, 'switchTab', { from, to });
76
+ });
77
+ }
78
+ setInterceptor(interceptor) {
79
+ this.dispatchHandler.setInterceptor(interceptor);
80
+ }
81
+ setResult = (sceneId, resultCode, data = null) => NavigationModule.setResult(sceneId, resultCode, data);
82
+ result(sceneId, resultCode) {
83
+ return this.resultHandler.waitResult(sceneId, resultCode);
84
+ }
85
+ unmount(sceneId) {
86
+ this.resultHandler.invalidateResultEventListener(sceneId);
87
+ this.buttonHandler.unbindBarButtonClickEvent(sceneId);
88
+ }
89
+ setRoot(layout, sticky = false) {
90
+ return this.layoutHandler.setRoot(layout, sticky);
91
+ }
92
+ setRootLayoutUpdateListener(willSetRoot = () => { }, didSetRoot = () => { }) {
93
+ this.layoutHandler.setRootLayoutUpdateListener(willSetRoot, didSetRoot);
94
+ }
95
+ currentTab(sceneId) {
96
+ return NavigationModule.currentTab(sceneId);
97
+ }
98
+ findSceneIdByModuleName(moduleName) {
99
+ return NavigationModule.findSceneIdByModuleName(moduleName);
100
+ }
101
+ isStackRoot(sceneId) {
102
+ return NavigationModule.isStackRoot(sceneId);
103
+ }
104
+ signalFirstRenderComplete(sceneId) {
105
+ NavigationModule.signalFirstRenderComplete(sceneId);
106
+ }
107
+ currentRoute() {
108
+ return NavigationModule.currentRoute();
109
+ }
110
+ routeGraph() {
111
+ return NavigationModule.routeGraph();
112
+ }
113
+ _routeConfigs = new Map();
114
+ registerRoute(moduleName, route) {
115
+ this._routeConfigs.set(moduleName, route);
116
+ }
117
+ routeConfigs() {
118
+ return this._routeConfigs;
119
+ }
120
+ setDefaultOptions(options) {
121
+ GardenModule.setStyle(options);
122
+ }
123
+ setLeftBarButtonItem(sceneId, buttonItem) {
124
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItem);
125
+ GardenModule.setLeftBarButtonItem(sceneId, options);
126
+ }
127
+ setRightBarButtonItem(sceneId, buttonItem) {
128
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItem);
129
+ GardenModule.setRightBarButtonItem(sceneId, options);
130
+ }
131
+ setLeftBarButtonItems(sceneId, buttonItems) {
132
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
133
+ GardenModule.setLeftBarButtonItems(sceneId, options);
134
+ }
135
+ setRightBarButtonItems(sceneId, buttonItems) {
136
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
137
+ GardenModule.setRightBarButtonItems(sceneId, options);
138
+ }
139
+ setTitleItem(sceneId, titleItem) {
140
+ GardenModule.setTitleItem(sceneId, titleItem);
141
+ }
142
+ updateOptions(sceneId, options) {
143
+ GardenModule.updateOptions(sceneId, options);
144
+ }
145
+ updateTabBar(sceneId, options) {
146
+ GardenModule.updateTabBar(sceneId, options);
147
+ }
148
+ setTabItem(sceneId, item) {
149
+ if (!Array.isArray(item)) {
150
+ item = [item];
151
+ }
152
+ GardenModule.setTabItem(sceneId, item);
153
+ }
154
+ setMenuInteractive(sceneId, enabled) {
155
+ GardenModule.setMenuInteractive(sceneId, enabled);
156
+ }
157
+ _statusBarHeight = STATUSBAR_HEIGHT;
158
+ _toolbarHeight = TOOLBAR_HEIGHT;
159
+ handleStatusBarHeightChange() {
160
+ if (Platform.OS === 'ios') {
161
+ Event.listenStatusBarHeightChange(statusBarHeight => {
162
+ this._statusBarHeight = statusBarHeight;
163
+ });
164
+ }
165
+ }
166
+ statusBarHeight() {
167
+ return this._statusBarHeight;
168
+ }
169
+ toolbarHeight() {
170
+ return this._toolbarHeight;
171
+ }
172
+ topBarHeight() {
173
+ return this.statusBarHeight() + this.toolbarHeight();
174
+ }
175
+ setBarButtonClickEventListener(listener) {
176
+ this.buttonHandler.setBarButtonClickEventListener(listener);
177
+ }
178
+ bindBarButtonClickEvent(sceneId, item) {
179
+ return this.buttonHandler.bindBarButtonClickEvent(sceneId, item);
180
+ }
181
+ }
182
+ export default new Navigation();
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import type { Garden } from './Garden';
3
+ import type { NavigationItem } from './Options';
4
+ import { Navigator } from './Navigator';
5
+ export interface NavigationComponentProps {
6
+ navigator: Navigator;
7
+ garden: Garden;
8
+ sceneId: string;
9
+ }
10
+ /**
11
+ * @deprecated Use NavigationComponentProps instead.
12
+ */
13
+ export declare type InjectedProps = NavigationComponentProps;
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 {};