hybrid-navigation 2.20.1 → 3.0.0

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 (136) hide show
  1. package/HybridNavigation.podspec +7 -5
  2. package/README.md +17 -0
  3. package/android/build.gradle +56 -19
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +1 -2
  6. package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +320 -326
  7. package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +13 -20
  8. package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +6 -11
  9. package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +55 -21
  10. package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +31 -0
  11. package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +223 -0
  12. package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +370 -0
  13. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +239 -224
  14. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +177 -198
  15. package/android/src/main/java/com/reactnative/hybridnavigation/ReactDrawerFragment.java +2 -9
  16. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +41 -78
  17. package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +438 -0
  18. package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +10 -19
  19. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +7 -15
  20. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +135 -173
  21. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +54 -227
  22. package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +2 -3
  23. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +12 -14
  24. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +18 -21
  25. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +17 -20
  26. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +13 -26
  27. package/dist/NativeEvent.d.ts +33 -0
  28. package/dist/NativeEvent.js +2 -0
  29. package/dist/NativeGarden.d.ts +18 -0
  30. package/dist/NativeGarden.js +2 -0
  31. package/dist/NativeNavigation.d.ts +47 -0
  32. package/dist/NativeNavigation.js +2 -0
  33. package/dist/Navigation.js +3 -3
  34. package/dist/NavigationModule.d.ts +3 -3
  35. package/dist/NavigationModule.js +18 -19
  36. package/dist/Navigator.js +1 -2
  37. package/dist/Options.d.ts +4 -7
  38. package/dist/Route.d.ts +0 -2
  39. package/dist/handler/BarButtonEventHandler.js +2 -2
  40. package/dist/handler/LayoutCommandHandler.js +3 -3
  41. package/dist/handler/ResultEventHandler.js +3 -3
  42. package/dist/handler/VisibilityEventHandler.js +11 -4
  43. package/dist/index.d.ts +0 -1
  44. package/dist/index.js +0 -1
  45. package/ios/HybridNavigation/GlobalStyle.h +0 -6
  46. package/ios/HybridNavigation/{GlobalStyle.m → GlobalStyle.mm} +54 -44
  47. package/ios/HybridNavigation/HBDUtils.h +0 -4
  48. package/ios/HybridNavigation/{HBDUtils.m → HBDUtils.mm} +0 -41
  49. package/ios/HybridNavigation/Navigator/{HBDScreenNavigator.m → HBDScreenNavigator.mm} +3 -9
  50. package/ios/HybridNavigation/Navigator/{HBDStackNavigator.m → HBDStackNavigator.mm} +0 -4
  51. package/ios/HybridNavigation/Navigator/{HBDTabNavigator.m → HBDTabNavigator.mm} +1 -55
  52. package/ios/HybridNavigation/React/HBDNativeEvent.h +13 -0
  53. package/ios/HybridNavigation/React/HBDNativeEvent.mm +31 -0
  54. package/ios/HybridNavigation/React/HBDNativeGarden.h +10 -0
  55. package/ios/HybridNavigation/React/HBDNativeGarden.mm +151 -0
  56. package/ios/HybridNavigation/React/HBDNativeNavigation.h +11 -0
  57. package/ios/HybridNavigation/React/HBDNativeNavigation.mm +263 -0
  58. package/ios/HybridNavigation/{ReactBridge → React}/HBDReactBridgeManager.h +3 -1
  59. package/ios/HybridNavigation/{ReactBridge/HBDReactBridgeManager.m → React/HBDReactBridgeManager.mm} +7 -30
  60. package/ios/HybridNavigation/View/HBDRootView.h +2 -2
  61. package/ios/HybridNavigation/View/{HBDRootView.m → HBDRootView.mm} +2 -2
  62. package/ios/HybridNavigation/View/HBDTitleView.h +2 -2
  63. package/ios/HybridNavigation/View/{HBDTitleView.m → HBDTitleView.mm} +3 -3
  64. package/ios/HybridNavigation/View/UIImage+WithBadge.h +13 -0
  65. package/ios/HybridNavigation/View/UIImage+WithBadge.mm +36 -0
  66. package/ios/HybridNavigation/ViewController/{HBDDrawerController.m → HBDDrawerController.mm} +2 -25
  67. package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -4
  68. package/ios/HybridNavigation/ViewController/{HBDReactViewController.m → HBDReactViewController.mm} +40 -31
  69. package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -2
  70. package/ios/HybridNavigation/ViewController/HBDTabBarController.mm +140 -0
  71. package/ios/HybridNavigation/ViewController/HBDViewController+Garden.h +0 -2
  72. package/ios/HybridNavigation/ViewController/{HBDViewController+Garden.m → HBDViewController+Garden.mm} +8 -26
  73. package/ios/HybridNavigation/ViewController/HBDViewController.h +2 -0
  74. package/ios/HybridNavigation/ViewController/{HBDViewController.m → HBDViewController.mm} +67 -57
  75. package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +0 -2
  76. package/ios/HybridNavigation/ViewController/{UIViewController+HBD.m → UIViewController+HBD.mm} +1 -42
  77. package/package.json +11 -2
  78. package/src/DeepLink.ts +3 -3
  79. package/src/NativeEvent.ts +40 -0
  80. package/src/NativeGarden.ts +27 -0
  81. package/src/NativeNavigation.ts +72 -0
  82. package/src/Navigation.ts +13 -13
  83. package/src/NavigationComponentWrap.tsx +4 -4
  84. package/src/NavigationModule.ts +21 -46
  85. package/src/Navigator.ts +13 -13
  86. package/src/Options.ts +9 -9
  87. package/src/Route.ts +0 -2
  88. package/src/handler/BarButtonEventHandler.ts +4 -8
  89. package/src/handler/DispatchCommandHandler.ts +4 -8
  90. package/src/handler/LayoutCommandHandler.ts +4 -5
  91. package/src/handler/ResultEventHandler.ts +11 -27
  92. package/src/handler/VisibilityEventHandler.ts +23 -32
  93. package/src/hooks.ts +2 -2
  94. package/src/index.ts +4 -5
  95. package/src/router/drawer.ts +5 -5
  96. package/src/router/index.ts +15 -15
  97. package/src/router/screen.ts +2 -2
  98. package/src/router/stack.ts +4 -4
  99. package/src/router/tabs.ts +3 -3
  100. package/src/store.ts +1 -1
  101. package/android/src/main/java/com/reactnative/hybridnavigation/DefaultTabBarProvider.java +0 -143
  102. package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +0 -230
  103. package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +0 -89
  104. package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +0 -71
  105. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +0 -370
  106. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +0 -445
  107. package/dist/Event.d.ts +0 -16
  108. package/dist/Event.js +0 -62
  109. package/dist/GardenModule.d.ts +0 -24
  110. package/dist/GardenModule.js +0 -21
  111. package/ios/HybridNavigation/HBDAnimationObserver.h +0 -24
  112. package/ios/HybridNavigation/HBDAnimationObserver.m +0 -45
  113. package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.h +0 -28
  114. package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.m +0 -72
  115. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +0 -6
  116. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +0 -157
  117. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +0 -6
  118. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +0 -249
  119. package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -9
  120. package/ios/HybridNavigation/View/HBDReactTabBar.m +0 -36
  121. package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -9
  122. package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -46
  123. package/ios/HybridNavigation/ViewController/HBDTabBarController.m +0 -265
  124. package/src/Event.ts +0 -117
  125. package/src/GardenModule.ts +0 -50
  126. /package/ios/HybridNavigation/Navigator/{HBDDrawerNavigator.m → HBDDrawerNavigator.mm} +0 -0
  127. /package/ios/HybridNavigation/Navigator/{HBDNavigatorRegistry.m → HBDNavigatorRegistry.mm} +0 -0
  128. /package/ios/HybridNavigation/{ReactBridge → React}/HBDNavigator.h +0 -0
  129. /package/ios/HybridNavigation/View/{HBDBackBarButtonItem.m → HBDBackBarButtonItem.mm} +0 -0
  130. /package/ios/HybridNavigation/View/{HBDBarButtonItem.m → HBDBarButtonItem.mm} +0 -0
  131. /package/ios/HybridNavigation/View/{HBDNavigationBar.m → HBDNavigationBar.mm} +0 -0
  132. /package/ios/HybridNavigation/ViewController/{HBDFadeAnimation.m → HBDFadeAnimation.mm} +0 -0
  133. /package/ios/HybridNavigation/ViewController/{HBDNavigationController.m → HBDNavigationController.mm} +0 -0
  134. /package/ios/HybridNavigation/ViewController/{HBDPopAnimation.m → HBDPopAnimation.mm} +0 -0
  135. /package/ios/HybridNavigation/ViewController/{HBDPushAnimation.m → HBDPushAnimation.mm} +0 -0
  136. /package/ios/HybridNavigation/ViewController/{UINavigationController+HBD.m → UINavigationController+HBD.mm} +0 -0
package/src/Navigation.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type React from 'react';
2
- import {AppRegistry, ComponentProvider} from 'react-native';
2
+ import { AppRegistry, ComponentProvider } from 'react-native';
3
3
 
4
4
  import type {
5
5
  BarButtonItem,
@@ -9,24 +9,24 @@ import type {
9
9
  TabItemInfo,
10
10
  TitleItem,
11
11
  } from './Options';
12
- import type {BuildInLayout, Layout, Route, RouteGraph, RouteConfig} from './Route';
12
+ import type { BuildInLayout, Layout, Route, RouteGraph, RouteConfig } from './Route';
13
13
 
14
14
  import BarButtonEventHandler from './handler/BarButtonEventHandler';
15
15
  import LayoutCommandHandler from './handler/LayoutCommandHandler';
16
16
  import DispatchCommandHandler from './handler/DispatchCommandHandler';
17
- import ResultEventHandler, {ResultType} from './handler/ResultEventHandler';
17
+ import ResultEventHandler, { ResultType } from './handler/ResultEventHandler';
18
18
  import VisibilityEventHandler, {
19
19
  GlobalVisibilityEventListener,
20
20
  VisibilityEventListener,
21
21
  } from './handler/VisibilityEventHandler';
22
22
 
23
- import Event from './Event';
24
- import GardenModule from './GardenModule';
23
+ import NativeEvent from './NativeEvent';
25
24
  import NavigationModule from './NavigationModule';
25
+ import GardenModule from './NativeGarden';
26
26
 
27
- export type {ResultType} from './handler/ResultEventHandler';
28
- import type {DispatchParams, NavigationInterceptor} from './handler/DispatchCommandHandler';
29
- export type {DispatchParams, NavigationInterceptor} from './handler/DispatchCommandHandler';
27
+ export type { ResultType } from './handler/ResultEventHandler';
28
+ import type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
29
+ export type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
30
30
 
31
31
  type BarButtonClickEventListener = (sceneId: string, value: Function) => void;
32
32
 
@@ -34,7 +34,7 @@ type Nullable<T> = {
34
34
  [P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P];
35
35
  };
36
36
 
37
- export const {RESULT_CANCEL, RESULT_OK, RESULT_BLOCK} = NavigationModule.getConstants();
37
+ export const { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK } = NavigationModule.getConstants();
38
38
 
39
39
  export type NavigationSubscription = {
40
40
  remove: () => void;
@@ -187,8 +187,8 @@ class NavigationImpl implements Navigation {
187
187
  }
188
188
 
189
189
  private handleTabSwitch() {
190
- Event.listenTabSwitch((sceneId: string, from: number, to: number) => {
191
- this.dispatch(sceneId, 'switchTab', {from, to});
190
+ NativeEvent.onSwitchTab(({ sceneId, from, to }) => {
191
+ this.dispatch(sceneId, 'switchTab', { from, to });
192
192
  });
193
193
  }
194
194
 
@@ -265,12 +265,12 @@ class NavigationImpl implements Navigation {
265
265
  }
266
266
 
267
267
  setLeftBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null) {
268
- const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
268
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItems) as Array<{}> | null;
269
269
  GardenModule.setLeftBarButtonItems(sceneId, options);
270
270
  }
271
271
 
272
272
  setRightBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null) {
273
- const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
273
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItems) as Array<{}> | null;
274
274
  GardenModule.setRightBarButtonItems(sceneId, options);
275
275
  }
276
276
 
@@ -1,6 +1,6 @@
1
- import React, {useEffect} from 'react';
2
- import type {NavigationItem} from './Options';
3
- import {Navigator, NavigationContext} from './Navigator';
1
+ import React, { useEffect } from 'react';
2
+ import type { NavigationItem } from './Options';
3
+ import { Navigator, NavigationContext } from './Navigator';
4
4
  import Navigation from './Navigation';
5
5
 
6
6
  export interface NavigationProps {
@@ -20,7 +20,7 @@ export function withNavigation(moduleName: string) {
20
20
  return function (WrappedComponent: React.ComponentType<any>) {
21
21
  const FC = React.forwardRef(
22
22
  (props: NativeProps, ref: React.Ref<React.ComponentType<any>>) => {
23
- const {sceneId} = props;
23
+ const { sceneId } = props;
24
24
 
25
25
  const navigator = Navigator.of(sceneId);
26
26
  if (navigator.moduleName === undefined) {
@@ -1,58 +1,33 @@
1
- import {NativeModules} from 'react-native';
2
- import {Route, RouteGraph} from './Route';
3
-
4
- type Callback = (error: never, result: any) => void;
5
-
6
- interface NavigationModule {
7
- getConstants: () => {
8
- RESULT_OK: number;
9
- RESULT_CANCEL: number;
10
- RESULT_BLOCK: number;
11
- };
12
-
13
- startRegisterReactComponent: () => void;
14
- endRegisterReactComponent: () => void;
15
- registerReactComponent: (appKey: string, options: object) => void;
16
- signalFirstRenderComplete: (sceneId: string) => void;
17
- setRoot: (layout: object, sticky: boolean, callback: Callback) => void;
18
- setResult: (sceneId: string, resultCode: number, data: object | null) => void;
19
- dispatch: (sceneId: string, action: string, params: object, callback: Callback) => void;
20
- currentTab: (sceneId: string, callback: Callback) => void;
21
- isStackRoot: (sceneId: string, callback: Callback) => void;
22
- findSceneIdByModuleName: (moduleName: string, callback: Callback) => void;
23
- currentRoute: (callback: Callback) => void;
24
- routeGraph: (callback: Callback) => void;
25
- }
26
-
27
- const NavigationModule: NavigationModule = NativeModules.NavigationModule;
1
+ import type { Route, RouteGraph, RouteConfig, ResultType } from './NativeNavigation';
2
+ import NativeNavigation from './NativeNavigation';
28
3
 
29
4
  function getConstants() {
30
- return NavigationModule.getConstants();
5
+ return NativeNavigation.getConstants();
31
6
  }
32
7
 
33
8
  function startRegisterReactComponent() {
34
- NavigationModule.startRegisterReactComponent();
9
+ NativeNavigation.startRegisterReactComponent();
35
10
  }
36
11
 
37
12
  function endRegisterReactComponent() {
38
- NavigationModule.endRegisterReactComponent();
13
+ NativeNavigation.endRegisterReactComponent();
39
14
  }
40
15
 
41
- function registerReactComponent(appKey: string, options: object) {
42
- NavigationModule.registerReactComponent(appKey, options);
16
+ function registerReactComponent(appKey: string, options: RouteConfig) {
17
+ NativeNavigation.registerReactComponent(appKey, options);
43
18
  }
44
19
 
45
20
  function signalFirstRenderComplete(sceneId: string) {
46
- NavigationModule.signalFirstRenderComplete(sceneId);
21
+ NativeNavigation.signalFirstRenderComplete(sceneId);
47
22
  }
48
23
 
49
- function setResult(sceneId: string, resultCode: number, data: object | null) {
50
- NavigationModule.setResult(sceneId, resultCode, data);
24
+ function setResult<T extends ResultType>(sceneId: string, resultCode: number, data: T) {
25
+ NativeNavigation.setResult(sceneId, resultCode, data as object);
51
26
  }
52
27
 
53
28
  function setRoot(layout: object, sticky: boolean) {
54
29
  return new Promise<boolean>(resolve => {
55
- NavigationModule.setRoot(layout, sticky, (_, success) => {
30
+ NativeNavigation.setRoot(layout, sticky, (_, success) => {
56
31
  resolve(success);
57
32
  });
58
33
  });
@@ -60,7 +35,7 @@ function setRoot(layout: object, sticky: boolean) {
60
35
 
61
36
  function dispatch(sceneId: string, action: string, params: object) {
62
37
  return new Promise<boolean>(resolve => {
63
- NavigationModule.dispatch(sceneId, action, params, (_, result) => {
38
+ NativeNavigation.dispatch(sceneId, action, params, (_, result) => {
64
39
  resolve(result);
65
40
  });
66
41
  });
@@ -68,15 +43,15 @@ function dispatch(sceneId: string, action: string, params: object) {
68
43
 
69
44
  function currentTab(sceneId: string) {
70
45
  return new Promise<number>(resolve => {
71
- NavigationModule.currentTab(sceneId, (_, result) => {
72
- resolve(result);
46
+ NativeNavigation.currentTab(sceneId, (_, index) => {
47
+ resolve(index);
73
48
  });
74
49
  });
75
50
  }
76
51
 
77
52
  function isStackRoot(sceneId: string) {
78
53
  return new Promise<boolean>(resolve => {
79
- NavigationModule.isStackRoot(sceneId, (_, result) => {
54
+ NativeNavigation.isStackRoot(sceneId, (_, result) => {
80
55
  resolve(result);
81
56
  });
82
57
  });
@@ -84,24 +59,24 @@ function isStackRoot(sceneId: string) {
84
59
 
85
60
  function findSceneIdByModuleName(moduleName: string) {
86
61
  return new Promise<string | null>(resolve => {
87
- NavigationModule.findSceneIdByModuleName(moduleName, (_, result) => {
88
- resolve(result);
62
+ NativeNavigation.findSceneIdByModuleName(moduleName, (_, sceneId) => {
63
+ resolve(sceneId);
89
64
  });
90
65
  });
91
66
  }
92
67
 
93
68
  function currentRoute() {
94
69
  return new Promise<Route>(resolve => {
95
- NavigationModule.currentRoute((_, result) => {
96
- resolve(result);
70
+ NativeNavigation.currentRoute((_, route) => {
71
+ resolve(route);
97
72
  });
98
73
  });
99
74
  }
100
75
 
101
76
  function routeGraph() {
102
77
  return new Promise<RouteGraph[]>(resolve => {
103
- NavigationModule.routeGraph((_, result) => {
104
- resolve(result);
78
+ NativeNavigation.routeGraph((_, graph) => {
79
+ resolve(graph);
105
80
  });
106
81
  });
107
82
  }
package/src/Navigator.ts CHANGED
@@ -1,14 +1,14 @@
1
- import {createContext} from 'react';
1
+ import { createContext } from 'react';
2
2
 
3
3
  import store from './store';
4
- import type {Visibility, Layout, BuildInLayout} from './Route';
5
- import type {NavigationItem} from './Options';
6
- import Navigation, {ResultType, RESULT_BLOCK} from './Navigation';
4
+ import type { Visibility, Layout, BuildInLayout } from './Route';
5
+ import type { NavigationItem } from './Options';
6
+ import Navigation, { ResultType, RESULT_BLOCK } from './Navigation';
7
7
 
8
8
  export const NavigationContext = createContext<any>(null);
9
9
 
10
10
  interface NavigationState {
11
- params: {readonly [index: string]: any};
11
+ params: { readonly [index: string]: any };
12
12
  }
13
13
 
14
14
  interface PropsType {
@@ -66,8 +66,8 @@ export class Navigator implements Navigator {
66
66
  params: {},
67
67
  };
68
68
 
69
- setParams = (params: {[index: string]: any}) => {
70
- this.state.params = {...this.state.params, ...params};
69
+ setParams = (params: { [index: string]: any }) => {
70
+ this.state.params = { ...this.state.params, ...params };
71
71
  };
72
72
 
73
73
  push = async <T extends ResultType, P extends PropsType = {}>(
@@ -99,7 +99,7 @@ export class Navigator implements Navigator {
99
99
  return Navigation.result<T>(this.sceneId, 0);
100
100
  };
101
101
 
102
- pop = () => Navigation.dispatch(this.sceneId, 'pop', {from: this.moduleName});
102
+ pop = () => Navigation.dispatch(this.sceneId, 'pop', { from: this.moduleName });
103
103
 
104
104
  popTo = (moduleName: string, inclusive: boolean = false) =>
105
105
  Navigation.dispatch(this.sceneId, 'popTo', {
@@ -109,7 +109,7 @@ export class Navigator implements Navigator {
109
109
  to: moduleName,
110
110
  });
111
111
 
112
- popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot', {from: this.moduleName});
112
+ popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot', { from: this.moduleName });
113
113
 
114
114
  redirectTo = <P extends PropsType>(
115
115
  moduleName: string,
@@ -163,7 +163,7 @@ export class Navigator implements Navigator {
163
163
  return Navigation.result<T>(this.sceneId, requestCode);
164
164
  };
165
165
 
166
- dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss', {from: this.moduleName});
166
+ dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss', { from: this.moduleName });
167
167
 
168
168
  showModal = async <T extends ResultType, P extends PropsType = {}>(
169
169
  moduleName: string,
@@ -204,7 +204,7 @@ export class Navigator implements Navigator {
204
204
  return Navigation.result<T>(this.sceneId, requestCode);
205
205
  };
206
206
 
207
- hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal', {from: this.moduleName});
207
+ hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal', { from: this.moduleName });
208
208
 
209
209
  setResult = <T extends ResultType>(resultCode: number, data: T = null as any): void =>
210
210
  Navigation.setResult(this.sceneId, resultCode, data);
@@ -223,9 +223,9 @@ export class Navigator implements Navigator {
223
223
  from: this.moduleName,
224
224
  });
225
225
 
226
- openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu', {from: this.moduleName});
226
+ openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu', { from: this.moduleName });
227
227
 
228
- closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', {from: this.moduleName});
228
+ closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', { from: this.moduleName });
229
229
 
230
230
  isStackRoot = () => Navigation.isStackRoot(this.sceneId);
231
231
  }
package/src/Options.ts CHANGED
@@ -1,5 +1,4 @@
1
- import type {Insets} from 'react-native';
2
- import type {Navigator} from './Navigator';
1
+ import type { Navigator } from './Navigator';
3
2
 
4
3
  export type Color = string;
5
4
  export type ImageSource = {
@@ -59,14 +58,12 @@ export interface NavigationItem extends NavigationOption {
59
58
  rightBarButtonItem?: BarButtonItem;
60
59
  leftBarButtonItems?: BarButtonItem[];
61
60
  rightBarButtonItems?: BarButtonItem[];
62
- backItemIOS?: BackItem;
63
61
  tabItem?: TabItem;
64
62
  }
65
63
 
66
64
  export interface BarButtonItem {
67
65
  title?: string;
68
66
  icon?: ImageSource;
69
- insetsIOS?: Insets;
70
67
  action?: (navigator: Navigator) => void;
71
68
  enabled?: boolean;
72
69
  tintColor?: Color;
@@ -122,16 +119,19 @@ export interface DefaultOptions {
122
119
  fitsOpaqueNavigationBarAndroid?: boolean; // 适配不透明的导航栏边衬区,默认为 true
123
120
  displayCutoutWhenLandscapeAndroid?: boolean; // 横屏时,是否将界面延伸至刘海区域,默认 true
124
121
 
125
- tabBarColor?: Color; // 底部 TabBar 背景颜色,请勿使用带透明度的颜色。
126
- tabBarShadowImage?: ShadowImage; // 底部 TabBar 阴影图片。对于 iOS, 只有同时设置了 tabBarColor 才会生效
127
- tabBarItemColor?: Color; // 底部 TabBarItem icon 选中颜色
128
- tabBarUnselectedItemColor?: Color; // 底部 TabBarItem icon 未选中颜色,默认为 #BDBDBD
122
+ tabBarBackgroundColor?: Color; // 底部 TabBar 背景颜色,请勿使用带透明度的颜色。
123
+ tabBarShadowImage?: ShadowImage; // 底部 TabBar 阴影图片。对于 iOS, 只有同时设置了 tabBarBackgroundColor 才会生效
124
+ tabBarItemSelectedColor?: Color; // 底部 TabBarItem icon 选中颜色
125
+ tabBarItemNormalColor?: Color; // 底部 TabBarItem icon 未选中颜色,默认为 #666666
129
126
  tabBarBadgeColor?: Color; // Tab badge 颜色
130
127
  }
131
128
 
132
129
  export type TabBarStyle = Pick<
133
130
  DefaultOptions,
134
- 'tabBarColor' | 'tabBarShadowImage' | 'tabBarItemColor' | 'tabBarUnselectedItemColor'
131
+ | 'tabBarBackgroundColor'
132
+ | 'tabBarShadowImage'
133
+ | 'tabBarItemSelectedColor'
134
+ | 'tabBarItemNormalColor'
135
135
  >;
136
136
 
137
137
  export interface TabItemInfo {
package/src/Route.ts CHANGED
@@ -20,8 +20,6 @@ export interface Tabs extends Layout {
20
20
  children: Array<BuildInLayout | Layout>;
21
21
  options?: {
22
22
  selectedIndex?: number;
23
- tabBarModuleName?: string;
24
- sizeIndeterminate?: boolean;
25
23
  };
26
24
  };
27
25
  }
@@ -1,4 +1,4 @@
1
- import Event from '../Event';
1
+ import NativeEvent from '../NativeEvent';
2
2
 
3
3
  type BarButtonClickEventListener = (sceneId: string, value: Function) => void;
4
4
 
@@ -7,10 +7,7 @@ export default class BarButtonEventHandler {
7
7
  private keyPairs: Record<string, string[]> = {};
8
8
  private actionIdGenerator = 0;
9
9
 
10
- bindBarButtonClickEvent(
11
- sceneId: string,
12
- item: object | null | undefined,
13
- ): object | null {
10
+ bindBarButtonClickEvent(sceneId: string, item: object | null | undefined): object | null {
14
11
  if (item === null || item === undefined) {
15
12
  return null;
16
13
  }
@@ -21,8 +18,7 @@ export default class BarButtonEventHandler {
21
18
  return value;
22
19
  }
23
20
 
24
- const actionKey =
25
- 'ON_BAR_BUTTON_ITEM_CLICK_' + this.actionIdGenerator++;
21
+ const actionKey = 'ON_BAR_BUTTON_ITEM_CLICK_' + this.actionIdGenerator++;
26
22
 
27
23
  if (!this.keyPairs[sceneId]) {
28
24
  this.keyPairs[sceneId] = [];
@@ -44,7 +40,7 @@ export default class BarButtonEventHandler {
44
40
  }
45
41
 
46
42
  setBarButtonClickEventListener(handler: BarButtonClickEventListener) {
47
- Event.listenBarButtonItemClick((sceneId: string, action: string) => {
43
+ NativeEvent.onBarButtonItemClick(({ sceneId, action }) => {
48
44
  const listeners = this.actions;
49
45
  if (listeners[action]) {
50
46
  handler(sceneId, listeners[action]);
@@ -1,6 +1,6 @@
1
1
  import NavigationModule from '../NavigationModule';
2
- import {NavigationItem} from '../Options';
3
- import {BuildInLayout, Layout} from '../Route';
2
+ import { NavigationItem } from '../Options';
3
+ import { BuildInLayout, Layout } from '../Route';
4
4
 
5
5
  export interface DispatchParams {
6
6
  animated?: boolean;
@@ -30,12 +30,8 @@ export type NavigationInterceptor = (
30
30
  export default class DispatchCommandHandler {
31
31
  private interceptor: NavigationInterceptor = () => false;
32
32
 
33
- async dispatch(
34
- sceneId: string,
35
- action: string,
36
- params: DispatchParams,
37
- ): Promise<boolean> {
38
- const {from, to, props} = params;
33
+ async dispatch(sceneId: string, action: string, params: DispatchParams): Promise<boolean> {
34
+ const { from, to, props } = params;
39
35
  const intercepted = await this.intercept(action, {
40
36
  sceneId,
41
37
  from,
@@ -1,6 +1,6 @@
1
- import Event from '../Event';
2
1
  import NavigationModule from '../NavigationModule';
3
- import {BuildInLayout, Layout} from '../Route';
2
+ import { BuildInLayout, Layout } from '../Route';
3
+ import NativeEvent from '../NativeEvent';
4
4
 
5
5
  export default class LayoutCommandHandler {
6
6
  private willSetRoot = () => {};
@@ -9,11 +9,10 @@ export default class LayoutCommandHandler {
9
9
  constructor() {}
10
10
 
11
11
  handleRootLayoutChange() {
12
- Event.listenWillSetRoot(() => {
12
+ NativeEvent.willSetRoot(() => {
13
13
  this.willSetRoot();
14
14
  });
15
-
16
- Event.listenDidSetRoot(() => {
15
+ NativeEvent.didSetRoot(() => {
17
16
  this.didSetRoot();
18
17
  });
19
18
  }
@@ -1,38 +1,25 @@
1
- import Event from '../Event';
1
+ import NativeEvent from '../NativeEvent';
2
2
 
3
3
  interface IndexType {
4
4
  [index: string]: any;
5
5
  }
6
6
 
7
7
  export type ResultType = IndexType | null;
8
- export type ResultEventListener<T extends ResultType> = (
9
- resultCode: number,
10
- data: T,
11
- ) => void;
8
+ export type ResultEventListener<T extends ResultType> = (resultCode: number, data: T) => void;
12
9
 
13
10
  export default class ResultEventHandler {
14
- private listenerRecords: Record<
15
- string,
16
- Record<number, Array<ResultEventListener<any>>>
17
- > = {};
11
+ private listenerRecords: Record<string, Record<number, Array<ResultEventListener<any>>>> = {};
18
12
 
19
13
  constructor() {}
20
14
 
21
15
  handleComponentResult() {
22
- Event.listenComponentResult(
23
- (
24
- sceneId: string,
25
- requestCode: number,
26
- resultCode: number,
27
- data: any,
28
- ) => {
29
- const listeners = this.listenerRecords[sceneId]?.[requestCode];
30
- if (listeners) {
31
- delete this.listenerRecords[sceneId][requestCode];
32
- listeners.forEach(l => l(resultCode, data));
33
- }
34
- },
35
- );
16
+ NativeEvent.onResult(({ sceneId, requestCode, resultCode, resultData }) => {
17
+ const listeners = this.listenerRecords[sceneId]?.[requestCode];
18
+ if (listeners) {
19
+ delete this.listenerRecords[sceneId][requestCode];
20
+ listeners.forEach(l => l(resultCode, resultData));
21
+ }
22
+ });
36
23
  }
37
24
 
38
25
  private addResultEventListener(
@@ -63,10 +50,7 @@ export default class ResultEventHandler {
63
50
  }
64
51
  }
65
52
 
66
- waitResult<T extends ResultType>(
67
- sceneId: string,
68
- requestCode: number,
69
- ): Promise<[number, T]> {
53
+ waitResult<T extends ResultType>(sceneId: string, requestCode: number): Promise<[number, T]> {
70
54
  return new Promise<[number, T]>(resolve => {
71
55
  const listener = (resultCode: number, data: T) => {
72
56
  this.removeResultEventListener(sceneId, requestCode);
@@ -1,11 +1,8 @@
1
- import {Visibility} from '../Route';
2
- import Event from '../Event';
1
+ import { Visibility } from '../Route';
2
+ import NativeEvent from '../NativeEvent';
3
3
 
4
4
  export type VisibilityEventListener = (visibility: Visibility) => void;
5
- export type GlobalVisibilityEventListener = (
6
- sceneId: string,
7
- visibility: Visibility,
8
- ) => void;
5
+ export type GlobalVisibilityEventListener = (sceneId: string, visibility: Visibility) => void;
9
6
 
10
7
  export default class VisibilityEventHandler {
11
8
  private listeners: Record<string, VisibilityEventListener[]> = {};
@@ -14,48 +11,42 @@ export default class VisibilityEventHandler {
14
11
  constructor() {}
15
12
 
16
13
  handleComponentVisibility() {
17
- Event.listenComponentVisibility(
18
- (sceneId: string, visibility: Visibility) => {
19
- const listeners = this.listeners[sceneId];
20
- if (listeners) {
21
- listeners.forEach(listener => listener(visibility));
22
- }
23
-
24
- this.globalListeners.forEach(listener =>
25
- listener(sceneId, visibility),
26
- );
27
- },
28
- );
14
+ NativeEvent.onComponentAppear(({ sceneId }) => {
15
+ const listeners = this.listeners[sceneId];
16
+ if (listeners) {
17
+ listeners.forEach(listener => listener('visible'));
18
+ }
19
+
20
+ this.globalListeners.forEach(listener => listener(sceneId, 'visible'));
21
+ });
22
+ NativeEvent.onComponentDisappear(({ sceneId }) => {
23
+ const listeners = this.listeners[sceneId];
24
+ if (listeners) {
25
+ listeners.forEach(listener => listener('invisible'));
26
+ }
27
+
28
+ this.globalListeners.forEach(listener => listener(sceneId, 'invisible'));
29
+ });
29
30
  }
30
31
 
31
32
  addGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener) {
32
33
  this.globalListeners.push(listener);
33
34
  }
34
35
 
35
- removeGlobalVisibilityEventListener(
36
- listener: GlobalVisibilityEventListener,
37
- ) {
36
+ removeGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener) {
38
37
  this.globalListeners = this.globalListeners.filter(l => l !== listener);
39
38
  }
40
39
 
41
- addVisibilityEventListener(
42
- sceneId: string,
43
- listener: VisibilityEventListener,
44
- ) {
40
+ addVisibilityEventListener(sceneId: string, listener: VisibilityEventListener) {
45
41
  if (!this.listeners[sceneId]) {
46
42
  this.listeners[sceneId] = [];
47
43
  }
48
44
  this.listeners[sceneId].push(listener);
49
45
  }
50
46
 
51
- removeVisibilityEventListener(
52
- sceneId: string,
53
- listener: VisibilityEventListener,
54
- ) {
47
+ removeVisibilityEventListener(sceneId: string, listener: VisibilityEventListener) {
55
48
  if (this.listeners[sceneId]) {
56
- this.listeners[sceneId] = this.listeners[sceneId].filter(
57
- l => l !== listener,
58
- );
49
+ this.listeners[sceneId] = this.listeners[sceneId].filter(l => l !== listener);
59
50
  }
60
51
  }
61
52
  }
package/src/hooks.ts CHANGED
@@ -1,6 +1,6 @@
1
- import React, {useContext, useEffect, useState} from 'react';
1
+ import React, { useContext, useEffect, useState } from 'react';
2
2
  import Navigation from './Navigation';
3
- import {Navigator, NavigationContext} from './Navigator';
3
+ import { Navigator, NavigationContext } from './Navigator';
4
4
 
5
5
  export function useNavigator(): Navigator {
6
6
  return useContext<Navigator>(NavigationContext);
package/src/index.ts CHANGED
@@ -1,12 +1,11 @@
1
- import {withNavigation} from './NavigationComponentWrap';
1
+ import { withNavigation } from './NavigationComponentWrap';
2
2
  import navigation from './Navigation';
3
3
  navigation.setNavigationComponentWrap(withNavigation);
4
4
  const Navigation = navigation;
5
5
  export default Navigation;
6
- export {RESULT_OK, RESULT_CANCEL, RESULT_BLOCK} from './Navigation';
7
- export {statusBarHeight, toolbarHeight, topBarHeight} from './GardenModule';
8
- export {withNavigationItem} from './NavigationComponentWrap';
9
- export type {NavigationProps} from './NavigationComponentWrap';
6
+ export { RESULT_OK, RESULT_CANCEL, RESULT_BLOCK } from './Navigation';
7
+ export { withNavigationItem } from './NavigationComponentWrap';
8
+ export type { NavigationProps } from './NavigationComponentWrap';
10
9
 
11
10
  export * from './Navigator';
12
11
  export * from './hooks';
@@ -1,5 +1,5 @@
1
- import {ScreenGraph, isTargetLocateIn} from './screen';
2
- import {LayoutMode, RouteGraph, RouteHandler, RouteInfo} from '../Route';
1
+ import { ScreenGraph, isTargetLocateIn } from './screen';
2
+ import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route';
3
3
  import Navigation from '../Navigation';
4
4
 
5
5
  export interface DrawerGraph extends RouteGraph {
@@ -19,16 +19,16 @@ export class DrawerRouteHandler implements RouteHandler {
19
19
  throw new Error(`${graph} is Not a DrawerGraph`);
20
20
  }
21
21
 
22
- const {children} = graph;
22
+ const { children } = graph;
23
23
 
24
- const {moduleName, sceneId} = children[1];
24
+ const { moduleName, sceneId } = children[1];
25
25
  if (moduleName === target.moduleName) {
26
26
  await Navigation.dispatch(sceneId, 'openMenu');
27
27
  return [true, null];
28
28
  }
29
29
 
30
30
  if (isTargetLocateIn(children[0], target)) {
31
- Navigation.dispatch(sceneId, 'closeMenu', {from: moduleName});
31
+ Navigation.dispatch(sceneId, 'closeMenu', { from: moduleName });
32
32
  return [true, children[0]];
33
33
  }
34
34