hybrid-navigation 5.1.1 → 5.3.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 (101) hide show
  1. package/README.md +9 -20
  2. package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +5 -13
  3. package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
  4. package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +0 -50
  5. package/android/src/main/java/com/navigation/androidx/TabBarItem.java +0 -4
  6. package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +0 -7
  7. package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +7 -43
  8. package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +5 -39
  9. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +62 -135
  10. package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +0 -20
  11. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +10 -21
  12. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +39 -87
  13. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +2 -16
  14. package/dist/NativeEvent.d.ts +1 -11
  15. package/dist/NativeNavigation.d.ts +7 -6
  16. package/dist/Navigation.d.ts +8 -20
  17. package/dist/Navigation.js +32 -163
  18. package/dist/NavigationComponentWrap.d.ts +3 -3
  19. package/dist/Navigator.d.ts +4 -5
  20. package/dist/Navigator.js +13 -36
  21. package/dist/Options.d.ts +2 -2
  22. package/dist/Route.d.ts +12 -33
  23. package/dist/handler/DispatchCommandHandler.d.ts +3 -17
  24. package/dist/handler/DispatchCommandHandler.js +17 -62
  25. package/dist/handler/LayoutCommandHandler.d.ts +2 -3
  26. package/dist/handler/LayoutCommandHandler.js +0 -3
  27. package/dist/handler/LeaveGuardHandler.d.ts +2 -2
  28. package/dist/handler/LeaveGuardHandler.js +88 -46
  29. package/dist/handler/LifecycleEventHandler.d.ts +2 -14
  30. package/dist/handler/LifecycleEventHandler.js +2 -79
  31. package/dist/handler/ResultEventHandler.d.ts +0 -1
  32. package/dist/handler/ResultEventHandler.js +0 -3
  33. package/dist/handler/SceneExitHandler.d.ts +3 -0
  34. package/dist/handler/SceneExitHandler.js +76 -0
  35. package/dist/hooks.d.ts +2 -2
  36. package/dist/hooks.js +39 -22
  37. package/dist/index.d.ts +1 -12
  38. package/dist/index.js +0 -3
  39. package/dist/router/index.d.ts +0 -1
  40. package/dist/router/index.js +43 -11
  41. package/dist/sceneCoverage.d.ts +2 -0
  42. package/dist/sceneCoverage.js +25 -0
  43. package/dist/store.d.ts +0 -2
  44. package/dist/store.js +0 -4
  45. package/ios/HBDGlobalStyle.h +0 -1
  46. package/ios/HBDGlobalStyle.mm +0 -7
  47. package/ios/HybridNavigation.h +0 -1
  48. package/ios/Navigator/HBDScreenNavigator.mm +89 -237
  49. package/ios/Navigator/HBDStackNavigator.mm +1 -1
  50. package/ios/Navigator/HBDTabNavigator.mm +15 -30
  51. package/ios/React/HBDNativeNavigation.mm +4 -31
  52. package/ios/React/HBDReactBridgeManager.h +0 -5
  53. package/ios/React/HBDReactBridgeManager.mm +0 -17
  54. package/ios/ViewController/HBDReactViewController.h +1 -1
  55. package/ios/ViewController/HBDReactViewController.mm +34 -9
  56. package/ios/ViewController/HBDTabBarController.h +2 -11
  57. package/ios/ViewController/HBDTabBarController.mm +14 -170
  58. package/ios/ViewController/HBDViewController.h +0 -1
  59. package/ios/ViewController/HBDViewController.mm +9 -57
  60. package/ios/ViewController/UIViewController+HBD.h +2 -0
  61. package/ios/ViewController/UIViewController+HBD.mm +5 -0
  62. package/package.json +1 -3
  63. package/src/NativeEvent.ts +1 -12
  64. package/src/NativeNavigation.ts +8 -7
  65. package/src/Navigation.ts +49 -257
  66. package/src/NavigationComponentWrap.tsx +3 -11
  67. package/src/Navigator.ts +15 -45
  68. package/src/Options.ts +2 -3
  69. package/src/Route.ts +17 -54
  70. package/src/handler/DispatchCommandHandler.ts +29 -109
  71. package/src/handler/LayoutCommandHandler.ts +2 -6
  72. package/src/handler/LeaveGuardHandler.ts +97 -46
  73. package/src/handler/LifecycleEventHandler.ts +22 -122
  74. package/src/handler/ResultEventHandler.ts +0 -6
  75. package/src/handler/SceneExitHandler.ts +86 -0
  76. package/src/hooks.ts +39 -22
  77. package/src/index.ts +0 -14
  78. package/src/router/index.ts +45 -12
  79. package/src/sceneCoverage.ts +30 -0
  80. package/src/store.ts +0 -5
  81. package/dist/defineRoutes.d.ts +0 -19
  82. package/dist/defineRoutes.js +0 -6
  83. package/dist/handler/PresentationCoordinator.d.ts +0 -24
  84. package/dist/handler/PresentationCoordinator.js +0 -456
  85. package/dist/handler/TabEventHandler.d.ts +0 -8
  86. package/dist/handler/TabEventHandler.js +0 -25
  87. package/dist/reveal.d.ts +0 -46
  88. package/dist/reveal.js +0 -431
  89. package/dist/routeGraph.d.ts +0 -12
  90. package/dist/routeGraph.js +0 -68
  91. package/dist/testing.d.ts +0 -79
  92. package/dist/testing.js +0 -251
  93. package/ios/ViewController/HBDTabBarRenderer.h +0 -28
  94. package/src/defineRoutes.ts +0 -46
  95. package/src/handler/PresentationCoordinator.ts +0 -566
  96. package/src/handler/TabEventHandler.ts +0 -31
  97. package/src/reveal.ts +0 -565
  98. package/src/routeGraph.ts +0 -87
  99. package/src/testing.ts +0 -395
  100. package/testing.d.ts +0 -1
  101. package/testing.js +0 -3
@@ -1,566 +0,0 @@
1
- import NativeNavigation from '../NativeNavigation';
2
- import type {
3
- CloseTarget,
4
- CoveredPolicy,
5
- DispatchResult,
6
- RouteGraph,
7
- SceneExitHandler,
8
- SceneLifecycleState,
9
- } from '../Route';
10
- import { containsScene, findSceneInGraph } from '../routeGraph';
11
- import type { DispatchParams } from './DispatchCommandHandler';
12
- import { lifecycleHandler } from './LifecycleEventHandler';
13
-
14
- const PRESENT_ACTIONS = new Set([
15
- 'showModal',
16
- 'showModalLayout',
17
- 'present',
18
- 'presentLayout',
19
- ]);
20
-
21
- const CLOSE_ACTIONS = new Set(['hideModal', 'dismiss', 'close']);
22
-
23
- const DEFAULT_EXIT_TIMEOUT_MS = 1200;
24
- const MAX_IMMEDIATE_COVERED_RETRIES = 1;
25
-
26
- function findInnermostContainingStack(graph: RouteGraph, sceneId: string): RouteGraph | null {
27
- if (graph.layout === 'stack' && Array.isArray(graph.children)) {
28
- for (const child of graph.children) {
29
- if (!containsScene(child, sceneId)) {
30
- continue;
31
- }
32
- const nested = findInnermostContainingStack(child, sceneId);
33
- return nested ?? graph;
34
- }
35
- return null;
36
- }
37
- if (!Array.isArray(graph.children)) {
38
- return null;
39
- }
40
- for (const child of graph.children) {
41
- if (containsScene(child, sceneId)) {
42
- return findInnermostContainingStack(child, sceneId);
43
- }
44
- }
45
- return null;
46
- }
47
-
48
- function isSceneCoveredInStack(graph: RouteGraph, sceneId: string): boolean {
49
- const stack = findInnermostContainingStack(graph, sceneId);
50
- if (!stack || !Array.isArray(stack.children) || stack.children.length <= 1) {
51
- return false;
52
- }
53
- const childIndex = stack.children.findIndex(child => containsScene(child, sceneId));
54
- return childIndex >= 0 && childIndex < stack.children.length - 1;
55
- }
56
-
57
- interface PendingCloseEntry {
58
- promise: Promise<DispatchResult>;
59
- deferred: boolean;
60
- nativeParams: DispatchParams;
61
- }
62
-
63
- interface DeferredUncoverResult {
64
- uncovered: boolean;
65
- waited: boolean;
66
- }
67
-
68
- export default class PresentationCoordinator {
69
- private exitHandlers = new Map<string, SceneExitHandler>();
70
- private closingScenes = new Map<string, PendingCloseEntry>();
71
- private presentingOwnerByChild = new Map<string, string>();
72
- private uncoveredWaiters = new Map<string, Set<(result: DeferredUncoverResult) => void>>();
73
-
74
- registerExitHandler(sceneId: string, handler: SceneExitHandler): () => void {
75
- this.exitHandlers.set(sceneId, handler);
76
- return () => {
77
- if (this.exitHandlers.get(sceneId) === handler) {
78
- this.exitHandlers.delete(sceneId);
79
- }
80
- };
81
- }
82
-
83
- hasExitHandler(sceneId: string): boolean {
84
- return this.exitHandlers.has(sceneId);
85
- }
86
-
87
- async isSceneCovered(sceneId: string, includeStackCover: boolean = false): Promise<boolean> {
88
- try {
89
- const layers: RouteGraph[] = await NativeNavigation.routeGraph();
90
- if (!Array.isArray(layers) || layers.length === 0) {
91
- return false;
92
- }
93
- const index = layers.findIndex(layer => containsScene(layer, sceneId));
94
- if (index < 0) {
95
- return false;
96
- }
97
- if (index < layers.length - 1) {
98
- return true;
99
- }
100
- return includeStackCover ? isSceneCoveredInStack(layers[index], sceneId) : false;
101
- } catch {
102
- return false;
103
- }
104
- }
105
-
106
- private async findTopmostDirectPresentedExitSceneId(sceneId: string): Promise<string | null> {
107
- try {
108
- const layers: RouteGraph[] = await NativeNavigation.routeGraph();
109
- if (!Array.isArray(layers) || layers.length <= 1) {
110
- return null;
111
- }
112
- const index = layers.findIndex(layer => containsScene(layer, sceneId));
113
- if (index < 0 || index + 1 !== layers.length - 1) {
114
- return null;
115
- }
116
- const presentedLayer = layers[index + 1];
117
- if (presentedLayer.layout === 'screen') {
118
- return this.exitHandlers.has(presentedLayer.sceneId) ? presentedLayer.sceneId : null;
119
- }
120
- const match = findSceneInGraph(presentedLayer, node => this.exitHandlers.has(node.sceneId));
121
- return match?.sceneId ?? null;
122
- } catch {
123
- return null;
124
- }
125
- }
126
-
127
- private waitUntilUncovered(
128
- sceneId: string,
129
- includeStackCover: boolean,
130
- ): Promise<DeferredUncoverResult> {
131
- if (lifecycleHandler.getSceneState(sceneId) === 'destroyed') {
132
- return Promise.resolve({ uncovered: false, waited: false });
133
- }
134
- return new Promise<DeferredUncoverResult>(resolve => {
135
- let settled = false;
136
- let waited = false;
137
- let checkVersion = 0;
138
- let checking = false;
139
- let recheckQueued = false;
140
-
141
- const finish = (result: DeferredUncoverResult) => {
142
- if (settled) {
143
- return;
144
- }
145
- settled = true;
146
- lifecycleHandler.removeGlobalLifecycleListener(onGlobalLifecycle);
147
- const waiters = this.uncoveredWaiters.get(sceneId);
148
- if (waiters) {
149
- waiters.delete(finish);
150
- if (waiters.size === 0) {
151
- this.uncoveredWaiters.delete(sceneId);
152
- }
153
- }
154
- resolve(result);
155
- };
156
-
157
- const runCheck = () => {
158
- if (settled) {
159
- return;
160
- }
161
- if (lifecycleHandler.getSceneState(sceneId) === 'destroyed') {
162
- finish({ uncovered: false, waited });
163
- return;
164
- }
165
- if (checking) {
166
- recheckQueued = true;
167
- return;
168
- }
169
- checking = true;
170
- const version = ++checkVersion;
171
- this.isSceneCovered(sceneId, includeStackCover).then(
172
- covered => {
173
- checking = false;
174
- if (settled || version !== checkVersion) {
175
- return;
176
- }
177
- if (lifecycleHandler.getSceneState(sceneId) === 'destroyed') {
178
- finish({ uncovered: false, waited });
179
- return;
180
- }
181
- if (!covered) {
182
- finish({ uncovered: true, waited });
183
- return;
184
- }
185
- waited = true;
186
- if (recheckQueued) {
187
- recheckQueued = false;
188
- runCheck();
189
- }
190
- },
191
- () => {
192
- checking = false;
193
- if (settled) {
194
- return;
195
- }
196
- waited = true;
197
- if (recheckQueued) {
198
- recheckQueued = false;
199
- runCheck();
200
- }
201
- },
202
- );
203
- };
204
-
205
- const onGlobalLifecycle = (changedSceneId: string, nextState: SceneLifecycleState) => {
206
- if (settled) {
207
- return;
208
- }
209
- if (changedSceneId === sceneId) {
210
- if (nextState === 'destroyed') {
211
- finish({ uncovered: false, waited });
212
- } else if (nextState === 'visible') {
213
- waited = true;
214
- runCheck();
215
- }
216
- return;
217
- }
218
- // iOS OverFullScreen modal dismissal emits invisible/destroyed on the upper scene
219
- // without re-emitting visible on the underlying scene.
220
- if (nextState === 'invisible' || nextState === 'destroyed') {
221
- waited = true;
222
- runCheck();
223
- }
224
- };
225
-
226
- let waiters = this.uncoveredWaiters.get(sceneId);
227
- if (!waiters) {
228
- waiters = new Set();
229
- this.uncoveredWaiters.set(sceneId, waiters);
230
- }
231
- waiters.add(finish);
232
- lifecycleHandler.addGlobalLifecycleListener(onGlobalLifecycle);
233
- // Re-check right after subscribing so an uncover during the prior async check is never missed.
234
- runCheck();
235
- });
236
- }
237
-
238
- private async awaitPendingClosesForOwner(ownerSceneId: string): Promise<void> {
239
- if (this.closingScenes.size === 0) {
240
- return;
241
- }
242
- const pending: Promise<unknown>[] = [];
243
- for (const [closingSceneId, entry] of this.closingScenes) {
244
- if (entry.deferred || closingSceneId === ownerSceneId) {
245
- continue;
246
- }
247
- const presentingOwner =
248
- lifecycleHandler.getSceneInfo(closingSceneId)?.presentingId ??
249
- this.presentingOwnerByChild.get(closingSceneId);
250
- if (!presentingOwner || presentingOwner !== ownerSceneId) {
251
- continue;
252
- }
253
- pending.push(entry.promise.catch(() => undefined));
254
- }
255
- if (pending.length > 0) {
256
- await Promise.all(pending);
257
- }
258
- }
259
-
260
- private runExitWithTimeout(handler: SceneExitHandler): Promise<void> {
261
- const timeoutMs = handler.exitTimeoutMs ?? DEFAULT_EXIT_TIMEOUT_MS;
262
- let result: void | Promise<void>;
263
- try {
264
- result = handler.onExit();
265
- } catch (error) {
266
- return Promise.reject(error);
267
- }
268
- if (!result || typeof (result as Promise<void>).then !== 'function') {
269
- return Promise.resolve();
270
- }
271
- if (timeoutMs <= 0) {
272
- return result;
273
- }
274
- return new Promise<void>((resolve, reject) => {
275
- let settled = false;
276
- const timer = setTimeout(() => {
277
- if (settled) {
278
- return;
279
- }
280
- settled = true;
281
- reject(new Error(`Scene exit handler timed out after ${timeoutMs}ms.`));
282
- }, timeoutMs);
283
- (timer as { unref?: () => void }).unref?.();
284
- Promise.resolve(result).then(
285
- () => {
286
- if (settled) {
287
- return;
288
- }
289
- settled = true;
290
- clearTimeout(timer);
291
- resolve();
292
- },
293
- error => {
294
- if (settled) {
295
- return;
296
- }
297
- settled = true;
298
- clearTimeout(timer);
299
- reject(error);
300
- },
301
- );
302
- });
303
- }
304
-
305
- middleware = async (
306
- sceneId: string,
307
- action: string,
308
- params: DispatchParams,
309
- next: (sceneId: string, action: string, params: DispatchParams) => Promise<DispatchResult>,
310
- ): Promise<DispatchResult> => {
311
- if (PRESENT_ACTIONS.has(action)) {
312
- return this.handleOpen(sceneId, action, params, next);
313
- }
314
- if (CLOSE_ACTIONS.has(action)) {
315
- return this.handleClose(sceneId, action, params, next);
316
- }
317
- return next(sceneId, action, params);
318
- };
319
-
320
- private async handleOpen(
321
- ownerSceneId: string,
322
- action: string,
323
- params: DispatchParams,
324
- next: (sceneId: string, action: string, params: DispatchParams) => Promise<DispatchResult>,
325
- ): Promise<DispatchResult> {
326
- await this.awaitPendingClosesForOwner(ownerSceneId);
327
- const result = await next(ownerSceneId, action, params);
328
- if (result.ok && result.sceneId) {
329
- this.presentingOwnerByChild.set(result.sceneId, ownerSceneId);
330
- }
331
- return result;
332
- }
333
-
334
- private async handleClose(
335
- sceneId: string,
336
- action: string,
337
- params: DispatchParams,
338
- next: (sceneId: string, action: string, params: DispatchParams) => Promise<DispatchResult>,
339
- ): Promise<DispatchResult> {
340
- const explicitTarget: CloseTarget | undefined =
341
- params.target ?? (action === 'close' ? 'self' : undefined);
342
- const onCovered: CoveredPolicy = params.onCovered ?? 'fail';
343
-
344
- if (explicitTarget === 'presented') {
345
- const childSceneId = await this.findTopmostDirectPresentedExitSceneId(sceneId);
346
- if (childSceneId) {
347
- const childMode = lifecycleHandler.getSceneInfo(childSceneId)?.mode;
348
- const childAction = childMode === 'present' ? 'dismiss' : 'hideModal';
349
- return this.runDeduplicatedSelfClose(
350
- childSceneId,
351
- childAction,
352
- { ...params, target: 'self' },
353
- onCovered,
354
- next,
355
- );
356
- }
357
- return next(sceneId, action, params);
358
- }
359
-
360
- if (explicitTarget === 'self') {
361
- return this.runDeduplicatedSelfClose(sceneId, action, params, onCovered, next);
362
- }
363
-
364
- // Legacy hideModal() / dismiss() without explicit target:
365
- // If covered by a presented child, keep v5.0 native semantics (dismiss child).
366
- // Only coordinate self exit when not covered and an exit handler is registered.
367
- if (this.exitHandlers.has(sceneId) && !(await this.isSceneCovered(sceneId, false))) {
368
- return this.runDeduplicatedSelfClose(sceneId, action, params, onCovered, next);
369
- }
370
-
371
- return next(sceneId, action, params);
372
- }
373
-
374
- private async runDeduplicatedSelfClose(
375
- sceneId: string,
376
- action: string,
377
- params: DispatchParams,
378
- onCovered: CoveredPolicy,
379
- next: (sceneId: string, action: string, params: DispatchParams) => Promise<DispatchResult>,
380
- ): Promise<DispatchResult> {
381
- const existing = this.closingScenes.get(sceneId);
382
- if (existing) {
383
- if (existing.deferred) {
384
- if (onCovered === 'fail') {
385
- return {
386
- ok: false,
387
- code: 'covered',
388
- message: 'Target scene is covered by another scene.',
389
- };
390
- }
391
- if (params.result !== undefined) {
392
- existing.nativeParams = {
393
- ...existing.nativeParams,
394
- result: params.result,
395
- };
396
- }
397
- }
398
- return existing.promise;
399
- }
400
-
401
- const nativeParams: DispatchParams = { ...params, target: 'self' };
402
- delete nativeParams.onCovered;
403
-
404
- const entry: PendingCloseEntry = {
405
- promise: Promise.resolve({ ok: false, code: 'invalid_action' }),
406
- deferred: false,
407
- nativeParams,
408
- };
409
- const pending = this.executeSelfClose(sceneId, action, onCovered, entry, next);
410
- entry.promise = pending;
411
- this.closingScenes.set(sceneId, entry);
412
- try {
413
- return await pending;
414
- } finally {
415
- if (this.closingScenes.get(sceneId) === entry) {
416
- this.closingScenes.delete(sceneId);
417
- }
418
- }
419
- }
420
-
421
- private async waitForDeferredUncover(
422
- sceneId: string,
423
- entry: PendingCloseEntry,
424
- includeStackCover: boolean,
425
- ): Promise<DeferredUncoverResult> {
426
- entry.deferred = true;
427
- try {
428
- return await this.waitUntilUncovered(sceneId, includeStackCover);
429
- } finally {
430
- entry.deferred = false;
431
- }
432
- }
433
-
434
- private async executeSelfClose(
435
- sceneId: string,
436
- action: string,
437
- onCovered: CoveredPolicy,
438
- entry: PendingCloseEntry,
439
- next: (sceneId: string, action: string, params: DispatchParams) => Promise<DispatchResult>,
440
- ): Promise<DispatchResult> {
441
- const includeStackCover = action === 'close';
442
- let immediateCoveredRetries = 0;
443
-
444
- while (true) {
445
- if (lifecycleHandler.getSceneState(sceneId) === 'destroyed') {
446
- return { ok: false, code: 'scene_not_found', message: 'Target scene is already destroyed.' };
447
- }
448
-
449
- if (await this.isSceneCovered(sceneId, includeStackCover)) {
450
- if (onCovered === 'defer') {
451
- const waitResult = await this.waitForDeferredUncover(
452
- sceneId,
453
- entry,
454
- includeStackCover,
455
- );
456
- if (!waitResult.uncovered) {
457
- return { ok: false, code: 'scene_not_found' };
458
- }
459
- immediateCoveredRetries = 0;
460
- continue;
461
- }
462
- return {
463
- ok: false,
464
- code: 'covered',
465
- message: 'Target scene is covered by another scene.',
466
- };
467
- }
468
-
469
- const registration = this.exitHandlers.get(sceneId);
470
- if (registration) {
471
- try {
472
- await this.runExitWithTimeout(registration);
473
- } catch (error) {
474
- registration.onRestore?.('exit_error');
475
- return {
476
- ok: false,
477
- code: 'invalid_action',
478
- message: error instanceof Error ? error.message : String(error),
479
- };
480
- }
481
-
482
- if (await this.isSceneCovered(sceneId, includeStackCover)) {
483
- registration.onRestore?.('covered');
484
- if (onCovered === 'defer') {
485
- const waitResult = await this.waitForDeferredUncover(
486
- sceneId,
487
- entry,
488
- includeStackCover,
489
- );
490
- if (!waitResult.uncovered) {
491
- return { ok: false, code: 'scene_not_found' };
492
- }
493
- immediateCoveredRetries = 0;
494
- continue;
495
- }
496
- return {
497
- ok: false,
498
- code: 'covered',
499
- message: 'Target scene became covered during exit.',
500
- };
501
- }
502
- }
503
-
504
- let result: DispatchResult;
505
- try {
506
- result = await next(sceneId, action, entry.nativeParams);
507
- } catch (error) {
508
- registration?.onRestore?.('invalid_action');
509
- throw error;
510
- }
511
- if (result.ok) {
512
- this.presentingOwnerByChild.delete(sceneId);
513
- return result;
514
- }
515
-
516
- registration?.onRestore?.(result.code);
517
- if (result.code === 'covered' && onCovered === 'defer') {
518
- const waitResult = await this.waitForDeferredUncover(
519
- sceneId,
520
- entry,
521
- includeStackCover,
522
- );
523
- if (!waitResult.uncovered) {
524
- return { ok: false, code: 'scene_not_found' };
525
- }
526
- if (waitResult.waited) {
527
- immediateCoveredRetries = 0;
528
- } else {
529
- immediateCoveredRetries += 1;
530
- if (immediateCoveredRetries > MAX_IMMEDIATE_COVERED_RETRIES) {
531
- return result;
532
- }
533
- }
534
- continue;
535
- }
536
- return result;
537
- }
538
- }
539
-
540
- onSceneDestroyed(sceneId: string) {
541
- this.exitHandlers.delete(sceneId);
542
- const waiters = this.uncoveredWaiters.get(sceneId);
543
- if (waiters) {
544
- this.uncoveredWaiters.delete(sceneId);
545
- waiters.forEach(resolve => resolve({ uncovered: false, waited: false }));
546
- }
547
-
548
- this.presentingOwnerByChild.delete(sceneId);
549
- for (const [childId, ownerId] of this.presentingOwnerByChild) {
550
- if (ownerId === sceneId) {
551
- this.presentingOwnerByChild.delete(childId);
552
- }
553
- }
554
- }
555
-
556
- onRootReset() {
557
- for (const waiters of this.uncoveredWaiters.values()) {
558
- waiters.forEach(resolve => resolve({ uncovered: false, waited: false }));
559
- }
560
- this.uncoveredWaiters.clear();
561
- this.exitHandlers.clear();
562
- this.presentingOwnerByChild.clear();
563
- }
564
- }
565
-
566
- export const presentationCoordinator = new PresentationCoordinator();
@@ -1,31 +0,0 @@
1
- import NativeEvent from '../NativeEvent';
2
- import type { TabPressEvent, TabPressListener } from '../Route';
3
-
4
- export default class TabEventHandler {
5
- private listeners: TabPressListener[] = [];
6
-
7
- handleTabPress() {
8
- NativeEvent.onTabPress(({ index, tabKey, previousIndex, reselected }) => {
9
- const event: TabPressEvent = {
10
- index,
11
- tabKey,
12
- previousIndex,
13
- reselected: Boolean(reselected),
14
- };
15
- this.listeners.slice().forEach(listener => listener(event));
16
- });
17
- }
18
-
19
- addListener(listener: TabPressListener): () => void {
20
- this.listeners.push(listener);
21
- return () => {
22
- this.listeners = this.listeners.filter(item => item !== listener);
23
- };
24
- }
25
-
26
- clearListeners() {
27
- this.listeners = [];
28
- }
29
- }
30
-
31
- export const tabEventHandler = new TabEventHandler();