Keep sidebar toasts and bottom scrolling stable (#9639)
* fix(app): keep sidebar toast dismissal and bottom scrolling stable Keep the positioned toast surface mounted through its native exit so its bottom anchor cannot collapse beneath the fading card. Reserve scrollable space below the final sidebar row without changing the scroll range when a toast appears. * fix(app): preserve toast safety across themes and sidebar groups Keep animated positioning in static React Native styles, extend the permanent scroll clearance to status grouping, and bound recording analysis to the requested frames. * fix(app): preserve the toast surface when content changes Replacing upload and reconnect status toasts must update the existing surface. A per-toast key retained the old surface during its exit, duplicating messages and breaking continuity.
This commit is contained in:
1 parent
046ac7b339
commit
caae991a0f
5 files changed
+152
-35
No files matched your search
@@ -0,0 +1,83 @@
|
||||
// Record a sidebar toast through timeout on the 2560×1600 Android tablet.
|
||||
// Pass a vertical sample line through the card's plain interior, away from text,
|
||||
// icons, and Android's clipboard preview, plus the visible-to-dismissed interval:
|
||||
// node .../toast-dismissal.mjs recording.mp4 sample-x start-seconds end-seconds
|
||||
// This checks actual native frames; a browser layout test misses this regression.
|
||||
import assert from "node:assert/strict";
|
||||
import { execFileSync } from "node:child_process";
|
||||
|
||||
const [, , recording, sampleX, start, end] = process.argv;
|
||||
assert(recording && sampleX && start && end, "Pass recording, sample x, start and end seconds");
|
||||
const { frames } = JSON.parse(
|
||||
execFileSync(
|
||||
"ffprobe",
|
||||
[
|
||||
"-v",
|
||||
"error",
|
||||
"-select_streams",
|
||||
"v",
|
||||
"-show_entries",
|
||||
"frame=best_effort_timestamp_time",
|
||||
"-of",
|
||||
"json",
|
||||
recording,
|
||||
],
|
||||
{ encoding: "utf8" },
|
||||
),
|
||||
);
|
||||
const selectedFrames = frames
|
||||
.map((frame, index) => ({ time: Number(frame.best_effort_timestamp_time), index }))
|
||||
.filter(({ time }) => time >= Number(start) && time <= Number(end));
|
||||
assert(selectedFrames.length > 2, "Capture at least three frames in the supplied interval");
|
||||
const firstFrame = selectedFrames[0].index;
|
||||
const endFrame = selectedFrames.at(-1).index + 1;
|
||||
const bytesPerFrame = 800;
|
||||
// Bound both output and buffer to the requested frames, even for a long recording.
|
||||
const pixels = execFileSync(
|
||||
"ffmpeg",
|
||||
[
|
||||
"-v",
|
||||
"fatal",
|
||||
"-i",
|
||||
recording,
|
||||
"-vf",
|
||||
`trim=start_frame=${firstFrame}:end_frame=${endFrame},crop=2:400:${Number(sampleX)}:1100,format=gray`,
|
||||
"-fps_mode",
|
||||
"passthrough",
|
||||
"-f",
|
||||
"rawvideo",
|
||||
"-",
|
||||
],
|
||||
{ maxBuffer: selectedFrames.length * bytesPerFrame + 1024 },
|
||||
);
|
||||
assert.equal(
|
||||
pixels.length,
|
||||
selectedFrames.length * bytesPerFrame,
|
||||
"Every selected frame must be decoded",
|
||||
);
|
||||
const positions = [];
|
||||
let disappeared = false;
|
||||
for (const [index, { time }] of selectedFrames.entries()) {
|
||||
const column = pixels.subarray(index * bytesPerFrame, (index + 1) * bytesPerFrame);
|
||||
const runs = [];
|
||||
let run = [];
|
||||
for (let y = 0; y < 400; y++) {
|
||||
if (column[y * 2] > 250) run.push(y);
|
||||
else {
|
||||
if (run.length > 40) runs.push(run);
|
||||
run = [];
|
||||
}
|
||||
}
|
||||
if (run.length > 40) runs.push(run);
|
||||
runs.sort((a, b) => b.length - a.length);
|
||||
if (runs.length) {
|
||||
const card = runs[0];
|
||||
positions.push({ time, centre: 1100 + (card[0] + card.at(-1)) / 2 });
|
||||
} else if (positions.length) disappeared = true;
|
||||
}
|
||||
assert(positions.length > 2, "Capture at least three visible card frames");
|
||||
assert(disappeared, "Recording must include the card disappearing");
|
||||
const centres = positions.map(({ centre }) => centre);
|
||||
const shift = Math.max(...centres) - Math.min(...centres);
|
||||
console.log(JSON.stringify({ positions, maximumShiftPixels: shift }, null, 2));
|
||||
assert(shift <= 2, `Toast moved ${shift}px during dismissal`);
|
||||
@@ -2592,7 +2592,9 @@ const styles = StyleSheet.create((theme) => ({
|
||||
// Optical inset: aligns the visible Pinned/Workspaces glyph edge with the
|
||||
// Schedules icon across the divider; their layout boxes have different insets.
|
||||
paddingTop: 2,
|
||||
paddingBottom: theme.spacing[4],
|
||||
// Keep the last row scrollable above the sidebar toast, including a wrapped Undo row.
|
||||
// This space stays present across toast changes so the scroll range never jumps.
|
||||
paddingBottom: theme.spacing[24],
|
||||
},
|
||||
projectListContainer: {
|
||||
width: "100%",
|
||||
|
||||
@@ -1101,7 +1101,8 @@ const styles = StyleSheet.create((theme) => ({
|
||||
paddingHorizontal: theme.spacing[2],
|
||||
// Keep status mode's Pinned/Workspaces boundary identical to project mode.
|
||||
paddingTop: 2,
|
||||
paddingBottom: theme.spacing[4],
|
||||
// Match project grouping: permanent room to scroll the final row above sidebar toasts.
|
||||
paddingBottom: theme.spacing[24],
|
||||
},
|
||||
pinnedSection: {
|
||||
marginBottom: theme.spacing[1],
|
||||
|
||||
@@ -32,4 +32,32 @@ describe("useToastHost", () => {
|
||||
act(() => dismissUploading());
|
||||
expect(result.current.toast?.content).toBe("Image uploaded");
|
||||
});
|
||||
|
||||
it("ends each toast's undo opportunity once, including replacement", () => {
|
||||
const { result } = renderHook(() => useToastHost());
|
||||
const dismissed: string[] = [];
|
||||
let dismissFirst = () => {};
|
||||
let dismissSecond = () => {};
|
||||
act(() => {
|
||||
dismissFirst = result.current.api.show("First archive", {
|
||||
onDismiss: () => dismissed.push("first"),
|
||||
});
|
||||
});
|
||||
act(() => {
|
||||
dismissSecond = result.current.api.show("Second archive", {
|
||||
onDismiss: () => dismissed.push("second"),
|
||||
});
|
||||
});
|
||||
expect(dismissed).toEqual(["first"]);
|
||||
act(() => dismissFirst());
|
||||
expect(result.current.toast?.content).toBe("Second archive");
|
||||
expect(dismissed).toEqual(["first"]);
|
||||
act(() => {
|
||||
dismissSecond();
|
||||
dismissSecond();
|
||||
result.current.dismiss();
|
||||
});
|
||||
expect(result.current.toast).toBeNull();
|
||||
expect(dismissed).toEqual(["first", "second"]);
|
||||
});
|
||||
});
|
||||
@@ -8,7 +8,7 @@ import { Platform, StyleSheet as NativeStyleSheet, Text, ToastAndroid, View } fr
|
||||
import Animated, { FadeIn, FadeOut } from "react-native-reanimated";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import type { Theme } from "@/styles/theme";
|
||||
import { SPACING, type Theme } from "@/styles/theme";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useIsCompactFormFactor } from "@/constants/layout";
|
||||
import { isWeb } from "@/constants/platform";
|
||||
@@ -212,10 +212,18 @@ export function ToastViewport({
|
||||
const topOffset =
|
||||
placement === "app-shell" ? insets.top + headerTopPadding + headerHeight : panelClearance;
|
||||
|
||||
const content = (
|
||||
<View
|
||||
// Keep the bottom anchor and its contents together while the native exit retains the view.
|
||||
const content = toast ? (
|
||||
<Animated.View
|
||||
entering={toastEntering}
|
||||
exiting={toastExiting}
|
||||
style={
|
||||
placement === "sidebar" ? styles.sidebarContainer : styles.container(placement, topOffset)
|
||||
placement === "sidebar"
|
||||
? animatedStyles.sidebarContainer
|
||||
: [
|
||||
animatedStyles.container,
|
||||
{ top: topOffset + (placement === "app-shell" ? SPACING[2] : SPACING[3]) },
|
||||
]
|
||||
}
|
||||
pointerEvents="box-none"
|
||||
collapsable={false}
|
||||
@@ -225,20 +233,16 @@ export function ToastViewport({
|
||||
pointerEvents="box-none"
|
||||
collapsable={false}
|
||||
>
|
||||
{toast ? (
|
||||
<Animated.View
|
||||
entering={toastEntering}
|
||||
exiting={toastExiting}
|
||||
style={animatedStyles.surface}
|
||||
testID={toast.testID ?? "app-toast"}
|
||||
accessibilityRole="alert"
|
||||
>
|
||||
<ToastCard toast={toast} onPointerEnter={pauseDismiss} onPointerLeave={resumeDismiss} />
|
||||
</Animated.View>
|
||||
) : null}
|
||||
<View
|
||||
style={animatedStyles.surface}
|
||||
testID={toast.testID ?? "app-toast"}
|
||||
accessibilityRole="alert"
|
||||
>
|
||||
<ToastCard toast={toast} onPointerEnter={pauseDismiss} onPointerLeave={resumeDismiss} />
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
</Animated.View>
|
||||
) : null;
|
||||
|
||||
if (placement === "app-shell" && isWeb && typeof document !== "undefined") {
|
||||
return createPortal(content, getOverlayRoot());
|
||||
@@ -294,26 +298,25 @@ function ToastCard({
|
||||
}
|
||||
|
||||
const animatedStyles = NativeStyleSheet.create({
|
||||
container: {
|
||||
position: "absolute",
|
||||
left: SPACING[4],
|
||||
right: SPACING[4],
|
||||
zIndex: OVERLAY_Z.toast,
|
||||
alignItems: "center",
|
||||
},
|
||||
sidebarContainer: {
|
||||
position: "absolute",
|
||||
left: SPACING[2],
|
||||
right: SPACING[2],
|
||||
bottom: SPACING[2],
|
||||
zIndex: OVERLAY_Z.toast,
|
||||
alignItems: "center",
|
||||
},
|
||||
surface: { alignSelf: "center", maxWidth: "100%" },
|
||||
});
|
||||
|
||||
const styles = StyleSheet.create((theme) => ({
|
||||
container: (placement: Exclude<ToastViewportPlacement, "sidebar">, topOffset: number) => ({
|
||||
position: "absolute",
|
||||
left: theme.spacing[4],
|
||||
right: theme.spacing[4],
|
||||
top: topOffset + (placement === "app-shell" ? theme.spacing[2] : theme.spacing[3]),
|
||||
zIndex: OVERLAY_Z.toast,
|
||||
alignItems: "center",
|
||||
}),
|
||||
sidebarContainer: {
|
||||
position: "absolute",
|
||||
left: theme.spacing[2],
|
||||
right: theme.spacing[2],
|
||||
bottom: theme.spacing[2],
|
||||
zIndex: OVERLAY_Z.toast,
|
||||
alignItems: "center",
|
||||
},
|
||||
widthBoundary: {
|
||||
width: "92%",
|
||||
maxWidth: TOAST_MAX_WIDTH,
|
||||
|
||||
Reference in new issue
Block a user