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

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/ios/HybridNavigation/HBDUtils.h +3 -6
  2. package/ios/HybridNavigation/HBDUtils.m +10 -0
  3. package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +7 -2
  4. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +1 -1
  5. package/ios/HybridNavigation/View/HBDRootView.m +9 -3
  6. package/ios/HybridNavigation/ViewController/HBDNavigationController.m +0 -30
  7. package/ios/HybridNavigation/ViewController/HBDViewController.m +7 -3
  8. package/ios/HybridNavigation/ViewController/UINavigationController+HBD.m +0 -3
  9. package/lib/Event.d.ts +22 -0
  10. package/lib/Event.js +117 -0
  11. package/lib/Garden.d.ts +2 -64
  12. package/lib/Garden.js +9 -47
  13. package/lib/GardenModule.d.ts +20 -0
  14. package/lib/GardenModule.js +3 -0
  15. package/lib/NavigationModule.d.ts +33 -22
  16. package/lib/NavigationModule.js +79 -22
  17. package/lib/Navigator.d.ts +33 -17
  18. package/lib/Navigator.js +106 -170
  19. package/lib/{typing.d.ts → Options.d.ts} +46 -50
  20. package/lib/{typing.js → Options.js} +0 -0
  21. package/lib/ReactRegistry.d.ts +2 -3
  22. package/lib/ReactRegistry.js +8 -28
  23. package/lib/Route.d.ts +74 -0
  24. package/lib/{router/typing.js → Route.js} +0 -0
  25. package/lib/hooks.d.ts +0 -1
  26. package/lib/hooks.js +18 -24
  27. package/lib/index.d.ts +3 -2
  28. package/lib/index.js +4 -2
  29. package/lib/router/drawer.d.ts +1 -1
  30. package/lib/router/index.d.ts +4 -7
  31. package/lib/router/index.js +1 -6
  32. package/lib/router/screen.d.ts +1 -1
  33. package/lib/router/stack.d.ts +1 -1
  34. package/lib/router/tabs.d.ts +1 -1
  35. package/lib/store.d.ts +0 -9
  36. package/lib/store.js +0 -22
  37. package/package.json +1 -1
  38. package/src/Event.ts +188 -0
  39. package/src/Garden.ts +18 -122
  40. package/src/GardenModule.ts +24 -0
  41. package/src/NavigationModule.ts +118 -29
  42. package/src/Navigator.ts +164 -209
  43. package/src/{typing.ts → Options.ts} +51 -57
  44. package/src/ReactRegistry.tsx +17 -40
  45. package/src/Route.ts +88 -0
  46. package/src/hooks.ts +23 -32
  47. package/src/index.ts +5 -2
  48. package/src/router/drawer.ts +1 -1
  49. package/src/router/index.ts +21 -12
  50. package/src/router/screen.ts +1 -1
  51. package/src/router/stack.ts +1 -1
  52. package/src/router/tabs.ts +1 -1
  53. package/src/store.ts +0 -28
  54. package/lib/router/typing.d.ts +0 -37
  55. package/lib/utils.d.ts +0 -9
  56. package/lib/utils.js +0 -50
  57. package/src/router/typing.ts +0 -45
  58. package/src/utils.ts +0 -83
@@ -1,23 +1,80 @@
1
- import { NativeModules, NativeEventEmitter } from 'react-native';
1
+ import { NativeModules } from 'react-native';
2
2
  const NavigationModule = NativeModules.NavigationModule;
3
- const HBDEventEmitter = NativeModules.HBDEventEmitter;
4
- const EventEmitter = new NativeEventEmitter(HBDEventEmitter);
5
- export const EVENT_SWITCH_TAB = HBDEventEmitter.EVENT_SWITCH_TAB;
6
- export const EVENT_NAVIGATION = HBDEventEmitter.EVENT_NAVIGATION;
7
- export const EVENT_WILL_SET_ROOT = HBDEventEmitter.EVENT_WILL_SET_ROOT;
8
- export const EVENT_DID_SET_ROOT = HBDEventEmitter.EVENT_DID_SET_ROOT;
9
- export const ON_COMPONENT_RESULT = HBDEventEmitter.ON_COMPONENT_RESULT;
10
- export const ON_BAR_BUTTON_ITEM_CLICK = HBDEventEmitter.ON_BAR_BUTTON_ITEM_CLICK;
11
- export const ON_COMPONENT_APPEAR = HBDEventEmitter.ON_COMPONENT_APPEAR;
12
- export const ON_COMPONENT_DISAPPEAR = HBDEventEmitter.ON_COMPONENT_DISAPPEAR;
13
- export const KEY_ON = HBDEventEmitter.KEY_ON;
14
- export const KEY_REQUEST_CODE = HBDEventEmitter.KEY_REQUEST_CODE;
15
- export const KEY_RESULT_CODE = HBDEventEmitter.KEY_RESULT_CODE;
16
- export const KEY_RESULT_DATA = HBDEventEmitter.KEY_RESULT_DATA;
17
- export const KEY_SCENE_ID = HBDEventEmitter.KEY_SCENE_ID;
18
- export const KEY_MODULE_NAME = HBDEventEmitter.KEY_MODULE_NAME;
19
- export const KEY_INDEX = HBDEventEmitter.KEY_INDEX;
20
- export const KEY_ACTION = HBDEventEmitter.KEY_ACTION;
21
- export const RESULT_OK = NavigationModule.RESULT_OK;
22
- export const RESULT_CANCEL = NavigationModule.RESULT_CANCEL;
23
- export { EventEmitter, NavigationModule };
3
+ function getConstants() {
4
+ return NavigationModule.getConstants();
5
+ }
6
+ function startRegisterReactComponent() {
7
+ NavigationModule.startRegisterReactComponent();
8
+ }
9
+ function endRegisterReactComponent() {
10
+ NavigationModule.endRegisterReactComponent();
11
+ }
12
+ function registerReactComponent(appKey, options) {
13
+ NavigationModule.registerReactComponent(appKey, options);
14
+ }
15
+ function signalFirstRenderComplete(sceneId) {
16
+ NavigationModule.signalFirstRenderComplete(sceneId);
17
+ }
18
+ function setResult(sceneId, resultCode, data) {
19
+ NavigationModule.setResult(sceneId, resultCode, data);
20
+ }
21
+ function setRoot(layout, sticky, tag) {
22
+ NavigationModule.setRoot(layout, sticky, tag);
23
+ }
24
+ function dispatch(sceneId, action, params) {
25
+ return new Promise(resolve => {
26
+ NavigationModule.dispatch(sceneId, action, params, (_, result) => {
27
+ resolve(result);
28
+ });
29
+ });
30
+ }
31
+ function currentTab(sceneId) {
32
+ return new Promise(resolve => {
33
+ NavigationModule.currentTab(sceneId, (_, result) => {
34
+ resolve(result);
35
+ });
36
+ });
37
+ }
38
+ function isStackRoot(sceneId) {
39
+ return new Promise(resolve => {
40
+ NavigationModule.isStackRoot(sceneId, (_, result) => {
41
+ resolve(result);
42
+ });
43
+ });
44
+ }
45
+ function findSceneIdByModuleName(moduleName) {
46
+ return new Promise(resolve => {
47
+ NavigationModule.findSceneIdByModuleName(moduleName, (_, result) => {
48
+ resolve(result);
49
+ });
50
+ });
51
+ }
52
+ function currentRoute() {
53
+ return new Promise(resolve => {
54
+ NavigationModule.currentRoute((_, result) => {
55
+ resolve(result);
56
+ });
57
+ });
58
+ }
59
+ function routeGraph() {
60
+ return new Promise(resolve => {
61
+ NavigationModule.routeGraph((_, result) => {
62
+ resolve(result);
63
+ });
64
+ });
65
+ }
66
+ export default {
67
+ getConstants,
68
+ startRegisterReactComponent,
69
+ endRegisterReactComponent,
70
+ registerReactComponent,
71
+ signalFirstRenderComplete,
72
+ setResult,
73
+ setRoot,
74
+ dispatch,
75
+ currentTab,
76
+ isStackRoot,
77
+ findSceneIdByModuleName,
78
+ currentRoute,
79
+ routeGraph,
80
+ };
@@ -1,22 +1,38 @@
1
- import { RouteGraph, Route } from './router';
2
- import { Visibility } from './hooks';
3
- import { IndexType, ResultType, NavigationInterceptor, Layout, BuildInLayout, NavigationItem, PropsType } from './typing';
1
+ /// <reference types="react" />
2
+ import { Visibility, Layout, BuildInLayout, Route, RouteGraph } from './Route';
3
+ import { NavigationItem } from './Options';
4
4
  import { Garden } from './Garden';
5
- interface Params {
5
+ export declare const NavigationContext: import("react").Context<any>;
6
+ interface NavigationState {
7
+ params: {
8
+ readonly [index: string]: any;
9
+ };
10
+ }
11
+ interface IndexType {
12
+ [index: string]: any;
13
+ }
14
+ interface PropsType {
15
+ [index: string]: any;
16
+ }
17
+ interface DispatchParams {
6
18
  animated?: boolean;
7
19
  moduleName?: string;
8
20
  layout?: BuildInLayout | Layout;
9
21
  popToRoot?: boolean;
10
22
  requestCode?: number;
11
- props?: IndexType;
23
+ props?: object;
12
24
  options?: NavigationItem;
13
25
  [index: string]: any;
14
26
  }
15
- interface NavigationState {
16
- params: {
17
- readonly [index: string]: any;
18
- };
27
+ interface InterceptParams {
28
+ sceneId: string;
29
+ from?: number | string;
30
+ to?: number | string;
31
+ }
32
+ export interface NavigationInterceptor {
33
+ (action: string, params: InterceptParams): boolean | Promise<boolean>;
19
34
  }
35
+ declare type ResultType = IndexType | null;
20
36
  export declare class Navigator {
21
37
  sceneId: string;
22
38
  moduleName?: string | undefined;
@@ -27,32 +43,32 @@ export declare class Navigator {
27
43
  static routeGraph(): Promise<RouteGraph[]>;
28
44
  static setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<void>;
29
45
  static setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
30
- static dispatch(sceneId: string, action: string, params?: Params): Promise<boolean>;
46
+ static dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<boolean>;
31
47
  static setInterceptor(interceptFn: NavigationInterceptor): void;
32
48
  constructor(sceneId: string, moduleName?: string | undefined);
49
+ private _garden?;
50
+ get garden(): Garden;
33
51
  visibility: Visibility;
34
52
  readonly state: NavigationState;
35
53
  setParams: (params: {
36
54
  [index: string]: any;
37
55
  }) => void;
38
- dispatch: (action: string, params?: Params) => Promise<boolean>;
56
+ dispatch: (action: string, params?: DispatchParams) => Promise<boolean>;
39
57
  result: (resultCode: number, data: ResultType) => void;
40
58
  unmount: () => void;
41
- private _garden?;
42
- get garden(): Garden;
43
59
  private resultListener;
44
60
  private waitResult;
45
- push: <T extends ResultType, P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
61
+ push: <T extends ResultType, P extends PropsType = {}>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
46
62
  pushLayout: <T extends ResultType>(layout: BuildInLayout | Layout) => Promise<[number, T]>;
47
63
  pop: () => Promise<boolean>;
48
64
  popTo: (moduleName: string, inclusive?: boolean) => Promise<boolean>;
49
65
  popToRoot: () => Promise<boolean>;
50
- redirectTo: <P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem) => Promise<boolean>;
66
+ redirectTo: <P extends PropsType>(moduleName: string, props?: P, options?: NavigationItem) => Promise<boolean>;
51
67
  isStackRoot: () => Promise<boolean>;
52
- present: <T extends ResultType, P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
68
+ present: <T extends ResultType, P extends PropsType = {}>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
53
69
  presentLayout: <T extends ResultType>(layout: BuildInLayout | Layout) => Promise<[number, T]>;
54
70
  dismiss: () => Promise<boolean>;
55
- showModal: <T extends ResultType, P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
71
+ showModal: <T extends ResultType, P extends PropsType = {}>(moduleName: string, props?: P, options?: NavigationItem) => Promise<[number, T]>;
56
72
  showModalLayout: <T extends ResultType>(layout: BuildInLayout | Layout) => Promise<[number, T]>;
57
73
  hideModal: () => Promise<boolean>;
58
74
  setResult: <T extends ResultType>(resultCode: number, data?: T) => void;
package/lib/Navigator.js CHANGED
@@ -1,48 +1,56 @@
1
- import { EventEmitter, NavigationModule, EVENT_WILL_SET_ROOT, EVENT_DID_SET_ROOT, EVENT_SWITCH_TAB, KEY_SCENE_ID, KEY_INDEX, RESULT_CANCEL, EVENT_NAVIGATION, KEY_ON, ON_COMPONENT_RESULT, KEY_REQUEST_CODE, KEY_RESULT_CODE, KEY_RESULT_DATA, } from './NavigationModule';
2
- import { bindBarButtonItemClickEvent } from './utils';
1
+ import { createContext } from 'react';
2
+ import NavigationModule from './NavigationModule';
3
+ import Event from './Event';
3
4
  import store from './store';
4
5
  import { Garden } from './Garden';
6
+ const { RESULT_CANCEL } = NavigationModule.getConstants();
7
+ export const NavigationContext = createContext(null);
5
8
  let interceptor;
6
9
  let shouldCallWillSetRootCallback = 0;
7
10
  let willSetRootCallback;
8
11
  let didSetRootCallback;
9
- let tag = 0;
10
- EventEmitter.addListener(EVENT_DID_SET_ROOT, _ => {
11
- didSetRootCallback && didSetRootCallback();
12
- shouldCallWillSetRootCallback = 0;
13
- });
14
- EventEmitter.addListener(EVENT_WILL_SET_ROOT, _ => {
12
+ let tagGenerator = 0;
13
+ Event.listenSetRoot(() => {
15
14
  if (shouldCallWillSetRootCallback === 0 && willSetRootCallback) {
16
15
  willSetRootCallback();
17
16
  }
17
+ }, () => {
18
+ didSetRootCallback && didSetRootCallback();
19
+ shouldCallWillSetRootCallback = 0;
18
20
  });
19
- EventEmitter.addListener(EVENT_SWITCH_TAB, event => {
20
- const index = event[KEY_INDEX];
21
- const [from, to] = index.split('-');
22
- Navigator.dispatch(event[KEY_SCENE_ID], 'switchTab', {
23
- from: Number(from),
24
- to: Number(to),
25
- });
21
+ Event.listenSwitchTab((sceneId, from, to) => {
22
+ Navigator.dispatch(sceneId, 'switchTab', { from, to });
26
23
  });
27
- const resultListeners = new Map();
28
- EventEmitter.addListener(EVENT_NAVIGATION, data => {
29
- if (data[KEY_ON] === ON_COMPONENT_RESULT) {
30
- const requestCode = data[KEY_REQUEST_CODE];
31
- const resultCode = data[KEY_RESULT_CODE];
32
- const resultData = data[KEY_RESULT_DATA];
33
- const sceneId = data[KEY_SCENE_ID];
34
- if (requestCode < 0) {
35
- const listener = resultListeners.get(requestCode);
36
- if (listener) {
37
- resultListeners.delete(requestCode);
38
- listener(resultCode, resultData);
39
- }
40
- }
41
- else {
42
- const navigator = Navigator.of(sceneId);
43
- navigator.result(resultCode, resultData);
24
+ const globalResultListeners = new Map();
25
+ Event.listenComponentResult((sceneId, requestCode, resultCode, data) => {
26
+ if (requestCode < 0) {
27
+ const listener = globalResultListeners.get(requestCode);
28
+ if (listener) {
29
+ globalResultListeners.delete(requestCode);
30
+ listener(resultCode, data);
44
31
  }
45
32
  }
33
+ else {
34
+ const navigator = Navigator.of(sceneId);
35
+ navigator.result(resultCode, data);
36
+ }
37
+ });
38
+ Event.listenComponentVisibility((sceneId) => {
39
+ const navigator = store.getNavigator(sceneId);
40
+ if (navigator) {
41
+ navigator.visibility = 'visible';
42
+ }
43
+ }, (sceneId) => {
44
+ const navigator = store.getNavigator(sceneId);
45
+ if (navigator) {
46
+ navigator.visibility = 'invisible';
47
+ }
48
+ });
49
+ Event.setBarButtonClickHandlerFactory(() => {
50
+ return (sceneId, value) => {
51
+ const navigator = Navigator.of(sceneId);
52
+ value(navigator);
53
+ };
46
54
  });
47
55
  export class Navigator {
48
56
  sceneId;
@@ -56,16 +64,7 @@ export class Navigator {
56
64
  return navigator;
57
65
  }
58
66
  static async find(moduleName) {
59
- const sceneId = await new Promise((resolve, reject) => {
60
- NavigationModule.findSceneIdByModuleName(moduleName, (error, id) => {
61
- if (error) {
62
- reject(error);
63
- }
64
- else {
65
- resolve(id);
66
- }
67
- });
68
- });
67
+ const sceneId = await NavigationModule.findSceneIdByModuleName(moduleName);
69
68
  if (sceneId) {
70
69
  return Navigator.of(sceneId);
71
70
  }
@@ -75,45 +74,21 @@ export class Navigator {
75
74
  return Navigator.of(route.sceneId);
76
75
  }
77
76
  static currentRoute() {
78
- return new Promise((resolve, reject) => {
79
- NavigationModule.currentRoute((error, route) => {
80
- if (error) {
81
- reject(error);
82
- }
83
- else {
84
- resolve(route);
85
- }
86
- });
87
- });
77
+ return NavigationModule.currentRoute();
88
78
  }
89
79
  static routeGraph() {
90
- return new Promise((resolve, reject) => {
91
- NavigationModule.routeGraph((error, result) => {
92
- if (error) {
93
- reject(error);
94
- }
95
- else {
96
- resolve(result);
97
- }
98
- });
99
- });
80
+ return NavigationModule.routeGraph();
100
81
  }
101
82
  static setRoot(layout, sticky = false) {
102
- const pureLayout = bindBarButtonItemClickEvent(layout, {
103
- inLayout: true,
104
- navigatorFactory: (sceneId) => {
105
- return Navigator.of(sceneId);
106
- },
107
- });
108
83
  if (willSetRootCallback) {
109
84
  shouldCallWillSetRootCallback++;
110
85
  willSetRootCallback();
111
86
  }
112
- const flag = --tag;
113
- NavigationModule.setRoot(pureLayout, sticky, flag);
87
+ const flag = --tagGenerator;
88
+ NavigationModule.setRoot(layout, sticky, flag);
114
89
  return new Promise(resolve => {
115
- const subscription = EventEmitter.addListener(EVENT_DID_SET_ROOT, (data) => {
116
- if (data.tag === flag) {
90
+ const subscription = Event.listenSetRoot(() => { }, (tag) => {
91
+ if (tag === flag) {
117
92
  subscription.remove();
118
93
  resolve();
119
94
  }
@@ -141,16 +116,7 @@ export class Navigator {
141
116
  }
142
117
  }
143
118
  if (!intercepted) {
144
- return new Promise((resolve, reject) => {
145
- NavigationModule.dispatch(sceneId, action, params, (error, result) => {
146
- if (error) {
147
- reject(error);
148
- }
149
- else {
150
- resolve(result);
151
- }
152
- });
153
- });
119
+ return NavigationModule.dispatch(sceneId, action, params);
154
120
  }
155
121
  return false;
156
122
  }
@@ -161,6 +127,13 @@ export class Navigator {
161
127
  this.sceneId = sceneId;
162
128
  this.moduleName = moduleName;
163
129
  }
130
+ _garden;
131
+ get garden() {
132
+ if (!this._garden) {
133
+ this._garden = new Garden(this.sceneId);
134
+ }
135
+ return this._garden;
136
+ }
164
137
  visibility = 'pending';
165
138
  state = {
166
139
  params: {},
@@ -182,31 +155,23 @@ export class Navigator {
182
155
  }
183
156
  };
184
157
  unmount = () => {
158
+ Event.removeBarButtonClickEvent(this.sceneId);
159
+ store.removeNavigator(this.sceneId);
185
160
  const codes = [];
186
- for (const [requestCode, listener] of resultListeners) {
161
+ for (const [requestCode, listener] of globalResultListeners) {
187
162
  if (listener.sceneId === this.sceneId) {
188
163
  codes.push(requestCode);
189
164
  listener.cancel();
190
165
  }
191
166
  }
192
- codes.forEach(code => resultListeners.delete(code));
167
+ codes.forEach(code => globalResultListeners.delete(code));
193
168
  if (this.resultListener) {
194
169
  this.resultListener.cancel();
195
170
  this.resultListener = null;
196
171
  }
197
172
  };
198
- _garden;
199
- get garden() {
200
- if (!this._garden) {
201
- this._garden = new Garden(this.sceneId);
202
- }
203
- return this._garden;
204
- }
205
173
  resultListener = null;
206
- waitResult(requestCode, successful) {
207
- if (!successful) {
208
- return Promise.resolve([RESULT_CANCEL, null]);
209
- }
174
+ waitResult(requestCode) {
210
175
  if (this.resultListener) {
211
176
  this.resultListener.cancel();
212
177
  this.resultListener = null;
@@ -220,7 +185,7 @@ export class Navigator {
220
185
  };
221
186
  listener.sceneId = this.sceneId;
222
187
  if (requestCode < 0) {
223
- resultListeners.set(requestCode, listener);
188
+ globalResultListeners.set(requestCode, listener);
224
189
  }
225
190
  else {
226
191
  this.resultListener = listener;
@@ -229,107 +194,78 @@ export class Navigator {
229
194
  }
230
195
  push = async (moduleName, props = {}, options = {}) => {
231
196
  const success = await this.dispatch('push', { moduleName, props, options });
232
- console.log('push', success);
233
- return await this.waitResult(0, success);
197
+ if (!success) {
198
+ return [RESULT_CANCEL];
199
+ }
200
+ return await this.waitResult(0);
234
201
  };
235
202
  pushLayout = async (layout) => {
236
203
  const success = await this.dispatch('pushLayout', { layout });
237
- return await this.waitResult(0, success);
238
- };
239
- pop = async () => {
240
- const success = await this.dispatch('pop');
241
- console.log('pop', success);
242
- return success;
243
- };
244
- popTo = (moduleName, inclusive = false) => {
245
- return this.dispatch('popTo', { moduleName, inclusive });
246
- };
247
- popToRoot = () => {
248
- return this.dispatch('popToRoot');
249
- };
250
- redirectTo = async (moduleName, props = {}, options = {}) => {
251
- const success = await this.dispatch('redirectTo', {
252
- moduleName,
253
- props,
254
- options,
255
- });
256
- console.log('redirectTo', success);
257
- return success;
258
- };
259
- isStackRoot = () => {
260
- return new Promise((resolve, reject) => {
261
- NavigationModule.isStackRoot(this.sceneId, (error, result) => {
262
- if (error) {
263
- reject(error);
264
- }
265
- else {
266
- resolve(result);
267
- }
268
- });
269
- });
204
+ if (!success) {
205
+ return [RESULT_CANCEL];
206
+ }
207
+ return await this.waitResult(0);
270
208
  };
209
+ pop = () => this.dispatch('pop');
210
+ popTo = (moduleName, inclusive = false) => this.dispatch('popTo', { moduleName, inclusive });
211
+ popToRoot = () => this.dispatch('popToRoot');
212
+ redirectTo = (moduleName, props = {}, options = {}) => this.dispatch('redirectTo', {
213
+ moduleName,
214
+ props,
215
+ options,
216
+ });
217
+ isStackRoot = () => NavigationModule.isStackRoot(this.sceneId);
271
218
  present = async (moduleName, props = {}, options = {}) => {
272
- const requestCode = --tag;
219
+ const requestCode = --tagGenerator;
273
220
  const success = await this.dispatch('present', {
274
221
  moduleName,
275
222
  props,
276
223
  options,
277
224
  requestCode,
278
225
  });
279
- return await this.waitResult(requestCode, success);
226
+ if (!success) {
227
+ return [RESULT_CANCEL];
228
+ }
229
+ return await this.waitResult(requestCode);
280
230
  };
281
231
  presentLayout = async (layout) => {
282
- const requestCode = --tag;
232
+ const requestCode = --tagGenerator;
283
233
  const success = await this.dispatch('presentLayout', { layout, requestCode });
284
- return await this.waitResult(requestCode, success);
285
- };
286
- dismiss = () => {
287
- return this.dispatch('dismiss');
234
+ if (!success) {
235
+ return [RESULT_CANCEL];
236
+ }
237
+ return await this.waitResult(requestCode);
288
238
  };
239
+ dismiss = () => this.dispatch('dismiss');
289
240
  showModal = async (moduleName, props = {}, options = {}) => {
290
- const requestCode = --tag;
241
+ const requestCode = --tagGenerator;
291
242
  const success = await this.dispatch('showModal', {
292
243
  moduleName,
293
244
  props,
294
245
  options,
295
246
  requestCode,
296
247
  });
297
- return await this.waitResult(requestCode, success);
248
+ if (!success) {
249
+ return [RESULT_CANCEL];
250
+ }
251
+ return await this.waitResult(requestCode);
298
252
  };
299
253
  showModalLayout = async (layout) => {
300
- const requestCode = --tag;
254
+ const requestCode = --tagGenerator;
301
255
  const success = await this.dispatch('showModalLayout', { layout, requestCode });
302
- return await this.waitResult(requestCode, success);
303
- };
304
- hideModal = () => {
305
- return this.dispatch('hideModal');
306
- };
307
- setResult = (resultCode, data = null) => {
308
- NavigationModule.setResult(this.sceneId, resultCode, data);
256
+ if (!success) {
257
+ return [RESULT_CANCEL];
258
+ }
259
+ return await this.waitResult(requestCode);
309
260
  };
261
+ hideModal = () => this.dispatch('hideModal');
262
+ setResult = (resultCode, data = null) => NavigationModule.setResult(this.sceneId, resultCode, data);
310
263
  switchTab = async (index, popToRoot = false) => {
311
- const from = await new Promise((resolve, reject) => {
312
- NavigationModule.currentTab(this.sceneId, (error, result) => {
313
- if (error) {
314
- reject(error);
315
- }
316
- else {
317
- resolve(result);
318
- }
319
- });
320
- });
264
+ const from = await NavigationModule.currentTab(this.sceneId);
321
265
  return this.dispatch('switchTab', { from, to: index, popToRoot });
322
266
  };
323
- toggleMenu = () => {
324
- return this.dispatch('toggleMenu');
325
- };
326
- openMenu = () => {
327
- return this.dispatch('openMenu');
328
- };
329
- closeMenu = () => {
330
- return this.dispatch('closeMenu');
331
- };
332
- signalFirstRenderComplete = () => {
333
- NavigationModule.signalFirstRenderComplete(this.sceneId);
334
- };
267
+ toggleMenu = () => this.dispatch('toggleMenu');
268
+ openMenu = () => this.dispatch('openMenu');
269
+ closeMenu = () => this.dispatch('closeMenu');
270
+ signalFirstRenderComplete = () => NavigationModule.signalFirstRenderComplete(this.sceneId);
335
271
  }