fix(mobile): keep native screens ordered during stack pops (#17231)
This commit is contained in:
1 parent
a65b43892f
commit
a6ec88f7a7
3 files changed
+39
-11
No files matched your search
@@ -181,7 +181,14 @@ export function V5CardStackView(props: V5StackViewProps) {
|
||||
>
|
||||
<NavigationContext value={descriptor.navigation}>
|
||||
<NavigationRouteContext value={descriptor.route}>
|
||||
<V5StackHeader options={descriptor.options} canGoBack={index > 0} />
|
||||
<V5StackHeader
|
||||
options={descriptor.options}
|
||||
canGoBack={
|
||||
attached
|
||||
? props.state.routes.findIndex((current) => current.key === route.key) > 0
|
||||
: index > 0
|
||||
}
|
||||
/>
|
||||
<NativeColumnContent>{descriptor.render()}</NativeColumnContent>
|
||||
</NavigationRouteContext>
|
||||
</NavigationContext>
|
||||
|
||||
@@ -143,21 +143,41 @@ describe("v5 stack handoff", () => {
|
||||
});
|
||||
it("still retains an unfinished JS pop beside a completed native pop", () => {
|
||||
expect(reconcileStackScreens([home, thread, files], [home], new Set([files.key]))).toEqual([
|
||||
thread,
|
||||
home,
|
||||
thread,
|
||||
]);
|
||||
});
|
||||
it("retains removed native screens through a pop followed immediately by a push", () => {
|
||||
const popped = reconcileStackScreens([home, thread, files], [home, thread]);
|
||||
const next = { ...files, key: "new-files" };
|
||||
const screens = reconcileStackScreens(popped, [home, thread, next]);
|
||||
expect(screens.map((route) => route.key)).toEqual(["files", "home", "thread", "new-files"]);
|
||||
expect(screens.map((route) => route.key)).toEqual(["home", "thread", "files", "new-files"]);
|
||||
expect(screens.filter((route) => [home, thread, next].includes(route))).toEqual([
|
||||
home,
|
||||
thread,
|
||||
next,
|
||||
]);
|
||||
expect(screens[0]).toBe(files);
|
||||
expect(screens[2]).toBe(files);
|
||||
});
|
||||
it("keeps the root and outgoing settings page in place until the JS pop finishes", () => {
|
||||
const environments = { ...files, key: "environments", name: "SettingsEnvironments" };
|
||||
const popped = reconcileStackScreens([settings, environments], [settings]);
|
||||
expect(popped).toEqual([settings, environments]);
|
||||
expect(reconcileStackScreens(popped, [settings])).toEqual(popped);
|
||||
const next = { ...environments, key: "next-environments" };
|
||||
expect(reconcileStackScreens(popped, [settings, next])).toEqual([settings, environments, next]);
|
||||
expect(reconcileStackScreens(popped, [settings], new Set([environments.key]))).toEqual([
|
||||
settings,
|
||||
]);
|
||||
});
|
||||
it("retains a multi-page pop in order without changing the active router order", () => {
|
||||
const replacement = { ...thread, key: "replacement" };
|
||||
const screens = reconcileStackScreens([home, thread, files], [home, replacement]);
|
||||
expect(screens).toEqual([home, thread, files, replacement]);
|
||||
expect(screens.filter((route) => route === home || route === replacement)).toEqual([
|
||||
home,
|
||||
replacement,
|
||||
]);
|
||||
});
|
||||
it("updates params without retaining duplicate copies of the same screen", () => {
|
||||
const updated = { ...thread, params: { threadId: "another-thread" } };
|
||||
|
||||
@@ -57,17 +57,18 @@ export function partitionStackPresentations<T>(
|
||||
return groups;
|
||||
}
|
||||
|
||||
/** Preserve UIKit's outgoing screens, before newly pushed screens, until dismissal. */
|
||||
/** Keep outgoing screens in place until dismissal; Fabric moves enqueue native pop/push operations. */
|
||||
export function reconcileStackScreens<T extends { readonly key: string }>(
|
||||
previous: readonly T[],
|
||||
current: readonly T[],
|
||||
completedNativeDismissals: ReadonlySet<string> = new Set(),
|
||||
): T[] {
|
||||
const active = new Set(current.map((route) => route.key));
|
||||
return [
|
||||
...previous.filter(
|
||||
(route) => !active.has(route.key) && !completedNativeDismissals.has(route.key),
|
||||
),
|
||||
...current,
|
||||
];
|
||||
const screens = [...current];
|
||||
previous.forEach((route, index) => {
|
||||
if (!active.has(route.key) && !completedNativeDismissals.has(route.key)) {
|
||||
screens.splice(Math.min(index, screens.length), 0, route);
|
||||
}
|
||||
});
|
||||
return screens;
|
||||
}
|
||||
Reference in new issue
Block a user