Improve mobile drawers and timeline ruler
This commit is contained in:
1 parent
9e5c02f5db
commit
b1ca648e79
6 files changed
+136
-14
No files matched your search
@@ -1,5 +1,24 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test("mobile sticker drawer always shows cancel and add actions", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 412, height: 915 });
|
||||
await page.addInitScript(() => {
|
||||
localStorage.clear();
|
||||
localStorage.setItem("ai-voiceover-ui-language", "zh");
|
||||
});
|
||||
await page.goto("/");
|
||||
|
||||
await page.locator(".tool-rail").getByRole("button", { name: "贴纸" }).click();
|
||||
|
||||
const actions = page.locator(".mobile-sticker-actions");
|
||||
await expect(actions).toBeVisible();
|
||||
await expect(actions.getByRole("button", { name: "取消" })).toBeVisible();
|
||||
await expect(actions.getByRole("button", { name: "添加贴纸" })).toBeDisabled();
|
||||
|
||||
await page.getByRole("button", { name: "热度火焰" }).click();
|
||||
await expect(actions.getByRole("button", { name: "添加贴纸" })).toBeEnabled();
|
||||
});
|
||||
|
||||
test("mobile sticker clip exposes direct properties, copy, and delete actions", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 412, height: 915 });
|
||||
await page.addInitScript(() => {
|
||||
|
||||
@@ -53,6 +53,39 @@ async function readTimelineState(page) {
|
||||
});
|
||||
}
|
||||
|
||||
test("mobile ruler drag scrolls the shared timeline while desktop behavior stays separate", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 412, height: 915 });
|
||||
await page.addInitScript(() => localStorage.setItem("ai-voiceover-ui-language", "zh"));
|
||||
await page.goto("/");
|
||||
await page.locator('input[type="file"][multiple]').setInputFiles({
|
||||
name: "ruler-scroll-fixture.png",
|
||||
mimeType: "image/png",
|
||||
buffer: ONE_PIXEL_PNG,
|
||||
});
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(page.locator(".image-clip")).toBeVisible();
|
||||
|
||||
const ruler = page.locator(".timeline-ruler-viewport");
|
||||
const rulerBox = await ruler.boundingBox();
|
||||
if (!rulerBox) throw new Error("Timeline ruler is not visible");
|
||||
const cdp = await page.context().newCDPSession(page);
|
||||
await cdp.send("Emulation.setTouchEmulationEnabled", { enabled: true, maxTouchPoints: 1 });
|
||||
const y = rulerBox.y + rulerBox.height / 2;
|
||||
const startX = rulerBox.x + rulerBox.width * 0.72;
|
||||
const endX = rulerBox.x + rulerBox.width * 0.28;
|
||||
const touch = (x) => [{ id: 1, x, y, radiusX: 6, radiusY: 6, force: 1 }];
|
||||
|
||||
const before = await readTimelineState(page);
|
||||
await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: touch(startX) });
|
||||
await cdp.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: touch(endX) });
|
||||
await cdp.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] });
|
||||
await expect.poll(async () => (await readTimelineState(page)).scrollLeft).toBeGreaterThan(before.scrollLeft + 20);
|
||||
|
||||
const after = await readTimelineState(page);
|
||||
expect(after.currentTime).toBeGreaterThan(before.currentTime);
|
||||
await expect(page.locator(".mobile-fixed-playhead")).toBeVisible();
|
||||
});
|
||||
|
||||
test("mobile pinch zoom keeps the visible frame and ruler scale stable on release", async ({ page }, testInfo) => {
|
||||
await page.setViewportSize({ width: 412, height: 915 });
|
||||
await page.addInitScript(() => localStorage.setItem("ai-voiceover-ui-language", "zh"));
|
||||
|
||||
@@ -23,7 +23,7 @@ export function EditorSidebar({ model: d }) {
|
||||
))}
|
||||
</aside>
|
||||
|
||||
<aside className={`media-panel ${d.mobilePanel === "tools" && d.selectedLibraryAssetId ? "has-mobile-asset-actions" : ""} ${d.mobilePanel === "tools" && d.activeTool === "stickers" && d.selectedStickerId && d.selectedStickerId !== "none" ? "has-mobile-sticker-actions" : ""}`}>
|
||||
<aside className={`media-panel ${d.mobilePanel === "tools" && d.selectedLibraryAssetId ? "has-mobile-asset-actions" : ""} ${d.mobilePanel === "tools" && d.activeTool === "stickers" ? "has-mobile-sticker-actions" : ""}`}>
|
||||
{d.activeTool === "media" ? (
|
||||
<MediaPanel
|
||||
t={d.t}
|
||||
|
||||
@@ -564,6 +564,7 @@ export function Timeline({
|
||||
const rulerViewportFrameRef = useRef(0);
|
||||
const wheelZoomActiveRef = useRef(false);
|
||||
const rulerViewportSyncRef = useRef(null);
|
||||
const rulerViewportRef = useRef(null);
|
||||
const rulerCanvasRef = useRef(null);
|
||||
const zoomReadoutRef = useRef(null);
|
||||
const pendingWheelDeltaRef = useRef(0);
|
||||
@@ -1104,6 +1105,55 @@ export function Timeline({
|
||||
mobilePinchActiveRef.current = false;
|
||||
};
|
||||
}, [mobileTrackBaseWidth, setTimelineZoom, timelineDuration, trackScrollRef]);
|
||||
useEffect(() => {
|
||||
const rulerViewport = rulerViewportRef.current;
|
||||
const scrollElement = trackScrollRef.current?.parentElement;
|
||||
if (!rulerViewport || !scrollElement) return undefined;
|
||||
|
||||
let gesture = null;
|
||||
const handlePointerDown = (event) => {
|
||||
if (!window.matchMedia?.("(max-width: 760px)").matches || event.pointerType !== "touch") return;
|
||||
gesture = {
|
||||
pointerId: event.pointerId,
|
||||
startX: event.clientX,
|
||||
startY: event.clientY,
|
||||
startScrollLeft: scrollElement.scrollLeft,
|
||||
scrolling: false,
|
||||
};
|
||||
};
|
||||
const handlePointerMove = (event) => {
|
||||
if (!gesture || gesture.pointerId !== event.pointerId) return;
|
||||
const deltaX = event.clientX - gesture.startX;
|
||||
const deltaY = event.clientY - gesture.startY;
|
||||
if (!gesture.scrolling) {
|
||||
if (Math.abs(deltaX) < 3 || Math.abs(deltaX) < Math.abs(deltaY)) return;
|
||||
gesture.scrolling = true;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
scrollElement.scrollLeft = gesture.startScrollLeft - deltaX;
|
||||
rulerViewportSyncRef.current?.();
|
||||
};
|
||||
const handlePointerEnd = (event) => {
|
||||
if (gesture?.pointerId !== event.pointerId) return;
|
||||
if (gesture.scrolling) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
gesture = null;
|
||||
};
|
||||
|
||||
rulerViewport.addEventListener("pointerdown", handlePointerDown, { capture: true });
|
||||
window.addEventListener("pointermove", handlePointerMove, { capture: true, passive: false });
|
||||
window.addEventListener("pointerup", handlePointerEnd, { capture: true });
|
||||
window.addEventListener("pointercancel", handlePointerEnd, { capture: true });
|
||||
return () => {
|
||||
rulerViewport.removeEventListener("pointerdown", handlePointerDown, { capture: true });
|
||||
window.removeEventListener("pointermove", handlePointerMove, { capture: true });
|
||||
window.removeEventListener("pointerup", handlePointerEnd, { capture: true });
|
||||
window.removeEventListener("pointercancel", handlePointerEnd, { capture: true });
|
||||
};
|
||||
}, [trackScrollRef]);
|
||||
const renderAssetDropSlot = (track) =>
|
||||
assetDropTargetTrack === track ? (
|
||||
<div
|
||||
@@ -1448,13 +1498,16 @@ export function Timeline({
|
||||
|
||||
<div className="timeline-board">
|
||||
<div className="track-labels-ruler-spacer" aria-hidden="true" />
|
||||
<div className="timeline-ruler-viewport">
|
||||
<div ref={rulerViewportRef} className="timeline-ruler-viewport">
|
||||
<div
|
||||
ref={rulerCanvasRef}
|
||||
className="timeline-ruler-canvas"
|
||||
style={{ width: localTrackWidth }}
|
||||
>
|
||||
<div className="ruler" onPointerDown={handleTimelineSurfacePointerDown}>
|
||||
<div className="ruler" onPointerDown={(event) => {
|
||||
if (window.matchMedia?.("(max-width: 760px)").matches && event.pointerType === "touch") return;
|
||||
handleTimelineSurfacePointerDown(event);
|
||||
}}>
|
||||
{rulerTicks.map((tick) => (
|
||||
<span
|
||||
className={`ruler-tick ${tick.isMajor ? "is-major" : "is-minor"}`}
|
||||
|
||||
@@ -1329,13 +1329,14 @@ function StickerPanel({
|
||||
) : (
|
||||
<span className="sticker-load-sentinel" ref={loadMoreRef} aria-hidden="true" />
|
||||
)}
|
||||
{selectedSticker && mobilePanelOpen ? createPortal((
|
||||
{mobilePanelOpen ? createPortal((
|
||||
<div className="mobile-sticker-actions" aria-label={t("mobileStickerActions")}>
|
||||
<button type="button" className="is-secondary" onClick={() => {
|
||||
onSelect(emptySticker.id);
|
||||
closeMobilePanel?.();
|
||||
}}>{t("mobileStickerCancel")}</button>
|
||||
<button type="button" onClick={() => {
|
||||
<button type="button" disabled={!selectedSticker} onClick={() => {
|
||||
if (!selectedSticker) return;
|
||||
onStickerConfirm?.(selectedSticker);
|
||||
closeMobilePanel?.();
|
||||
}}>{t("addSticker")}</button>
|
||||
|
||||
+25
-9
@@ -4401,6 +4401,8 @@ button:disabled {
|
||||
.ruler {
|
||||
position: relative;
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
color: #7e8995;
|
||||
font-size: 12px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
@@ -4447,7 +4449,6 @@ button:disabled {
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 1px;
|
||||
border-left: 1px solid rgba(255, 255, 255, 0.06);
|
||||
padding-left: 7px;
|
||||
color: #838f9b;
|
||||
line-height: 24px;
|
||||
@@ -4455,17 +4456,25 @@ button:disabled {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.ruler-tick.is-major {
|
||||
border-left-color: rgba(255, 255, 255, 0.12);
|
||||
.ruler-tick::before {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 1px;
|
||||
height: 7px;
|
||||
background: rgba(186, 202, 211, 0.34);
|
||||
content: "";
|
||||
}
|
||||
|
||||
.ruler-tick.is-major::before {
|
||||
width: 1.5px;
|
||||
height: 12px;
|
||||
background: rgba(218, 232, 238, 0.62);
|
||||
}
|
||||
|
||||
.ruler-tick.is-minor {
|
||||
top: 15px;
|
||||
bottom: auto;
|
||||
height: 8px;
|
||||
padding-left: 0;
|
||||
color: transparent;
|
||||
border-left-color: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
.playhead {
|
||||
@@ -6178,7 +6187,8 @@ button:disabled {
|
||||
.media-panel > .asset-list,
|
||||
.media-panel > .tool-panel,
|
||||
.voice-panel > .voice-tab-body {
|
||||
flex: 1 1 auto;
|
||||
flex: 1 1 0;
|
||||
height: 0;
|
||||
min-height: 0;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
@@ -6262,6 +6272,11 @@ button:disabled {
|
||||
color: #c5d1d6;
|
||||
background: rgba(255, 255, 255, .045);
|
||||
}
|
||||
.mobile-sticker-actions button:disabled {
|
||||
border-color: rgba(255, 255, 255, .08);
|
||||
color: #66747d;
|
||||
background: rgba(255, 255, 255, .035);
|
||||
}
|
||||
.sticker-panel { padding: 0 10px 12px; }
|
||||
.sticker-panel h2 { margin: 0 0 8px; font-size: 13px; }
|
||||
.sticker-none-button { min-height: 34px; padding: 0 10px; font-size: 11px; }
|
||||
@@ -6414,6 +6429,7 @@ button:disabled {
|
||||
.timeline-ruler-viewport {
|
||||
padding-right: 0;
|
||||
padding-left: 0;
|
||||
touch-action: none;
|
||||
}
|
||||
.track-scroll,
|
||||
.timeline-ruler-canvas {
|
||||
@@ -6606,7 +6622,7 @@ button:disabled {
|
||||
|
||||
@media (max-width: 760px) {
|
||||
.media-panel .tool-panel {
|
||||
height: auto;
|
||||
height: 0;
|
||||
min-height: 0;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
|
||||
Reference in new issue
Block a user