hybrid-navigation 5.0.0 → 5.1.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 (107) hide show
  1. package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +2 -4
  2. package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +48 -2
  3. package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
  4. package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +7 -0
  5. package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +2 -4
  6. package/android/src/main/java/com/navigation/androidx/StackFragment.java +3 -0
  7. package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +50 -0
  8. package/android/src/main/java/com/navigation/androidx/TabBarItem.java +4 -0
  9. package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +16 -4
  10. package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +19 -0
  11. package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +17 -2
  12. package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +66 -7
  13. package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +116 -18
  14. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +8 -0
  15. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +376 -8
  16. package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +72 -2
  17. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +26 -0
  18. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +134 -12
  19. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +35 -3
  20. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +29 -4
  21. package/dist/NativeEvent.d.ts +15 -0
  22. package/dist/NativeNavigation.d.ts +8 -0
  23. package/dist/Navigation.d.ts +14 -1
  24. package/dist/Navigation.js +153 -12
  25. package/dist/NavigationComponentWrap.d.ts +3 -2
  26. package/dist/Navigator.d.ts +3 -2
  27. package/dist/Navigator.js +28 -9
  28. package/dist/Options.d.ts +12 -2
  29. package/dist/Route.d.ts +70 -5
  30. package/dist/defineRoutes.d.ts +19 -0
  31. package/dist/defineRoutes.js +6 -0
  32. package/dist/handler/DispatchCommandHandler.d.ts +16 -1
  33. package/dist/handler/DispatchCommandHandler.js +63 -5
  34. package/dist/handler/LayoutCommandHandler.d.ts +1 -0
  35. package/dist/handler/LayoutCommandHandler.js +3 -0
  36. package/dist/handler/LeaveGuardHandler.d.ts +17 -0
  37. package/dist/handler/LeaveGuardHandler.js +350 -0
  38. package/dist/handler/LifecycleEventHandler.d.ts +7 -3
  39. package/dist/handler/LifecycleEventHandler.js +36 -3
  40. package/dist/handler/PresentationCoordinator.d.ts +24 -0
  41. package/dist/handler/PresentationCoordinator.js +449 -0
  42. package/dist/handler/ResultEventHandler.d.ts +7 -0
  43. package/dist/handler/ResultEventHandler.js +13 -5
  44. package/dist/handler/TabEventHandler.d.ts +8 -0
  45. package/dist/handler/TabEventHandler.js +25 -0
  46. package/dist/hooks.d.ts +3 -1
  47. package/dist/hooks.js +20 -0
  48. package/dist/index.d.ts +11 -0
  49. package/dist/index.js +3 -0
  50. package/dist/reveal.d.ts +46 -0
  51. package/dist/reveal.js +431 -0
  52. package/dist/routeGraph.d.ts +12 -0
  53. package/dist/routeGraph.js +68 -0
  54. package/dist/router/index.js +5 -41
  55. package/dist/router/tabs.d.ts +1 -0
  56. package/dist/store.d.ts +2 -0
  57. package/dist/store.js +4 -0
  58. package/dist/testing.d.ts +79 -0
  59. package/dist/testing.js +251 -0
  60. package/ios/HBDGlobalStyle.h +3 -0
  61. package/ios/HBDGlobalStyle.mm +13 -0
  62. package/ios/HybridNavigation.h +1 -0
  63. package/ios/Navigator/HBDScreenNavigator.mm +177 -11
  64. package/ios/Navigator/HBDStackNavigator.mm +50 -7
  65. package/ios/Navigator/HBDTabNavigator.mm +33 -5
  66. package/ios/React/HBDNativeNavigation.mm +73 -12
  67. package/ios/React/HBDNavigator.h +8 -0
  68. package/ios/React/HBDOrientationCoordinator.h +2 -0
  69. package/ios/React/HBDOrientationCoordinator.mm +27 -0
  70. package/ios/React/HBDReactBridgeManager.h +10 -0
  71. package/ios/React/HBDReactBridgeManager.mm +48 -2
  72. package/ios/ViewController/HBDNavigationController.mm +14 -0
  73. package/ios/ViewController/HBDReactViewController.h +6 -0
  74. package/ios/ViewController/HBDReactViewController.mm +177 -1
  75. package/ios/ViewController/HBDTabBarController.h +11 -0
  76. package/ios/ViewController/HBDTabBarController.mm +170 -3
  77. package/ios/ViewController/HBDTabBarRenderer.h +28 -0
  78. package/ios/ViewController/HBDViewController.h +1 -0
  79. package/ios/ViewController/HBDViewController.mm +57 -9
  80. package/ios/ViewController/UIViewController+HBD.h +1 -0
  81. package/ios/ViewController/UIViewController+HBD.mm +13 -4
  82. package/package.json +3 -1
  83. package/src/NativeEvent.ts +17 -0
  84. package/src/NativeNavigation.ts +9 -0
  85. package/src/Navigation.ts +228 -12
  86. package/src/NavigationComponentWrap.tsx +11 -2
  87. package/src/Navigator.ts +38 -9
  88. package/src/Options.ts +9 -2
  89. package/src/Route.ts +102 -6
  90. package/src/defineRoutes.ts +46 -0
  91. package/src/handler/DispatchCommandHandler.ts +110 -11
  92. package/src/handler/LayoutCommandHandler.ts +4 -0
  93. package/src/handler/LeaveGuardHandler.ts +436 -0
  94. package/src/handler/LifecycleEventHandler.ts +85 -38
  95. package/src/handler/PresentationCoordinator.ts +560 -0
  96. package/src/handler/ResultEventHandler.ts +23 -9
  97. package/src/handler/TabEventHandler.ts +31 -0
  98. package/src/hooks.ts +37 -1
  99. package/src/index.ts +11 -0
  100. package/src/reveal.ts +565 -0
  101. package/src/routeGraph.ts +87 -0
  102. package/src/router/index.ts +5 -40
  103. package/src/router/tabs.ts +1 -0
  104. package/src/store.ts +5 -0
  105. package/src/testing.ts +395 -0
  106. package/testing.d.ts +1 -0
  107. package/testing.js +3 -0
package/dist/reveal.js ADDED
@@ -0,0 +1,431 @@
1
+ import { containsScene, findSceneInGraph, findTabIndex, findTabsGraph } from './routeGraph';
2
+ function isDrawerGraph(graph) {
3
+ return graph.layout === 'drawer';
4
+ }
5
+ function isScreenGraph(graph) {
6
+ return graph.layout === 'screen';
7
+ }
8
+ function isStackGraph(graph) {
9
+ return graph.layout === 'stack';
10
+ }
11
+ function findContainingDrawer(graph, sceneId) {
12
+ if (isDrawerGraph(graph)) {
13
+ const [content, menu] = graph.children;
14
+ if (menu && containsScene(menu, sceneId)) {
15
+ return { drawer: graph, inMenu: true };
16
+ }
17
+ if (content && containsScene(content, sceneId)) {
18
+ const nested = findContainingDrawer(content, sceneId);
19
+ return nested ?? { drawer: graph, inMenu: false };
20
+ }
21
+ }
22
+ if (!graph.children) {
23
+ return null;
24
+ }
25
+ for (const child of graph.children) {
26
+ const found = findContainingDrawer(child, sceneId);
27
+ if (found) {
28
+ return found;
29
+ }
30
+ }
31
+ return null;
32
+ }
33
+ function locateTargetInLayer(layer, target) {
34
+ if (target.sceneId) {
35
+ if (!containsScene(layer, target.sceneId)) {
36
+ return null;
37
+ }
38
+ const tabs = findTabsGraph(layer);
39
+ const tabIndex = tabs ? findTabIndex(tabs, { sceneId: target.sceneId }) : -1;
40
+ return { tabs: tabIndex >= 0 ? tabs : null, tabIndex, screenSceneId: target.sceneId };
41
+ }
42
+ if (target.tabKey) {
43
+ const tabs = findTabsGraph(layer);
44
+ if (tabs) {
45
+ const tabIndex = findTabIndex(tabs, { tabKey: target.tabKey, moduleName: target.moduleName });
46
+ if (tabIndex >= 0) {
47
+ const tabChild = tabs.children[tabIndex];
48
+ if (target.moduleName) {
49
+ const screen = findSceneInGraph(tabChild, node => node.moduleName === target.moduleName);
50
+ if (screen) {
51
+ return { tabs, tabIndex, screenSceneId: screen.sceneId };
52
+ }
53
+ }
54
+ else {
55
+ const screen = findSceneInGraph(tabChild, () => true);
56
+ return { tabs, tabIndex, screenSceneId: screen?.sceneId ?? tabChild.sceneId };
57
+ }
58
+ }
59
+ }
60
+ if (!target.moduleName) {
61
+ return null;
62
+ }
63
+ }
64
+ if (target.moduleName) {
65
+ const tabs = findTabsGraph(layer);
66
+ if (tabs) {
67
+ const tabIndex = findTabIndex(tabs, { moduleName: target.moduleName });
68
+ if (tabIndex >= 0) {
69
+ const screen = findSceneInGraph(tabs.children[tabIndex], node => node.moduleName === target.moduleName);
70
+ if (screen) {
71
+ return { tabs, tabIndex, screenSceneId: screen.sceneId };
72
+ }
73
+ }
74
+ }
75
+ const screen = findSceneInGraph(layer, node => node.moduleName === target.moduleName);
76
+ if (screen) {
77
+ return { tabs: null, tabIndex: -1, screenSceneId: screen.sceneId };
78
+ }
79
+ }
80
+ return null;
81
+ }
82
+ function locateTarget(layers, target) {
83
+ for (let i = layers.length - 1; i >= 0; i--) {
84
+ const located = locateTargetInLayer(layers[i], target);
85
+ if (located) {
86
+ return { layerIndex: i, ...located };
87
+ }
88
+ }
89
+ return null;
90
+ }
91
+ function isAlreadyRevealed(layers, current, located, target) {
92
+ if (located.layerIndex !== layers.length - 1) {
93
+ return false;
94
+ }
95
+ const layer = layers[located.layerIndex];
96
+ if (located.tabs) {
97
+ if (isStackGraph(layer) && layer.children[layer.children.length - 1] !== located.tabs) {
98
+ return false;
99
+ }
100
+ if (located.tabs.selectedIndex !== located.tabIndex) {
101
+ return false;
102
+ }
103
+ const activeTab = located.tabs.children[located.tabIndex];
104
+ if (target.sceneId) {
105
+ return current.sceneId === target.sceneId;
106
+ }
107
+ if (target.moduleName) {
108
+ return (current.moduleName === target.moduleName &&
109
+ (!located.screenSceneId || current.sceneId === located.screenSceneId));
110
+ }
111
+ if (isScreenGraph(activeTab)) {
112
+ return current.sceneId === activeTab.sceneId;
113
+ }
114
+ return containsScene(activeTab, current.sceneId);
115
+ }
116
+ if (target.sceneId) {
117
+ return current.sceneId === target.sceneId;
118
+ }
119
+ if (target.moduleName) {
120
+ return (current.moduleName === target.moduleName &&
121
+ (!located.screenSceneId || current.sceneId === located.screenSceneId));
122
+ }
123
+ return false;
124
+ }
125
+ /** Dismiss all presented/modal layers above the root layer with rootGeneration and loop protection. */
126
+ export async function dismissPresentedLayers(driver, options = {}) {
127
+ const { maxSteps = 12, bypassGuards = false } = options;
128
+ const visited = new Set();
129
+ let initialRootGeneration;
130
+ for (let step = 0; step < maxSteps; step++) {
131
+ let layers;
132
+ let current;
133
+ let rootGeneration;
134
+ if (driver.navigationSnapshot) {
135
+ const snapshot = await driver.navigationSnapshot();
136
+ layers = snapshot.layers;
137
+ current = snapshot.currentRoute;
138
+ rootGeneration = snapshot.rootGeneration;
139
+ }
140
+ else {
141
+ [layers, current] = await Promise.all([
142
+ driver.routeGraph(),
143
+ driver.currentRoute(),
144
+ ]);
145
+ }
146
+ if (rootGeneration !== undefined) {
147
+ if (initialRootGeneration === undefined) {
148
+ initialRootGeneration = rootGeneration;
149
+ }
150
+ else if (rootGeneration !== initialRootGeneration) {
151
+ return {
152
+ ok: false,
153
+ code: 'superseded',
154
+ message: 'Root layout changed while dismissing presented scenes.',
155
+ };
156
+ }
157
+ }
158
+ if (!Array.isArray(layers) || layers.length === 0) {
159
+ return { ok: false, code: 'not_ready', message: 'Route graph is empty.' };
160
+ }
161
+ if (layers.length <= 1) {
162
+ return { ok: true, layers };
163
+ }
164
+ if (!current?.sceneId) {
165
+ return {
166
+ ok: false,
167
+ code: 'scene_not_found',
168
+ message: 'Unable to resolve current route while dismissing presented scenes.',
169
+ };
170
+ }
171
+ const topLayer = layers[layers.length - 1];
172
+ if (!containsScene(topLayer, current.sceneId)) {
173
+ return { ok: false, code: 'scene_not_found', message: 'Current scene is not in top layer.' };
174
+ }
175
+ const stepKey = `${layers.length}:${current.sceneId}`;
176
+ if (visited.has(stepKey)) {
177
+ return {
178
+ ok: false,
179
+ code: 'invalid_action',
180
+ message: 'Dismissing presented layers did not advance.',
181
+ };
182
+ }
183
+ visited.add(stepKey);
184
+ const action = topLayer.mode === 'modal'
185
+ ? 'hideModal'
186
+ : topLayer.mode === 'present'
187
+ ? 'dismiss'
188
+ : null;
189
+ if (!action) {
190
+ return {
191
+ ok: false,
192
+ code: 'invalid_action',
193
+ message: `Unsupported layer mode: ${topLayer.mode}`,
194
+ };
195
+ }
196
+ const res = await driver.dispatch(current.sceneId, action, {
197
+ from: current.moduleName,
198
+ target: 'self',
199
+ ...(bypassGuards ? { bypassBeforeRemove: true } : {}),
200
+ });
201
+ if (!res.ok) {
202
+ return { ok: false, code: res.code, sceneId: res.sceneId, message: res.message };
203
+ }
204
+ }
205
+ return {
206
+ ok: false,
207
+ code: 'invalid_action',
208
+ message: 'Dismissing presented layers exceeded maximum navigation steps.',
209
+ };
210
+ }
211
+ export async function executeReveal(driver, target, options = {}) {
212
+ const { dismissModals = true, popToTarget = true, switchTab = true, bypassGuards = false, maxSteps = 12, shouldContinue, } = options;
213
+ const guardParam = bypassGuards ? { bypassBeforeRemove: true } : {};
214
+ const visited = new Set();
215
+ const closedDrawers = new Set();
216
+ const openedDrawers = new Set();
217
+ let initialRootGeneration;
218
+ for (let step = 0; step < maxSteps; step++) {
219
+ if (shouldContinue && !(await shouldContinue())) {
220
+ return { ok: false, code: 'aborted' };
221
+ }
222
+ let layers;
223
+ let current;
224
+ let rootGeneration;
225
+ if (driver.navigationSnapshot) {
226
+ const snapshot = await driver.navigationSnapshot();
227
+ layers = snapshot.layers;
228
+ current = snapshot.currentRoute;
229
+ rootGeneration = snapshot.rootGeneration;
230
+ }
231
+ else {
232
+ [layers, current] = await Promise.all([
233
+ driver.routeGraph(),
234
+ driver.currentRoute(),
235
+ ]);
236
+ }
237
+ if (shouldContinue && !(await shouldContinue())) {
238
+ return { ok: false, code: 'aborted' };
239
+ }
240
+ if (rootGeneration !== undefined) {
241
+ if (initialRootGeneration === undefined) {
242
+ initialRootGeneration = rootGeneration;
243
+ }
244
+ else if (rootGeneration !== initialRootGeneration) {
245
+ return {
246
+ ok: false,
247
+ code: 'superseded',
248
+ message: 'Root layout changed during reveal.',
249
+ };
250
+ }
251
+ }
252
+ if (!Array.isArray(layers) || layers.length === 0 || !current?.sceneId) {
253
+ return { ok: false, code: 'not_ready', message: 'Route graph or current route is unavailable.' };
254
+ }
255
+ const located = locateTarget(layers, target);
256
+ if (!located) {
257
+ return {
258
+ ok: false,
259
+ code: 'scene_not_found',
260
+ message: 'Target scene or tab not found in route graph.',
261
+ };
262
+ }
263
+ const targetLayer = layers[located.layerIndex];
264
+ const targetSceneForDrawer = located.screenSceneId ?? located.tabs?.sceneId;
265
+ const drawerContext = targetSceneForDrawer
266
+ ? findContainingDrawer(targetLayer, targetSceneForDrawer)
267
+ : null;
268
+ const needsDrawerClose = Boolean(drawerContext) &&
269
+ !drawerContext.inMenu &&
270
+ !closedDrawers.has(drawerContext.drawer.sceneId);
271
+ const needsDrawerOpen = Boolean(drawerContext) &&
272
+ drawerContext.inMenu &&
273
+ !openedDrawers.has(drawerContext.drawer.sceneId);
274
+ if (!needsDrawerClose &&
275
+ !needsDrawerOpen &&
276
+ isAlreadyRevealed(layers, current, located, target)) {
277
+ return { ok: true, sceneId: current.sceneId, moduleName: current.moduleName };
278
+ }
279
+ const stepKey = `${layers.length}:${current.sceneId}:${located.tabs?.selectedIndex ?? -1}:${needsDrawerClose ? 1 : 0}:${needsDrawerOpen ? 1 : 0}`;
280
+ if (visited.has(stepKey)) {
281
+ return {
282
+ ok: false,
283
+ code: 'invalid_action',
284
+ message: 'Reveal did not advance after previous navigation step.',
285
+ };
286
+ }
287
+ visited.add(stepKey);
288
+ if (layers.length - 1 > located.layerIndex) {
289
+ if (!dismissModals) {
290
+ return { ok: false, code: 'covered', message: 'Target is covered by a presented layer.' };
291
+ }
292
+ const topLayer = layers[layers.length - 1];
293
+ if (!containsScene(topLayer, current.sceneId)) {
294
+ return { ok: false, code: 'scene_not_found', message: 'Current scene is not in top layer.' };
295
+ }
296
+ const action = topLayer.mode === 'modal'
297
+ ? 'hideModal'
298
+ : topLayer.mode === 'present'
299
+ ? 'dismiss'
300
+ : null;
301
+ if (!action) {
302
+ return { ok: false, code: 'invalid_action', message: `Unsupported layer mode: ${topLayer.mode}` };
303
+ }
304
+ const res = await driver.dispatch(current.sceneId, action, {
305
+ from: current.moduleName,
306
+ target: 'self',
307
+ ...guardParam,
308
+ });
309
+ if (!res.ok) {
310
+ return { ok: false, code: res.code, sceneId: res.sceneId, message: res.message };
311
+ }
312
+ continue;
313
+ }
314
+ if (isStackGraph(targetLayer)) {
315
+ const stackTop = targetLayer.children[targetLayer.children.length - 1];
316
+ const targetSceneInStack = located.screenSceneId ?? located.tabs?.sceneId;
317
+ const targetChild = targetSceneInStack
318
+ ? targetLayer.children.find(child => containsScene(child, targetSceneInStack))
319
+ : undefined;
320
+ if (targetChild && stackTop !== targetChild) {
321
+ if (!popToTarget) {
322
+ return {
323
+ ok: false,
324
+ code: 'covered',
325
+ message: located.tabs
326
+ ? 'Target tabs are covered by stack screens.'
327
+ : 'Target scene is below stack top.',
328
+ };
329
+ }
330
+ if (!stackTop || !containsScene(stackTop, current.sceneId)) {
331
+ return { ok: false, code: 'scene_not_found' };
332
+ }
333
+ const isContainerRoot = !isScreenGraph(targetChild) && targetLayer.children[0] === targetChild;
334
+ const res = isContainerRoot
335
+ ? await driver.dispatch(current.sceneId, 'popToRoot', {
336
+ from: current.moduleName,
337
+ ...guardParam,
338
+ })
339
+ : await driver.dispatch(current.sceneId, 'popTo', {
340
+ moduleName: isScreenGraph(targetChild)
341
+ ? (located.screenSceneId ?? targetChild.sceneId)
342
+ : targetChild.sceneId,
343
+ from: current.moduleName,
344
+ ...guardParam,
345
+ });
346
+ if (!res.ok) {
347
+ return { ok: false, code: res.code, sceneId: res.sceneId, message: res.message };
348
+ }
349
+ continue;
350
+ }
351
+ }
352
+ if (drawerContext && needsDrawerClose) {
353
+ const menuScreen = drawerContext.drawer.children[1];
354
+ const res = await driver.dispatch(menuScreen.sceneId, 'closeMenu', {
355
+ from: menuScreen.moduleName,
356
+ });
357
+ if (res.code === 'intercepted') {
358
+ return { ok: false, code: res.code, sceneId: res.sceneId, message: res.message };
359
+ }
360
+ closedDrawers.add(drawerContext.drawer.sceneId);
361
+ continue;
362
+ }
363
+ if (drawerContext && needsDrawerOpen) {
364
+ const menuScreen = drawerContext.drawer.children[1];
365
+ const res = await driver.dispatch(menuScreen.sceneId, 'openMenu', {
366
+ from: menuScreen.moduleName,
367
+ });
368
+ if (!res.ok) {
369
+ return { ok: false, code: res.code, sceneId: res.sceneId, message: res.message };
370
+ }
371
+ openedDrawers.add(drawerContext.drawer.sceneId);
372
+ return { ok: true, sceneId: menuScreen.sceneId, moduleName: menuScreen.moduleName };
373
+ }
374
+ if (located.tabs) {
375
+ if (located.tabs.selectedIndex !== located.tabIndex) {
376
+ if (!switchTab) {
377
+ return { ok: false, code: 'invalid_action', message: 'Tab switching is disabled.' };
378
+ }
379
+ const activeTab = located.tabs.children[located.tabs.selectedIndex];
380
+ if (!activeTab || !containsScene(activeTab, current.sceneId)) {
381
+ return { ok: false, code: 'scene_not_found' };
382
+ }
383
+ const res = await driver.dispatch(current.sceneId, 'switchTab', {
384
+ from: located.tabs.selectedIndex,
385
+ to: located.tabIndex,
386
+ });
387
+ if (!res.ok) {
388
+ return { ok: false, code: res.code, message: res.message };
389
+ }
390
+ continue;
391
+ }
392
+ const selectedTab = located.tabs.children[located.tabIndex];
393
+ if (isStackGraph(selectedTab) &&
394
+ located.screenSceneId &&
395
+ current.sceneId !== located.screenSceneId) {
396
+ if (!popToTarget) {
397
+ return { ok: false, code: 'covered', message: 'Target scene is below tab stack top.' };
398
+ }
399
+ const res = await driver.dispatch(current.sceneId, 'popTo', {
400
+ moduleName: located.screenSceneId,
401
+ from: current.moduleName,
402
+ ...guardParam,
403
+ });
404
+ if (!res.ok) {
405
+ return { ok: false, code: res.code, sceneId: res.sceneId, message: res.message };
406
+ }
407
+ continue;
408
+ }
409
+ }
410
+ if (drawerContext &&
411
+ !drawerContext.inMenu &&
412
+ isStackGraph(drawerContext.drawer.children[0]) &&
413
+ located.screenSceneId &&
414
+ current.sceneId !== located.screenSceneId) {
415
+ if (!popToTarget) {
416
+ return { ok: false, code: 'covered', message: 'Target scene is below stack top.' };
417
+ }
418
+ const res = await driver.dispatch(current.sceneId, 'popTo', {
419
+ moduleName: located.screenSceneId,
420
+ from: current.moduleName,
421
+ ...guardParam,
422
+ });
423
+ if (!res.ok) {
424
+ return { ok: false, code: res.code, sceneId: res.sceneId, message: res.message };
425
+ }
426
+ continue;
427
+ }
428
+ return { ok: false, code: 'invalid_action', message: 'Unable to determine next reveal step.' };
429
+ }
430
+ return { ok: false, code: 'invalid_action', message: 'Reveal exceeded maximum steps.' };
431
+ }
@@ -0,0 +1,12 @@
1
+ import type { RouteGraph } from './Route';
2
+ import type { ScreenGraph } from './router/screen';
3
+ import type { TabsGraph } from './router/tabs';
4
+ export declare function containsScene(graph: RouteGraph, sceneId: string): boolean;
5
+ export declare function findSceneInGraph(graph: RouteGraph, predicate: (node: ScreenGraph) => boolean): ScreenGraph | null;
6
+ export declare function findTabsGraph(graph: RouteGraph): TabsGraph | null;
7
+ export declare function findTabIndex(tabs: TabsGraph, target: {
8
+ tabKey?: string;
9
+ moduleName?: string;
10
+ sceneId?: string;
11
+ index?: number;
12
+ }): number;
@@ -0,0 +1,68 @@
1
+ function isScreenNode(graph) {
2
+ return graph.layout === 'screen';
3
+ }
4
+ function isTabsNode(graph) {
5
+ return graph.layout === 'tabs';
6
+ }
7
+ export function containsScene(graph, sceneId) {
8
+ if (graph.sceneId === sceneId) {
9
+ return true;
10
+ }
11
+ return Boolean(graph.children?.some(child => containsScene(child, sceneId)));
12
+ }
13
+ export function findSceneInGraph(graph, predicate) {
14
+ if (isScreenNode(graph)) {
15
+ return predicate(graph) ? graph : null;
16
+ }
17
+ if (!graph.children) {
18
+ return null;
19
+ }
20
+ for (const child of graph.children) {
21
+ const found = findSceneInGraph(child, predicate);
22
+ if (found) {
23
+ return found;
24
+ }
25
+ }
26
+ return null;
27
+ }
28
+ export function findTabsGraph(graph) {
29
+ if (isTabsNode(graph)) {
30
+ return graph;
31
+ }
32
+ if (!graph.children) {
33
+ return null;
34
+ }
35
+ for (const child of graph.children) {
36
+ const found = findTabsGraph(child);
37
+ if (found) {
38
+ return found;
39
+ }
40
+ }
41
+ return null;
42
+ }
43
+ export function findTabIndex(tabs, target) {
44
+ if (target.tabKey && Array.isArray(tabs.tabKeys)) {
45
+ const byKey = tabs.tabKeys.findIndex(key => key === target.tabKey);
46
+ if (byKey >= 0) {
47
+ return byKey;
48
+ }
49
+ }
50
+ if (target.sceneId) {
51
+ const byScene = tabs.children.findIndex(child => containsScene(child, target.sceneId));
52
+ if (byScene >= 0) {
53
+ return byScene;
54
+ }
55
+ }
56
+ if (target.moduleName) {
57
+ const byModule = tabs.children.findIndex(child => Boolean(findSceneInGraph(child, node => node.moduleName === target.moduleName)));
58
+ if (byModule >= 0) {
59
+ return byModule;
60
+ }
61
+ }
62
+ if (typeof target.index === 'number' &&
63
+ target.index >= 0 &&
64
+ target.index < tabs.children.length) {
65
+ return target.index;
66
+ }
67
+ return -1;
68
+ }
@@ -4,6 +4,7 @@ import { ScreenRouteHandler } from './screen';
4
4
  import { TabsRouteHandler } from './tabs';
5
5
  import { DrawerRouteHandler } from './drawer';
6
6
  import Navigation from '../Navigation';
7
+ import { dismissPresentedLayers } from '../reveal';
7
8
  import { getRouteConfigs, getRouteConfigVersion } from '../routeConfigRegistry';
8
9
  function safeDecodeURIComponent(value) {
9
10
  try {
@@ -168,48 +169,11 @@ class Router {
168
169
  message: `No route matched path: ${path}`,
169
170
  };
170
171
  }
171
- let graphArray = await Navigation.routeGraph();
172
- if (!graphArray || graphArray.length === 0) {
173
- return {
174
- ok: false,
175
- code: 'not_ready',
176
- message: 'Route graph is empty.',
177
- };
178
- }
179
- if (graphArray.length > 1) {
180
- for (let index = graphArray.length - 1; index > 0; index--) {
181
- const { mode: layoutMode } = graphArray[index];
182
- const currentRoute = await Navigation.currentRoute();
183
- if (!currentRoute) {
184
- return {
185
- ok: false,
186
- code: 'scene_not_found',
187
- message: 'Unable to resolve current route while dismissing presented scenes.',
188
- };
189
- }
190
- const { sceneId, moduleName } = currentRoute;
191
- if (layoutMode === 'present') {
192
- const res = await Navigation.dispatch(sceneId, 'dismiss', {
193
- from: moduleName,
194
- });
195
- if (!res.ok) {
196
- return res;
197
- }
198
- }
199
- else if (layoutMode === 'modal') {
200
- const res = await Navigation.dispatch(sceneId, 'hideModal', {
201
- from: moduleName,
202
- });
203
- if (!res.ok) {
204
- return res;
205
- }
206
- }
207
- else {
208
- console.warn('尚未处理的 layout mode:' + layoutMode);
209
- }
210
- }
211
- graphArray = await Navigation.routeGraph();
172
+ const dismissed = await dismissPresentedLayers(Navigation);
173
+ if (!dismissed.ok) {
174
+ return dismissed;
212
175
  }
176
+ const graphArray = dismissed.layers;
213
177
  const routeGraph = graphArray[0];
214
178
  if (!routeGraph) {
215
179
  return {
@@ -3,6 +3,7 @@ export interface TabsGraph extends RouteGraph {
3
3
  layout: 'tabs';
4
4
  sceneId: string;
5
5
  selectedIndex: number;
6
+ tabKeys?: Array<string | null>;
6
7
  mode: LayoutMode;
7
8
  children: RouteGraph[];
8
9
  }
package/dist/store.d.ts CHANGED
@@ -2,9 +2,11 @@ import type { Navigator } from './Navigator';
2
2
  declare function addNavigator(sceneId: string, navigator: Navigator): void;
3
3
  declare function removeNavigator(sceneId: string): void;
4
4
  declare function getNavigator(sceneId: string): Navigator<string> | undefined;
5
+ declare function clear(): void;
5
6
  declare const _default: {
6
7
  addNavigator: typeof addNavigator;
7
8
  removeNavigator: typeof removeNavigator;
8
9
  getNavigator: typeof getNavigator;
10
+ clear: typeof clear;
9
11
  };
10
12
  export default _default;
package/dist/store.js CHANGED
@@ -8,8 +8,12 @@ function removeNavigator(sceneId) {
8
8
  function getNavigator(sceneId) {
9
9
  return navigators.get(sceneId);
10
10
  }
11
+ function clear() {
12
+ navigators.clear();
13
+ }
11
14
  export default {
12
15
  addNavigator,
13
16
  removeNavigator,
14
17
  getNavigator,
18
+ clear,
15
19
  };
@@ -0,0 +1,79 @@
1
+ import type { TabItemInfo } from './Options';
2
+ import type { DispatchResult, LayoutMode, LeaveAction, ResultMap, Route, RouteGraph, SceneLifecycleState, TabPressEvent } from './Route';
3
+ import type { ResultEvent, Spec as NativeEventSpec } from './NativeEvent';
4
+ import type { Spec as NativeNavigationSpec } from './NativeNavigation';
5
+ import type { DispatchParams } from './handler/DispatchCommandHandler';
6
+ import type { Navigator } from './Navigator';
7
+ export interface MockNavigationOptions {
8
+ defaultSceneId?: string;
9
+ defaultModuleName?: string;
10
+ onDispatch?: (sceneId: string, action: string, params: DispatchParams) => DispatchResult | Promise<DispatchResult>;
11
+ onSetResult?: (sceneId: string, resultCode: number, data: ResultMap | null) => void;
12
+ }
13
+ export interface MockNavigationController {
14
+ readonly dispatchCalls: ReadonlyArray<{
15
+ sceneId: string;
16
+ action: string;
17
+ params: DispatchParams;
18
+ }>;
19
+ readonly setResultCalls: ReadonlyArray<{
20
+ sceneId: string;
21
+ resultCode: number;
22
+ data: ResultMap | null;
23
+ }>;
24
+ readonly tabItemCalls: ReadonlyArray<{
25
+ sceneId: string;
26
+ items: TabItemInfo[];
27
+ }>;
28
+ readonly beforeRemoveEnabled: ReadonlySet<string>;
29
+ setCurrentRoute(route: Route | null): void;
30
+ setRouteGraph(layers: RouteGraph[]): void;
31
+ setOnDispatch(fn: MockNavigationOptions['onDispatch']): void;
32
+ setOnSetResult(fn: MockNavigationOptions['onSetResult']): void;
33
+ emitSceneState(event: {
34
+ sceneId: string;
35
+ state: SceneLifecycleState;
36
+ prevState?: SceneLifecycleState;
37
+ moduleName?: string;
38
+ mode?: LayoutMode;
39
+ presentingId?: string | null;
40
+ }): void;
41
+ emitResult(event: ResultEvent): void;
42
+ emitBeforeRemove(sceneId: string, action?: LeaveAction): void;
43
+ emitTabPress(event: TabPressEvent): void;
44
+ emitRootReset(): void;
45
+ getNavigator(sceneId: string): Navigator;
46
+ reset(): void;
47
+ }
48
+ export declare const mockNativeEvent: NativeEventSpec;
49
+ export declare const mockNativeNavigation: NativeNavigationSpec;
50
+ export interface MockNavigationModule {
51
+ readonly __esModule: true;
52
+ readonly default: import('./Navigation').Navigation;
53
+ readonly Navigator: typeof import('./Navigator').Navigator;
54
+ readonly NavigationContext: typeof import('./Navigator').NavigationContext;
55
+ readonly RESULT_OK: number;
56
+ readonly RESULT_CANCEL: number;
57
+ readonly RESULT_BLOCK: number;
58
+ readonly useNavigator: typeof import('./hooks').useNavigator;
59
+ readonly useSceneState: typeof import('./hooks').useSceneState;
60
+ readonly useIsVisible: typeof import('./hooks').useIsVisible;
61
+ readonly useBeforeRemove: typeof import('./hooks').useBeforeRemove;
62
+ readonly useVisibleEffect: typeof import('./hooks').useVisibleEffect;
63
+ readonly withNavigationItem: typeof import('./NavigationComponentWrap').withNavigationItem;
64
+ readonly defineRoute: typeof import('./defineRoutes').defineRoute;
65
+ readonly defineRoutes: typeof import('./defineRoutes').defineRoutes;
66
+ readonly containsScene: typeof import('./routeGraph').containsScene;
67
+ readonly findSceneInGraph: typeof import('./routeGraph').findSceneInGraph;
68
+ readonly findTabIndex: typeof import('./routeGraph').findTabIndex;
69
+ readonly findTabsGraph: typeof import('./routeGraph').findTabsGraph;
70
+ readonly dismissPresentedLayers: typeof import('./reveal').dismissPresentedLayers;
71
+ readonly executeReveal: typeof import('./reveal').executeReveal;
72
+ readonly __mock: MockNavigationController;
73
+ readonly [key: string]: any;
74
+ }
75
+ /**
76
+ * Thin test harness that mocks only the two native TurboModule boundaries
77
+ * (`HBDNativeNavigation` and `HBDNativeEvent`) and runs the real JS navigation layer on top.
78
+ */
79
+ export declare function createMockNavigation(options?: MockNavigationOptions): MockNavigationModule;