hybrid-navigation 5.2.0 → 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.
- package/README.md +9 -20
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +5 -13
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +0 -50
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +0 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +0 -7
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +7 -43
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +5 -39
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +62 -135
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +0 -20
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +10 -21
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +39 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +2 -16
- package/dist/NativeEvent.d.ts +1 -11
- package/dist/NativeNavigation.d.ts +7 -6
- package/dist/Navigation.d.ts +8 -22
- package/dist/Navigation.js +33 -175
- package/dist/NavigationComponentWrap.d.ts +3 -3
- package/dist/Navigator.d.ts +4 -5
- package/dist/Navigator.js +13 -37
- package/dist/Options.d.ts +2 -2
- package/dist/Route.d.ts +10 -35
- package/dist/handler/DispatchCommandHandler.d.ts +3 -18
- package/dist/handler/DispatchCommandHandler.js +17 -64
- package/dist/handler/LayoutCommandHandler.d.ts +2 -3
- package/dist/handler/LayoutCommandHandler.js +0 -3
- package/dist/handler/LeaveGuardHandler.d.ts +3 -3
- package/dist/handler/LeaveGuardHandler.js +57 -32
- package/dist/handler/LifecycleEventHandler.d.ts +2 -14
- package/dist/handler/LifecycleEventHandler.js +2 -79
- package/dist/handler/ResultEventHandler.d.ts +0 -1
- package/dist/handler/ResultEventHandler.js +0 -3
- package/dist/handler/SceneExitHandler.d.ts +3 -0
- package/dist/handler/SceneExitHandler.js +76 -0
- package/dist/hooks.d.ts +0 -3
- package/dist/hooks.js +21 -46
- package/dist/index.d.ts +1 -12
- package/dist/index.js +0 -3
- package/dist/router/index.d.ts +0 -1
- package/dist/router/index.js +43 -11
- package/dist/router/stack.d.ts +1 -1
- package/dist/sceneCoverage.d.ts +2 -0
- package/dist/sceneCoverage.js +25 -0
- package/dist/store.d.ts +0 -2
- package/dist/store.js +0 -4
- package/ios/HBDGlobalStyle.h +0 -1
- package/ios/HBDGlobalStyle.mm +0 -7
- package/ios/HybridNavigation.h +0 -1
- package/ios/Navigator/HBDScreenNavigator.mm +89 -237
- package/ios/Navigator/HBDStackNavigator.mm +1 -1
- package/ios/Navigator/HBDTabNavigator.mm +15 -30
- package/ios/React/HBDNativeNavigation.mm +4 -31
- package/ios/React/HBDReactBridgeManager.h +0 -5
- package/ios/React/HBDReactBridgeManager.mm +0 -17
- package/ios/ViewController/HBDReactViewController.h +1 -1
- package/ios/ViewController/HBDReactViewController.mm +34 -9
- package/ios/ViewController/HBDTabBarController.h +2 -11
- package/ios/ViewController/HBDTabBarController.mm +14 -170
- package/ios/ViewController/HBDViewController.h +0 -1
- package/ios/ViewController/HBDViewController.mm +9 -57
- package/ios/ViewController/UIViewController+HBD.h +2 -0
- package/ios/ViewController/UIViewController+HBD.mm +5 -0
- package/package.json +1 -3
- package/src/NativeEvent.ts +1 -12
- package/src/NativeNavigation.ts +8 -7
- package/src/Navigation.ts +50 -281
- package/src/NavigationComponentWrap.tsx +3 -11
- package/src/Navigator.ts +15 -46
- package/src/Options.ts +2 -3
- package/src/Route.ts +13 -56
- package/src/handler/DispatchCommandHandler.ts +29 -111
- package/src/handler/LayoutCommandHandler.ts +2 -6
- package/src/handler/LeaveGuardHandler.ts +65 -32
- package/src/handler/LifecycleEventHandler.ts +22 -122
- package/src/handler/ResultEventHandler.ts +0 -6
- package/src/handler/SceneExitHandler.ts +86 -0
- package/src/hooks.ts +18 -53
- package/src/index.ts +0 -14
- package/src/router/index.ts +45 -12
- package/src/router/stack.ts +1 -1
- package/src/sceneCoverage.ts +30 -0
- package/src/store.ts +0 -5
- package/dist/defineRoutes.d.ts +0 -19
- package/dist/defineRoutes.js +0 -6
- package/dist/handler/PresentationCoordinator.d.ts +0 -39
- package/dist/handler/PresentationCoordinator.js +0 -673
- package/dist/handler/TabEventHandler.d.ts +0 -8
- package/dist/handler/TabEventHandler.js +0 -25
- package/dist/reveal.d.ts +0 -46
- package/dist/reveal.js +0 -431
- package/dist/routeGraph.d.ts +0 -12
- package/dist/routeGraph.js +0 -68
- package/dist/testing.d.ts +0 -82
- package/dist/testing.js +0 -253
- package/ios/ViewController/HBDTabBarRenderer.h +0 -28
- package/src/defineRoutes.ts +0 -46
- package/src/handler/PresentationCoordinator.ts +0 -806
- package/src/handler/TabEventHandler.ts +0 -31
- package/src/reveal.ts +0 -565
- package/src/routeGraph.ts +0 -87
- package/src/testing.ts +0 -402
- package/testing.d.ts +0 -1
- package/testing.js +0 -3
|
@@ -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();
|
package/src/reveal.ts
DELETED
|
@@ -1,565 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
DispatchResult,
|
|
3
|
-
DispatchResultCode,
|
|
4
|
-
NavigationSnapshot,
|
|
5
|
-
Route,
|
|
6
|
-
RouteGraph,
|
|
7
|
-
RouteName,
|
|
8
|
-
} from './Route';
|
|
9
|
-
import { containsScene, findSceneInGraph, findTabIndex, findTabsGraph } from './routeGraph';
|
|
10
|
-
import type { DrawerGraph } from './router/drawer';
|
|
11
|
-
import type { ScreenGraph } from './router/screen';
|
|
12
|
-
import type { StackGraph } from './router/stack';
|
|
13
|
-
import type { TabsGraph } from './router/tabs';
|
|
14
|
-
|
|
15
|
-
function isDrawerGraph(graph: RouteGraph): graph is DrawerGraph {
|
|
16
|
-
return graph.layout === 'drawer';
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function isScreenGraph(graph: RouteGraph): graph is ScreenGraph {
|
|
20
|
-
return graph.layout === 'screen';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function isStackGraph(graph: RouteGraph): graph is StackGraph {
|
|
24
|
-
return graph.layout === 'stack';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function findContainingDrawer(
|
|
28
|
-
graph: RouteGraph,
|
|
29
|
-
sceneId: string,
|
|
30
|
-
): { drawer: DrawerGraph; inMenu: boolean } | null {
|
|
31
|
-
if (isDrawerGraph(graph)) {
|
|
32
|
-
const [content, menu] = graph.children;
|
|
33
|
-
if (menu && containsScene(menu, sceneId)) {
|
|
34
|
-
return { drawer: graph, inMenu: true };
|
|
35
|
-
}
|
|
36
|
-
if (content && containsScene(content, sceneId)) {
|
|
37
|
-
const nested = findContainingDrawer(content, sceneId);
|
|
38
|
-
return nested ?? { drawer: graph, inMenu: false };
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (!graph.children) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
for (const child of graph.children) {
|
|
45
|
-
const found = findContainingDrawer(child, sceneId);
|
|
46
|
-
if (found) {
|
|
47
|
-
return found;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface RevealTarget {
|
|
54
|
-
sceneId?: string;
|
|
55
|
-
moduleName?: RouteName | (string & {});
|
|
56
|
-
tabKey?: string;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface RevealOptions {
|
|
60
|
-
dismissModals?: boolean;
|
|
61
|
-
popToTarget?: boolean;
|
|
62
|
-
switchTab?: boolean;
|
|
63
|
-
/** Skip beforeRemove guards during reveal steps (e.g. forced deep-link reset). Default false. */
|
|
64
|
-
bypassGuards?: boolean;
|
|
65
|
-
maxSteps?: number;
|
|
66
|
-
shouldContinue?: () => boolean | Promise<boolean>;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export type RevealResult =
|
|
70
|
-
| { ok: true; sceneId: string; moduleName?: string }
|
|
71
|
-
| {
|
|
72
|
-
ok: false;
|
|
73
|
-
code: DispatchResultCode | 'aborted';
|
|
74
|
-
sceneId?: string;
|
|
75
|
-
message?: string;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export interface RevealDriver {
|
|
79
|
-
routeGraph(): Promise<RouteGraph[]>;
|
|
80
|
-
currentRoute(): Promise<Route | null>;
|
|
81
|
-
navigationSnapshot?(): Promise<NavigationSnapshot>;
|
|
82
|
-
dispatch(sceneId: string, action: string, params?: Record<string, any>): Promise<DispatchResult>;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
interface LocatedTarget {
|
|
86
|
-
layerIndex: number;
|
|
87
|
-
tabs: TabsGraph | null;
|
|
88
|
-
tabIndex: number;
|
|
89
|
-
screenSceneId?: string;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function locateTargetInLayer(layer: RouteGraph, target: RevealTarget): Omit<LocatedTarget, 'layerIndex'> | null {
|
|
93
|
-
if (target.sceneId) {
|
|
94
|
-
if (!containsScene(layer, target.sceneId)) {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
const tabs = findTabsGraph(layer);
|
|
98
|
-
const tabIndex = tabs ? findTabIndex(tabs, { sceneId: target.sceneId }) : -1;
|
|
99
|
-
return { tabs: tabIndex >= 0 ? tabs : null, tabIndex, screenSceneId: target.sceneId };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (target.tabKey) {
|
|
103
|
-
const tabs = findTabsGraph(layer);
|
|
104
|
-
if (tabs) {
|
|
105
|
-
const tabIndex = findTabIndex(tabs, { tabKey: target.tabKey, moduleName: target.moduleName });
|
|
106
|
-
if (tabIndex >= 0) {
|
|
107
|
-
const tabChild = tabs.children[tabIndex];
|
|
108
|
-
if (target.moduleName) {
|
|
109
|
-
const screen = findSceneInGraph(tabChild, node => node.moduleName === target.moduleName);
|
|
110
|
-
if (screen) {
|
|
111
|
-
return { tabs, tabIndex, screenSceneId: screen.sceneId };
|
|
112
|
-
}
|
|
113
|
-
} else {
|
|
114
|
-
const screen = findSceneInGraph(tabChild, () => true);
|
|
115
|
-
return { tabs, tabIndex, screenSceneId: screen?.sceneId ?? tabChild.sceneId };
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
if (!target.moduleName) {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (target.moduleName) {
|
|
125
|
-
const tabs = findTabsGraph(layer);
|
|
126
|
-
if (tabs) {
|
|
127
|
-
const tabIndex = findTabIndex(tabs, { moduleName: target.moduleName });
|
|
128
|
-
if (tabIndex >= 0) {
|
|
129
|
-
const screen = findSceneInGraph(
|
|
130
|
-
tabs.children[tabIndex],
|
|
131
|
-
node => node.moduleName === target.moduleName,
|
|
132
|
-
);
|
|
133
|
-
if (screen) {
|
|
134
|
-
return { tabs, tabIndex, screenSceneId: screen.sceneId };
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
const screen = findSceneInGraph(layer, node => node.moduleName === target.moduleName);
|
|
139
|
-
if (screen) {
|
|
140
|
-
return { tabs: null, tabIndex: -1, screenSceneId: screen.sceneId };
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function locateTarget(layers: RouteGraph[], target: RevealTarget): LocatedTarget | null {
|
|
148
|
-
for (let i = layers.length - 1; i >= 0; i--) {
|
|
149
|
-
const located = locateTargetInLayer(layers[i], target);
|
|
150
|
-
if (located) {
|
|
151
|
-
return { layerIndex: i, ...located };
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function isAlreadyRevealed(
|
|
158
|
-
layers: RouteGraph[],
|
|
159
|
-
current: Route,
|
|
160
|
-
located: LocatedTarget,
|
|
161
|
-
target: RevealTarget,
|
|
162
|
-
): boolean {
|
|
163
|
-
if (located.layerIndex !== layers.length - 1) {
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
const layer = layers[located.layerIndex];
|
|
167
|
-
if (located.tabs) {
|
|
168
|
-
if (isStackGraph(layer) && layer.children[layer.children.length - 1] !== located.tabs) {
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
if (located.tabs.selectedIndex !== located.tabIndex) {
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
const activeTab = located.tabs.children[located.tabIndex];
|
|
175
|
-
if (target.sceneId) {
|
|
176
|
-
return current.sceneId === target.sceneId;
|
|
177
|
-
}
|
|
178
|
-
if (target.moduleName) {
|
|
179
|
-
return (
|
|
180
|
-
current.moduleName === target.moduleName &&
|
|
181
|
-
(!located.screenSceneId || current.sceneId === located.screenSceneId)
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
if (isScreenGraph(activeTab)) {
|
|
185
|
-
return current.sceneId === activeTab.sceneId;
|
|
186
|
-
}
|
|
187
|
-
return containsScene(activeTab, current.sceneId);
|
|
188
|
-
}
|
|
189
|
-
if (target.sceneId) {
|
|
190
|
-
return current.sceneId === target.sceneId;
|
|
191
|
-
}
|
|
192
|
-
if (target.moduleName) {
|
|
193
|
-
return (
|
|
194
|
-
current.moduleName === target.moduleName &&
|
|
195
|
-
(!located.screenSceneId || current.sceneId === located.screenSceneId)
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export type DismissPresentedLayersResult =
|
|
202
|
-
| { ok: true; layers: RouteGraph[] }
|
|
203
|
-
| {
|
|
204
|
-
ok: false;
|
|
205
|
-
code: DispatchResultCode;
|
|
206
|
-
sceneId?: string;
|
|
207
|
-
message?: string;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
/** Dismiss all presented/modal layers above the root layer with rootGeneration and loop protection. */
|
|
211
|
-
export async function dismissPresentedLayers(
|
|
212
|
-
driver: RevealDriver,
|
|
213
|
-
options: { maxSteps?: number; bypassGuards?: boolean } = {},
|
|
214
|
-
): Promise<DismissPresentedLayersResult> {
|
|
215
|
-
const { maxSteps = 12, bypassGuards = false } = options;
|
|
216
|
-
const visited = new Set<string>();
|
|
217
|
-
let initialRootGeneration: number | undefined;
|
|
218
|
-
|
|
219
|
-
for (let step = 0; step < maxSteps; step++) {
|
|
220
|
-
let layers: RouteGraph[];
|
|
221
|
-
let current: Route | null;
|
|
222
|
-
let rootGeneration: number | undefined;
|
|
223
|
-
if (driver.navigationSnapshot) {
|
|
224
|
-
const snapshot = await driver.navigationSnapshot();
|
|
225
|
-
layers = snapshot.layers;
|
|
226
|
-
current = snapshot.currentRoute;
|
|
227
|
-
rootGeneration = snapshot.rootGeneration;
|
|
228
|
-
} else {
|
|
229
|
-
[layers, current] = await Promise.all([
|
|
230
|
-
driver.routeGraph(),
|
|
231
|
-
driver.currentRoute(),
|
|
232
|
-
]);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (rootGeneration !== undefined) {
|
|
236
|
-
if (initialRootGeneration === undefined) {
|
|
237
|
-
initialRootGeneration = rootGeneration;
|
|
238
|
-
} else if (rootGeneration !== initialRootGeneration) {
|
|
239
|
-
return {
|
|
240
|
-
ok: false,
|
|
241
|
-
code: 'superseded',
|
|
242
|
-
message: 'Root layout changed while dismissing presented scenes.',
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (!Array.isArray(layers) || layers.length === 0) {
|
|
248
|
-
return { ok: false, code: 'not_ready', message: 'Route graph is empty.' };
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (layers.length <= 1) {
|
|
252
|
-
return { ok: true, layers };
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (!current?.sceneId) {
|
|
256
|
-
return {
|
|
257
|
-
ok: false,
|
|
258
|
-
code: 'scene_not_found',
|
|
259
|
-
message: 'Unable to resolve current route while dismissing presented scenes.',
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const topLayer = layers[layers.length - 1];
|
|
264
|
-
if (!containsScene(topLayer, current.sceneId)) {
|
|
265
|
-
return { ok: false, code: 'scene_not_found', message: 'Current scene is not in top layer.' };
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
const stepKey = `${layers.length}:${current.sceneId}`;
|
|
269
|
-
if (visited.has(stepKey)) {
|
|
270
|
-
return {
|
|
271
|
-
ok: false,
|
|
272
|
-
code: 'invalid_action',
|
|
273
|
-
message: 'Dismissing presented layers did not advance.',
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
visited.add(stepKey);
|
|
277
|
-
|
|
278
|
-
const action =
|
|
279
|
-
topLayer.mode === 'modal'
|
|
280
|
-
? 'hideModal'
|
|
281
|
-
: topLayer.mode === 'present'
|
|
282
|
-
? 'dismiss'
|
|
283
|
-
: null;
|
|
284
|
-
if (!action) {
|
|
285
|
-
return {
|
|
286
|
-
ok: false,
|
|
287
|
-
code: 'invalid_action',
|
|
288
|
-
message: `Unsupported layer mode: ${topLayer.mode}`,
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
const res = await driver.dispatch(current.sceneId, action, {
|
|
293
|
-
from: current.moduleName,
|
|
294
|
-
target: 'self' as const,
|
|
295
|
-
...(bypassGuards ? { bypassBeforeRemove: true } : {}),
|
|
296
|
-
});
|
|
297
|
-
if (!res.ok) {
|
|
298
|
-
return { ok: false, code: res.code, sceneId: res.sceneId, message: res.message };
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
return {
|
|
303
|
-
ok: false,
|
|
304
|
-
code: 'invalid_action',
|
|
305
|
-
message: 'Dismissing presented layers exceeded maximum navigation steps.',
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
export async function executeReveal(
|
|
310
|
-
driver: RevealDriver,
|
|
311
|
-
target: RevealTarget,
|
|
312
|
-
options: RevealOptions = {},
|
|
313
|
-
): Promise<RevealResult> {
|
|
314
|
-
const {
|
|
315
|
-
dismissModals = true,
|
|
316
|
-
popToTarget = true,
|
|
317
|
-
switchTab = true,
|
|
318
|
-
bypassGuards = false,
|
|
319
|
-
maxSteps = 12,
|
|
320
|
-
shouldContinue,
|
|
321
|
-
} = options;
|
|
322
|
-
const guardParam = bypassGuards ? { bypassBeforeRemove: true } : {};
|
|
323
|
-
|
|
324
|
-
const visited = new Set<string>();
|
|
325
|
-
const closedDrawers = new Set<string>();
|
|
326
|
-
const openedDrawers = new Set<string>();
|
|
327
|
-
let initialRootGeneration: number | undefined;
|
|
328
|
-
|
|
329
|
-
for (let step = 0; step < maxSteps; step++) {
|
|
330
|
-
if (shouldContinue && !(await shouldContinue())) {
|
|
331
|
-
return { ok: false, code: 'aborted' };
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
let layers: RouteGraph[];
|
|
335
|
-
let current: Route | null;
|
|
336
|
-
let rootGeneration: number | undefined;
|
|
337
|
-
if (driver.navigationSnapshot) {
|
|
338
|
-
const snapshot = await driver.navigationSnapshot();
|
|
339
|
-
layers = snapshot.layers;
|
|
340
|
-
current = snapshot.currentRoute;
|
|
341
|
-
rootGeneration = snapshot.rootGeneration;
|
|
342
|
-
} else {
|
|
343
|
-
[layers, current] = await Promise.all([
|
|
344
|
-
driver.routeGraph(),
|
|
345
|
-
driver.currentRoute(),
|
|
346
|
-
]);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
if (shouldContinue && !(await shouldContinue())) {
|
|
350
|
-
return { ok: false, code: 'aborted' };
|
|
351
|
-
}
|
|
352
|
-
if (rootGeneration !== undefined) {
|
|
353
|
-
if (initialRootGeneration === undefined) {
|
|
354
|
-
initialRootGeneration = rootGeneration;
|
|
355
|
-
} else if (rootGeneration !== initialRootGeneration) {
|
|
356
|
-
return {
|
|
357
|
-
ok: false,
|
|
358
|
-
code: 'superseded',
|
|
359
|
-
message: 'Root layout changed during reveal.',
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
if (!Array.isArray(layers) || layers.length === 0 || !current?.sceneId) {
|
|
364
|
-
return { ok: false, code: 'not_ready', message: 'Route graph or current route is unavailable.' };
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
const located = locateTarget(layers, target);
|
|
368
|
-
if (!located) {
|
|
369
|
-
return {
|
|
370
|
-
ok: false,
|
|
371
|
-
code: 'scene_not_found',
|
|
372
|
-
message: 'Target scene or tab not found in route graph.',
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
const targetLayer = layers[located.layerIndex];
|
|
377
|
-
const targetSceneForDrawer = located.screenSceneId ?? located.tabs?.sceneId;
|
|
378
|
-
const drawerContext = targetSceneForDrawer
|
|
379
|
-
? findContainingDrawer(targetLayer, targetSceneForDrawer)
|
|
380
|
-
: null;
|
|
381
|
-
const needsDrawerClose =
|
|
382
|
-
Boolean(drawerContext) &&
|
|
383
|
-
!drawerContext!.inMenu &&
|
|
384
|
-
!closedDrawers.has(drawerContext!.drawer.sceneId);
|
|
385
|
-
const needsDrawerOpen =
|
|
386
|
-
Boolean(drawerContext) &&
|
|
387
|
-
drawerContext!.inMenu &&
|
|
388
|
-
!openedDrawers.has(drawerContext!.drawer.sceneId);
|
|
389
|
-
|
|
390
|
-
if (
|
|
391
|
-
!needsDrawerClose &&
|
|
392
|
-
!needsDrawerOpen &&
|
|
393
|
-
isAlreadyRevealed(layers, current, located, target)
|
|
394
|
-
) {
|
|
395
|
-
return { ok: true, sceneId: current.sceneId, moduleName: current.moduleName };
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
const stepKey = `${layers.length}:${current.sceneId}:${located.tabs?.selectedIndex ?? -1}:${needsDrawerClose ? 1 : 0}:${needsDrawerOpen ? 1 : 0}`;
|
|
399
|
-
if (visited.has(stepKey)) {
|
|
400
|
-
return {
|
|
401
|
-
ok: false,
|
|
402
|
-
code: 'invalid_action',
|
|
403
|
-
message: 'Reveal did not advance after previous navigation step.',
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
visited.add(stepKey);
|
|
407
|
-
|
|
408
|
-
if (layers.length - 1 > located.layerIndex) {
|
|
409
|
-
if (!dismissModals) {
|
|
410
|
-
return { ok: false, code: 'covered', message: 'Target is covered by a presented layer.' };
|
|
411
|
-
}
|
|
412
|
-
const topLayer = layers[layers.length - 1];
|
|
413
|
-
if (!containsScene(topLayer, current.sceneId)) {
|
|
414
|
-
return { ok: false, code: 'scene_not_found', message: 'Current scene is not in top layer.' };
|
|
415
|
-
}
|
|
416
|
-
const action =
|
|
417
|
-
topLayer.mode === 'modal'
|
|
418
|
-
? 'hideModal'
|
|
419
|
-
: topLayer.mode === 'present'
|
|
420
|
-
? 'dismiss'
|
|
421
|
-
: null;
|
|
422
|
-
if (!action) {
|
|
423
|
-
return { ok: false, code: 'invalid_action', message: `Unsupported layer mode: ${topLayer.mode}` };
|
|
424
|
-
}
|
|
425
|
-
const res = await driver.dispatch(current.sceneId, action, {
|
|
426
|
-
from: current.moduleName,
|
|
427
|
-
target: 'self' as const,
|
|
428
|
-
...guardParam,
|
|
429
|
-
});
|
|
430
|
-
if (!res.ok) {
|
|
431
|
-
return { ok: false, code: res.code, sceneId: res.sceneId, message: res.message };
|
|
432
|
-
}
|
|
433
|
-
continue;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
if (isStackGraph(targetLayer)) {
|
|
437
|
-
const stackTop = targetLayer.children[targetLayer.children.length - 1];
|
|
438
|
-
const targetSceneInStack = located.screenSceneId ?? located.tabs?.sceneId;
|
|
439
|
-
const targetChild = targetSceneInStack
|
|
440
|
-
? targetLayer.children.find(child => containsScene(child, targetSceneInStack))
|
|
441
|
-
: undefined;
|
|
442
|
-
if (targetChild && stackTop !== targetChild) {
|
|
443
|
-
if (!popToTarget) {
|
|
444
|
-
return {
|
|
445
|
-
ok: false,
|
|
446
|
-
code: 'covered',
|
|
447
|
-
message: located.tabs
|
|
448
|
-
? 'Target tabs are covered by stack screens.'
|
|
449
|
-
: 'Target scene is below stack top.',
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
if (!stackTop || !containsScene(stackTop, current.sceneId)) {
|
|
453
|
-
return { ok: false, code: 'scene_not_found' };
|
|
454
|
-
}
|
|
455
|
-
const isContainerRoot =
|
|
456
|
-
!isScreenGraph(targetChild) && targetLayer.children[0] === targetChild;
|
|
457
|
-
const res = isContainerRoot
|
|
458
|
-
? await driver.dispatch(current.sceneId, 'popToRoot', {
|
|
459
|
-
from: current.moduleName,
|
|
460
|
-
...guardParam,
|
|
461
|
-
})
|
|
462
|
-
: await driver.dispatch(current.sceneId, 'popTo', {
|
|
463
|
-
moduleName: isScreenGraph(targetChild)
|
|
464
|
-
? (located.screenSceneId ?? targetChild.sceneId)
|
|
465
|
-
: targetChild.sceneId,
|
|
466
|
-
from: current.moduleName,
|
|
467
|
-
...guardParam,
|
|
468
|
-
});
|
|
469
|
-
if (!res.ok) {
|
|
470
|
-
return { ok: false, code: res.code, sceneId: res.sceneId, message: res.message };
|
|
471
|
-
}
|
|
472
|
-
continue;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
if (drawerContext && needsDrawerClose) {
|
|
477
|
-
const menuScreen = drawerContext.drawer.children[1];
|
|
478
|
-
const res = await driver.dispatch(menuScreen.sceneId, 'closeMenu', {
|
|
479
|
-
from: menuScreen.moduleName,
|
|
480
|
-
});
|
|
481
|
-
if (res.code === 'intercepted') {
|
|
482
|
-
return { ok: false, code: res.code, sceneId: res.sceneId, message: res.message };
|
|
483
|
-
}
|
|
484
|
-
closedDrawers.add(drawerContext.drawer.sceneId);
|
|
485
|
-
continue;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
if (drawerContext && needsDrawerOpen) {
|
|
489
|
-
const menuScreen = drawerContext.drawer.children[1];
|
|
490
|
-
const res = await driver.dispatch(menuScreen.sceneId, 'openMenu', {
|
|
491
|
-
from: menuScreen.moduleName,
|
|
492
|
-
});
|
|
493
|
-
if (!res.ok) {
|
|
494
|
-
return { ok: false, code: res.code, sceneId: res.sceneId, message: res.message };
|
|
495
|
-
}
|
|
496
|
-
openedDrawers.add(drawerContext.drawer.sceneId);
|
|
497
|
-
return { ok: true, sceneId: menuScreen.sceneId, moduleName: menuScreen.moduleName };
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
if (located.tabs) {
|
|
501
|
-
if (located.tabs.selectedIndex !== located.tabIndex) {
|
|
502
|
-
if (!switchTab) {
|
|
503
|
-
return { ok: false, code: 'invalid_action', message: 'Tab switching is disabled.' };
|
|
504
|
-
}
|
|
505
|
-
const activeTab = located.tabs.children[located.tabs.selectedIndex];
|
|
506
|
-
if (!activeTab || !containsScene(activeTab, current.sceneId)) {
|
|
507
|
-
return { ok: false, code: 'scene_not_found' };
|
|
508
|
-
}
|
|
509
|
-
const res = await driver.dispatch(current.sceneId, 'switchTab', {
|
|
510
|
-
from: located.tabs.selectedIndex,
|
|
511
|
-
to: located.tabIndex,
|
|
512
|
-
});
|
|
513
|
-
if (!res.ok) {
|
|
514
|
-
return { ok: false, code: res.code, message: res.message };
|
|
515
|
-
}
|
|
516
|
-
continue;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
const selectedTab = located.tabs.children[located.tabIndex];
|
|
520
|
-
if (
|
|
521
|
-
isStackGraph(selectedTab) &&
|
|
522
|
-
located.screenSceneId &&
|
|
523
|
-
current.sceneId !== located.screenSceneId
|
|
524
|
-
) {
|
|
525
|
-
if (!popToTarget) {
|
|
526
|
-
return { ok: false, code: 'covered', message: 'Target scene is below tab stack top.' };
|
|
527
|
-
}
|
|
528
|
-
const res = await driver.dispatch(current.sceneId, 'popTo', {
|
|
529
|
-
moduleName: located.screenSceneId,
|
|
530
|
-
from: current.moduleName,
|
|
531
|
-
...guardParam,
|
|
532
|
-
});
|
|
533
|
-
if (!res.ok) {
|
|
534
|
-
return { ok: false, code: res.code, sceneId: res.sceneId, message: res.message };
|
|
535
|
-
}
|
|
536
|
-
continue;
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
if (
|
|
541
|
-
drawerContext &&
|
|
542
|
-
!drawerContext.inMenu &&
|
|
543
|
-
isStackGraph(drawerContext.drawer.children[0]) &&
|
|
544
|
-
located.screenSceneId &&
|
|
545
|
-
current.sceneId !== located.screenSceneId
|
|
546
|
-
) {
|
|
547
|
-
if (!popToTarget) {
|
|
548
|
-
return { ok: false, code: 'covered', message: 'Target scene is below stack top.' };
|
|
549
|
-
}
|
|
550
|
-
const res = await driver.dispatch(current.sceneId, 'popTo', {
|
|
551
|
-
moduleName: located.screenSceneId,
|
|
552
|
-
from: current.moduleName,
|
|
553
|
-
...guardParam,
|
|
554
|
-
});
|
|
555
|
-
if (!res.ok) {
|
|
556
|
-
return { ok: false, code: res.code, sceneId: res.sceneId, message: res.message };
|
|
557
|
-
}
|
|
558
|
-
continue;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
return { ok: false, code: 'invalid_action', message: 'Unable to determine next reveal step.' };
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
return { ok: false, code: 'invalid_action', message: 'Reveal exceeded maximum steps.' };
|
|
565
|
-
}
|
package/src/routeGraph.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { RouteGraph } from './Route';
|
|
2
|
-
import type { ScreenGraph } from './router/screen';
|
|
3
|
-
import type { TabsGraph } from './router/tabs';
|
|
4
|
-
|
|
5
|
-
function isScreenNode(graph: RouteGraph): graph is ScreenGraph {
|
|
6
|
-
return graph.layout === 'screen';
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function isTabsNode(graph: RouteGraph): graph is TabsGraph {
|
|
10
|
-
return graph.layout === 'tabs';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function containsScene(graph: RouteGraph, sceneId: string): boolean {
|
|
14
|
-
if (graph.sceneId === sceneId) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
return Boolean(graph.children?.some(child => containsScene(child, sceneId)));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function findSceneInGraph(
|
|
21
|
-
graph: RouteGraph,
|
|
22
|
-
predicate: (node: ScreenGraph) => boolean,
|
|
23
|
-
): ScreenGraph | null {
|
|
24
|
-
if (isScreenNode(graph)) {
|
|
25
|
-
return predicate(graph) ? graph : null;
|
|
26
|
-
}
|
|
27
|
-
if (!graph.children) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
for (const child of graph.children) {
|
|
31
|
-
const found = findSceneInGraph(child, predicate);
|
|
32
|
-
if (found) {
|
|
33
|
-
return found;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function findTabsGraph(graph: RouteGraph): TabsGraph | null {
|
|
40
|
-
if (isTabsNode(graph)) {
|
|
41
|
-
return graph;
|
|
42
|
-
}
|
|
43
|
-
if (!graph.children) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
for (const child of graph.children) {
|
|
47
|
-
const found = findTabsGraph(child);
|
|
48
|
-
if (found) {
|
|
49
|
-
return found;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function findTabIndex(
|
|
56
|
-
tabs: TabsGraph,
|
|
57
|
-
target: { tabKey?: string; moduleName?: string; sceneId?: string; index?: number },
|
|
58
|
-
): number {
|
|
59
|
-
if (target.tabKey && Array.isArray(tabs.tabKeys)) {
|
|
60
|
-
const byKey = tabs.tabKeys.findIndex(key => key === target.tabKey);
|
|
61
|
-
if (byKey >= 0) {
|
|
62
|
-
return byKey;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (target.sceneId) {
|
|
66
|
-
const byScene = tabs.children.findIndex(child => containsScene(child, target.sceneId!));
|
|
67
|
-
if (byScene >= 0) {
|
|
68
|
-
return byScene;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (target.moduleName) {
|
|
72
|
-
const byModule = tabs.children.findIndex(child =>
|
|
73
|
-
Boolean(findSceneInGraph(child, node => node.moduleName === target.moduleName)),
|
|
74
|
-
);
|
|
75
|
-
if (byModule >= 0) {
|
|
76
|
-
return byModule;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (
|
|
80
|
-
typeof target.index === 'number' &&
|
|
81
|
-
target.index >= 0 &&
|
|
82
|
-
target.index < tabs.children.length
|
|
83
|
-
) {
|
|
84
|
-
return target.index;
|
|
85
|
-
}
|
|
86
|
-
return -1;
|
|
87
|
-
}
|