hybrid-navigation 2.18.3 → 2.18.5

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 (78) hide show
  1. package/LICENSE +1 -1
  2. package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +4 -54
  3. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +0 -3
  4. package/{lib → dist}/Navigation.js +3 -2
  5. package/{lib → dist}/NavigationComponentWrap.js +6 -5
  6. package/{lib → dist}/Navigator.d.ts +0 -1
  7. package/{lib → dist}/Navigator.js +15 -4
  8. package/{lib → dist}/hooks.js +2 -1
  9. package/{lib → dist}/router/index.js +6 -2
  10. package/{lib → dist}/router/stack.js +1 -1
  11. package/ios/HybridNavigation/HBDUtils.h +2 -0
  12. package/ios/HybridNavigation/HBDUtils.m +12 -3
  13. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +2 -6
  14. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +11 -12
  15. package/ios/HybridNavigation/ViewController/HBDDrawerController.m +1 -1
  16. package/ios/HybridNavigation/ViewController/HBDNavigationController.m +1 -1
  17. package/ios/HybridNavigation/ViewController/HBDViewController.m +1 -1
  18. package/package.json +47 -78
  19. package/src/DeepLink.ts +52 -52
  20. package/src/Event.ts +88 -83
  21. package/src/GardenModule.ts +30 -30
  22. package/src/Navigation.ts +293 -281
  23. package/src/NavigationComponentWrap.tsx +52 -47
  24. package/src/NavigationModule.ts +77 -77
  25. package/src/Navigator.ts +212 -201
  26. package/src/Options.ts +120 -112
  27. package/src/Route.ts +59 -59
  28. package/src/handler/BarButtonEventHandler.ts +50 -46
  29. package/src/handler/DispatchCommandHandler.ts +56 -52
  30. package/src/handler/LayoutCommandHandler.ts +21 -21
  31. package/src/handler/ResultEventHandler.ts +63 -49
  32. package/src/handler/VisibilityEventHandler.ts +57 -40
  33. package/src/hooks.ts +23 -21
  34. package/src/index.ts +15 -15
  35. package/src/router/drawer.ts +24 -24
  36. package/src/router/index.ts +206 -198
  37. package/src/router/screen.ts +28 -28
  38. package/src/router/stack.ts +76 -76
  39. package/src/router/tabs.ts +28 -28
  40. package/src/store.ts +9 -9
  41. package/README.md +0 -79
  42. /package/{lib → dist}/DeepLink.d.ts +0 -0
  43. /package/{lib → dist}/DeepLink.js +0 -0
  44. /package/{lib → dist}/Event.d.ts +0 -0
  45. /package/{lib → dist}/Event.js +0 -0
  46. /package/{lib → dist}/GardenModule.d.ts +0 -0
  47. /package/{lib → dist}/GardenModule.js +0 -0
  48. /package/{lib → dist}/Navigation.d.ts +0 -0
  49. /package/{lib → dist}/NavigationComponentWrap.d.ts +0 -0
  50. /package/{lib → dist}/NavigationModule.d.ts +0 -0
  51. /package/{lib → dist}/NavigationModule.js +0 -0
  52. /package/{lib → dist}/Options.d.ts +0 -0
  53. /package/{lib → dist}/Options.js +0 -0
  54. /package/{lib → dist}/Route.d.ts +0 -0
  55. /package/{lib → dist}/Route.js +0 -0
  56. /package/{lib → dist}/handler/BarButtonEventHandler.d.ts +0 -0
  57. /package/{lib → dist}/handler/BarButtonEventHandler.js +0 -0
  58. /package/{lib → dist}/handler/DispatchCommandHandler.d.ts +0 -0
  59. /package/{lib → dist}/handler/DispatchCommandHandler.js +0 -0
  60. /package/{lib → dist}/handler/LayoutCommandHandler.d.ts +0 -0
  61. /package/{lib → dist}/handler/LayoutCommandHandler.js +0 -0
  62. /package/{lib → dist}/handler/ResultEventHandler.d.ts +0 -0
  63. /package/{lib → dist}/handler/ResultEventHandler.js +0 -0
  64. /package/{lib → dist}/handler/VisibilityEventHandler.d.ts +0 -0
  65. /package/{lib → dist}/handler/VisibilityEventHandler.js +0 -0
  66. /package/{lib → dist}/hooks.d.ts +0 -0
  67. /package/{lib → dist}/index.d.ts +0 -0
  68. /package/{lib → dist}/index.js +0 -0
  69. /package/{lib → dist}/router/drawer.d.ts +0 -0
  70. /package/{lib → dist}/router/drawer.js +0 -0
  71. /package/{lib → dist}/router/index.d.ts +0 -0
  72. /package/{lib → dist}/router/screen.d.ts +0 -0
  73. /package/{lib → dist}/router/screen.js +0 -0
  74. /package/{lib → dist}/router/stack.d.ts +0 -0
  75. /package/{lib → dist}/router/tabs.d.ts +0 -0
  76. /package/{lib → dist}/router/tabs.js +0 -0
  77. /package/{lib → dist}/store.d.ts +0 -0
  78. /package/{lib → dist}/store.js +0 -0
package/src/Navigator.ts CHANGED
@@ -1,219 +1,230 @@
1
- import { createContext } from 'react'
1
+ import {createContext} from 'react';
2
2
 
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'
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';
7
7
 
8
- export const NavigationContext = createContext<any>(null)
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 {
15
- [index: string]: any
15
+ [index: string]: any;
16
16
  }
17
17
 
18
- let tagGenerator = 0
18
+ let tagGenerator = 0;
19
19
 
20
20
  Navigation.addGlobalVisibilityEventListener((sceneId: string, visibility: Visibility) => {
21
- const navigator = store.getNavigator(sceneId)
22
- if (navigator) {
23
- navigator.visibility = visibility
24
- }
25
- })
21
+ const navigator = store.getNavigator(sceneId);
22
+ if (navigator) {
23
+ navigator.visibility = visibility;
24
+ }
25
+ });
26
26
 
27
27
  Navigation.setBarButtonClickEventListener((sceneId, value) => {
28
- const navigator = Navigator.of(sceneId)
29
- value(navigator)
30
- })
28
+ const navigator = Navigator.of(sceneId);
29
+ value(navigator);
30
+ });
31
31
 
32
32
  export interface Navigator {}
33
33
 
34
34
  export class Navigator implements Navigator {
35
- static of(sceneId: string) {
36
- let navigator = store.getNavigator(sceneId)
37
- if (!navigator) {
38
- navigator = new Navigator(sceneId)
39
- store.addNavigator(sceneId, navigator)
40
- }
41
- return navigator
42
- }
43
-
44
- static unmount = (sceneId: string) => {
45
- store.removeNavigator(sceneId)
46
- Navigation.unmount(sceneId)
47
- }
48
-
49
- static async find(moduleName: string) {
50
- const sceneId = await Navigation.findSceneIdByModuleName(moduleName)
51
- if (sceneId) {
52
- return Navigator.of(sceneId)
53
- }
54
- }
55
-
56
- static async current(): Promise<Navigator> {
57
- const route = await Navigation.currentRoute()
58
- return Navigator.of(route.sceneId)
59
- }
60
-
61
- constructor(public sceneId: string, public moduleName?: string) {}
62
-
63
- visibility: Visibility = 'pending'
64
-
65
- readonly state: NavigationState = {
66
- params: {},
67
- }
68
-
69
- setParams = (params: { [index: string]: any }) => {
70
- this.state.params = { ...this.state.params, ...params }
71
- }
72
-
73
- push = async <T extends ResultType, P extends PropsType = {}>(
74
- moduleName: string,
75
- props: P = {} as P,
76
- options: NavigationItem = {},
77
- ) => {
78
- const success = await Navigation.dispatch(this.sceneId, 'push', {
79
- moduleName,
80
- from: this.moduleName,
81
- to: moduleName,
82
- props,
83
- options,
84
- })
85
- if (!success) {
86
- return [RESULT_BLOCK, null] as [number, T]
87
- }
88
- return Navigation.result<T>(this.sceneId, 0)
89
- }
90
-
91
- pushLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
92
- const success = await Navigation.dispatch(this.sceneId, 'pushLayout', {
93
- from: this.moduleName,
94
- layout,
95
- })
96
- if (!success) {
97
- return [RESULT_BLOCK, null] as [number, T]
98
- }
99
- return Navigation.result<T>(this.sceneId, 0)
100
- }
101
-
102
- pop = () => Navigation.dispatch(this.sceneId, 'pop', { from: this.moduleName })
103
-
104
- popTo = (moduleName: string, inclusive: boolean = false) =>
105
- Navigation.dispatch(this.sceneId, 'popTo', { moduleName, inclusive, from: this.moduleName })
106
-
107
- popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot', { from: this.moduleName })
108
-
109
- redirectTo = <P extends PropsType>(
110
- moduleName: string,
111
- props: P = {} as P,
112
- options: NavigationItem = {},
113
- ) =>
114
- Navigation.dispatch(this.sceneId, 'redirectTo', {
115
- moduleName,
116
- from: this.moduleName,
117
- to: moduleName,
118
- props,
119
- options,
120
- })
121
-
122
- present = async <T extends ResultType, P extends PropsType = {}>(
123
- moduleName: string,
124
- props: P = {} as P,
125
- options: NavigationItem = {},
126
- ) => {
127
- const requestCode = --tagGenerator
128
- const success = await Navigation.dispatch(this.sceneId, 'present', {
129
- moduleName,
130
- from: this.moduleName,
131
- to: moduleName,
132
- props,
133
- options,
134
- requestCode,
135
- })
136
- if (!success) {
137
- console.warn(
138
- `present from:${this.moduleName} to:${moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`,
139
- )
140
- return [RESULT_BLOCK, null] as [number, T]
141
- }
142
- return Navigation.result<T>(this.sceneId, requestCode)
143
- }
144
-
145
- presentLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
146
- const requestCode = --tagGenerator
147
- const success = await Navigation.dispatch(this.sceneId, 'presentLayout', {
148
- layout,
149
- from: this.moduleName,
150
- requestCode,
151
- })
152
- if (!success) {
153
- console.warn(
154
- `presentLayout from:${this.moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`,
155
- )
156
- return [RESULT_BLOCK, null] as [number, T]
157
- }
158
- return Navigation.result<T>(this.sceneId, requestCode)
159
- }
160
-
161
- dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss', { from: this.moduleName })
162
-
163
- showModal = async <T extends ResultType, P extends PropsType = {}>(
164
- moduleName: string,
165
- props: P = {} as P,
166
- options: NavigationItem = {},
167
- ) => {
168
- const requestCode = --tagGenerator
169
- const success = await Navigation.dispatch(this.sceneId, 'showModal', {
170
- moduleName,
171
- from: this.moduleName,
172
- to: moduleName,
173
- props,
174
- options,
175
- requestCode,
176
- })
177
- if (!success) {
178
- console.warn(
179
- `showModal from:${this.moduleName} to:${moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`,
180
- )
181
- return [RESULT_BLOCK, null] as [number, T]
182
- }
183
- return Navigation.result<T>(this.sceneId, requestCode)
184
- }
185
-
186
- showModalLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
187
- const requestCode = --tagGenerator
188
- const success = await Navigation.dispatch(this.sceneId, 'showModalLayout', {
189
- from: this.moduleName,
190
- layout,
191
- requestCode,
192
- })
193
- if (!success) {
194
- console.warn(
195
- `showModal from:${this.moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`,
196
- )
197
- return [RESULT_BLOCK, null] as [number, T]
198
- }
199
- return Navigation.result<T>(this.sceneId, requestCode)
200
- }
201
-
202
- hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal', { from: this.moduleName })
203
-
204
- setResult = <T extends ResultType>(resultCode: number, data: T = null as any): void =>
205
- Navigation.setResult(this.sceneId, resultCode, data)
206
-
207
- switchTab = async (index: number, popToRoot: boolean = false) => {
208
- const from = await Navigation.currentTab(this.sceneId)
209
- return Navigation.dispatch(this.sceneId, 'switchTab', { from, to: index, popToRoot })
210
- }
211
-
212
- toggleMenu = () => Navigation.dispatch(this.sceneId, 'toggleMenu', { from: this.moduleName })
213
-
214
- openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu', { from: this.moduleName })
215
-
216
- closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', { from: this.moduleName })
217
-
218
- isStackRoot = () => Navigation.isStackRoot(this.sceneId)
35
+ static of(sceneId: string) {
36
+ let navigator = store.getNavigator(sceneId);
37
+ if (!navigator) {
38
+ navigator = new Navigator(sceneId);
39
+ store.addNavigator(sceneId, navigator);
40
+ }
41
+ return navigator;
42
+ }
43
+
44
+ static unmount = (sceneId: string) => {
45
+ store.removeNavigator(sceneId);
46
+ Navigation.unmount(sceneId);
47
+ };
48
+
49
+ static async find(moduleName: string) {
50
+ const sceneId = await Navigation.findSceneIdByModuleName(moduleName);
51
+ if (sceneId) {
52
+ return Navigator.of(sceneId);
53
+ }
54
+ }
55
+
56
+ static async current(): Promise<Navigator> {
57
+ const route = await Navigation.currentRoute();
58
+ return Navigator.of(route.sceneId);
59
+ }
60
+
61
+ constructor(public sceneId: string, public moduleName?: string) {}
62
+
63
+ visibility: Visibility = 'pending';
64
+
65
+ readonly state: NavigationState = {
66
+ params: {},
67
+ };
68
+
69
+ setParams = (params: {[index: string]: any}) => {
70
+ this.state.params = {...this.state.params, ...params};
71
+ };
72
+
73
+ push = async <T extends ResultType, P extends PropsType = {}>(
74
+ moduleName: string,
75
+ props: P = {} as P,
76
+ options: NavigationItem = {},
77
+ ) => {
78
+ const success = await Navigation.dispatch(this.sceneId, 'push', {
79
+ moduleName,
80
+ from: this.moduleName,
81
+ to: moduleName,
82
+ props,
83
+ options,
84
+ });
85
+ if (!success) {
86
+ return [RESULT_BLOCK, null] as [number, T];
87
+ }
88
+ return Navigation.result<T>(this.sceneId, 0);
89
+ };
90
+
91
+ pushLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
92
+ const success = await Navigation.dispatch(this.sceneId, 'pushLayout', {
93
+ from: this.moduleName,
94
+ layout,
95
+ });
96
+ if (!success) {
97
+ return [RESULT_BLOCK, null] as [number, T];
98
+ }
99
+ return Navigation.result<T>(this.sceneId, 0);
100
+ };
101
+
102
+ pop = () => Navigation.dispatch(this.sceneId, 'pop', {from: this.moduleName});
103
+
104
+ popTo = (moduleName: string, inclusive: boolean = false) =>
105
+ Navigation.dispatch(this.sceneId, 'popTo', {
106
+ moduleName,
107
+ inclusive,
108
+ from: this.moduleName,
109
+ });
110
+
111
+ popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot', {from: this.moduleName});
112
+
113
+ redirectTo = <P extends PropsType>(
114
+ moduleName: string,
115
+ props: P = {} as P,
116
+ options: NavigationItem = {},
117
+ ) =>
118
+ Navigation.dispatch(this.sceneId, 'redirectTo', {
119
+ moduleName,
120
+ from: this.moduleName,
121
+ to: moduleName,
122
+ props,
123
+ options,
124
+ });
125
+
126
+ present = async <T extends ResultType, P extends PropsType = {}>(
127
+ moduleName: string,
128
+ props: P = {} as P,
129
+ options: NavigationItem = {},
130
+ ) => {
131
+ const requestCode = --tagGenerator;
132
+ const success = await Navigation.dispatch(this.sceneId, 'present', {
133
+ moduleName,
134
+ from: this.moduleName,
135
+ to: moduleName,
136
+ props,
137
+ options,
138
+ requestCode,
139
+ });
140
+ if (!success) {
141
+ console.warn(
142
+ `present from:${this.moduleName} to:${moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`,
143
+ );
144
+ return [RESULT_BLOCK, null] as [number, T];
145
+ }
146
+ return Navigation.result<T>(this.sceneId, requestCode);
147
+ };
148
+
149
+ presentLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
150
+ const requestCode = --tagGenerator;
151
+ const success = await Navigation.dispatch(this.sceneId, 'presentLayout', {
152
+ layout,
153
+ from: this.moduleName,
154
+ requestCode,
155
+ });
156
+ if (!success) {
157
+ console.warn(
158
+ `presentLayout from:${this.moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`,
159
+ );
160
+ return [RESULT_BLOCK, null] as [number, T];
161
+ }
162
+ return Navigation.result<T>(this.sceneId, requestCode);
163
+ };
164
+
165
+ dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss', {from: this.moduleName});
166
+
167
+ showModal = async <T extends ResultType, P extends PropsType = {}>(
168
+ moduleName: string,
169
+ props: P = {} as P,
170
+ options: NavigationItem = {},
171
+ ) => {
172
+ const requestCode = --tagGenerator;
173
+ const success = await Navigation.dispatch(this.sceneId, 'showModal', {
174
+ moduleName,
175
+ from: this.moduleName,
176
+ to: moduleName,
177
+ props,
178
+ options,
179
+ requestCode,
180
+ });
181
+ if (!success) {
182
+ console.warn(
183
+ `showModal from:${this.moduleName} to:${moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`,
184
+ );
185
+ return [RESULT_BLOCK, null] as [number, T];
186
+ }
187
+ return Navigation.result<T>(this.sceneId, requestCode);
188
+ };
189
+
190
+ showModalLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
191
+ const requestCode = --tagGenerator;
192
+ const success = await Navigation.dispatch(this.sceneId, 'showModalLayout', {
193
+ from: this.moduleName,
194
+ layout,
195
+ requestCode,
196
+ });
197
+ if (!success) {
198
+ console.warn(
199
+ `showModal from:${this.moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`,
200
+ );
201
+ return [RESULT_BLOCK, null] as [number, T];
202
+ }
203
+ return Navigation.result<T>(this.sceneId, requestCode);
204
+ };
205
+
206
+ hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal', {from: this.moduleName});
207
+
208
+ setResult = <T extends ResultType>(resultCode: number, data: T = null as any): void =>
209
+ Navigation.setResult(this.sceneId, resultCode, data);
210
+
211
+ switchTab = async (index: number, popToRoot: boolean = false) => {
212
+ const from = await Navigation.currentTab(this.sceneId);
213
+ return Navigation.dispatch(this.sceneId, 'switchTab', {
214
+ from,
215
+ to: index,
216
+ popToRoot,
217
+ });
218
+ };
219
+
220
+ toggleMenu = () =>
221
+ Navigation.dispatch(this.sceneId, 'toggleMenu', {
222
+ from: this.moduleName,
223
+ });
224
+
225
+ openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu', {from: this.moduleName});
226
+
227
+ closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', {from: this.moduleName});
228
+
229
+ isStackRoot = () => Navigation.isStackRoot(this.sceneId);
219
230
  }