feat: match YouTube swipe controls on watch feed

This commit is contained in:
Zhou Weidong committed 2026-11-10 16:29:30 +08:00
1 parent 02ccf0ddc4
commit 41e9cdf2e9
2 files changed
+4 -2

No files matched your search

+1
View File
@@ -1,4 +1,5 @@
/* Author: fruit.com.cn */
.single-video-feed{position:relative}.feed-arrows{position:fixed;right:28px;top:50%;z-index:5;display:grid;gap:10px;transform:translateY(-50%)}.feed-arrows button{width:42px;height:42px;border:1px solid #555;border-radius:50%;background:#111c;color:#fff;font-size:20px;cursor:pointer}.feed-arrows button:disabled{opacity:.3;cursor:not-allowed}@media(max-width:760px){.feed-arrows{right:14px;top:auto;bottom:84px;transform:none}.feed-arrows button{width:38px;height:38px;background:#0009}}
.single-video-page{position:fixed;inset:64px 0 0;background:#050505;z-index:2}.single-video-toolbar{position:absolute;top:0;left:0;right:0;height:58px;z-index:3;display:flex;align-items:center;gap:14px;padding:0 24px;background:linear-gradient(#000b,transparent);pointer-events:none}.single-video-toolbar button{pointer-events:auto;border:0;background:#0008;color:#fff;border-radius:50%;width:34px;height:34px;font-size:20px}.single-video-toolbar img{width:72px;height:34px;object-fit:contain}.single-video-toolbar span{color:#ddd;font-size:12px}.single-video-feed{height:100%;overflow-y:auto;scroll-snap-type:y mandatory;overscroll-behavior-y:contain}.single-video-feed>div{height:100%;scroll-snap-align:start}.single-video-slide{position:relative;height:100%;max-width:900px;margin:0 auto;background:#111}.single-video-stage,.single-video-stage .video-player,.single-video-placeholder{width:100%;height:100%;object-fit:contain;background:#050505}.single-video-placeholder{position:relative;display:grid;place-items:center}.single-video-placeholder img{width:100%;height:100%;object-fit:cover;opacity:.38}.single-video-placeholder span{position:absolute;background:#000b;border-radius:10px;padding:12px 16px;color:#fff}.single-video-info{position:absolute;left:28px;right:28px;bottom:28px;text-shadow:0 2px 14px #000}.single-video-info span{color:#ff786f;font-size:11px;letter-spacing:.12em}.single-video-info h1{margin:7px 0;font:700 28px Outfit}.single-video-info p{margin:0;color:#ddd}@media(max-width:760px){.single-video-page{inset:58px 0 0}.single-video-toolbar{padding:0 14px}.single-video-feed>div,.single-video-slide{height:100dvh}.single-video-info{left:20px;right:20px;bottom:34px}.single-video-info h1{font-size:23px}}
.youtube-watch-layout{display:grid;grid-template-columns:minmax(0,1fr) 330px;gap:28px;max-width:1320px;margin:0 auto}.watch-main{min-width:0}.watch-channel-bar{display:flex;align-items:center;gap:12px;margin-bottom:16px}.watch-channel-bar img{width:72px;height:34px;object-fit:contain}.watch-channel-bar div{display:grid;gap:3px}.watch-channel-bar small{color:#999}.watch-channel-bar button{margin-left:auto;border:0;border-radius:20px;padding:10px 16px;background:#fff;color:#111;font-weight:600}.episode-feed{display:grid;gap:20px;scroll-snap-type:y mandatory}.episode-slide{position:relative;min-height:min(72vh,700px);scroll-snap-align:start;overflow:hidden;border-radius:16px;background:#111}.episode-slide-player{height:100%;min-height:min(72vh,700px)}.episode-slide-player .video-player,.episode-slide-placeholder{width:100%;height:100%;min-height:min(72vh,700px);object-fit:contain;background:#050505}.episode-slide-placeholder{position:relative;display:grid;place-items:center}.episode-slide-placeholder img{width:100%;height:100%;object-fit:cover;opacity:.42}.episode-slide-placeholder span{position:absolute;color:#fff;padding:12px 16px;border-radius:10px;background:#000b}.episode-slide-caption{position:absolute;left:24px;right:24px;bottom:20px;text-shadow:0 2px 15px #000}.episode-slide-caption span{color:#ff786f;font-size:11px;letter-spacing:.12em}.episode-slide-caption h2{margin:6px 0;font:700 26px Outfit}.episode-slide-caption p{margin:0;color:#ddd}.watch-sidebar{display:grid;align-content:start;gap:24px}.episode-list-panel{padding:16px;border:1px solid #303030;border-radius:14px;background:#171717}.episode-list-title{display:flex;align-items:center;gap:9px;margin-bottom:12px}.episode-list-title h2,.watch-recommendations h2{margin:0;font:700 20px Outfit}.episode-list-title span{color:#999}.episode-list-panel button{display:flex;align-items:center;gap:10px;width:100%;padding:10px;border:0;border-radius:8px;background:transparent;color:#ccc;text-align:left;cursor:pointer}.episode-list-panel button:hover,.episode-list-panel button.active{background:#3a2223;color:#fff}.episode-list-panel button b{color:#ff786f}.episode-list-panel button span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.episode-list-panel button small{margin-left:auto}.watch-recommendations .media-card{margin-top:14px}@media(max-width:900px){.youtube-watch-layout{display:block}.watch-sidebar{margin-top:20px}.episode-slide,.episode-slide-player,.episode-slide-player .video-player,.episode-slide-placeholder{min-height:calc(100dvh - 190px)}.episode-feed{margin:0 -14px}.episode-slide{border-radius:0}.episode-slide-caption{bottom:28px}.watch-channel-bar,.watch-title,.watch-subtitle{margin-left:14px;margin-right:14px}}
.episode-picker{margin-top:24px;padding-top:20px;border-top:1px solid var(--line)}.episode-picker-heading{display:flex;align-items:center;gap:10px;margin-bottom:14px}.episode-picker-heading h2{margin:0;font:700 20px Outfit}.episode-picker-heading span{display:grid;place-items:center;min-width:24px;height:24px;border-radius:50%;background:#292929;color:#aaa;font-size:11px}.episode-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(120px,1fr));gap:10px}.episode-button{display:flex;align-items:center;gap:8px;min-height:48px;padding:8px 10px;border:1px solid #373737;border-radius:9px;background:#181818;color:#ddd;text-align:left;cursor:pointer}.episode-button:hover,.episode-button.active{border-color:#ff786f;background:#3a2223;color:#fff}.episode-button b{font-size:16px;color:#ff786f}.episode-button span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px}.episode-button small{margin-left:auto}.episode-button.locked{opacity:.72}@media(max-width:760px){.episode-grid{grid-template-columns:repeat(3,1fr)}.episode-button{min-width:0;padding:8px}.episode-button span{display:none}.episode-button b{margin:auto}}
+3 -2
View File
@@ -15,6 +15,7 @@ function SwipeVideo({ video, active }) {
export function WatchPage() {
const { id } = useParams(); const navigate = useNavigate(); const { locale } = useAppStore(); const [activeId, setActiveId] = useState(id); const current = useApi(() => appApi.drama(id).then((data) => normalizeDrama(data, locale.code)), [id, locale.code]); const feed = useApi(() => appApi.dramas().then((payload) => normalizePage(payload).list.map((item) => normalizeDrama(item, locale.code))), [locale.code]); const items = feed.data || []; const ordered = [current.data, ...items.filter((item) => item.id !== id)].filter(Boolean);
useEffect(() => { const node = document.querySelector('.single-video-feed'); if (!node) return undefined; const observer = new IntersectionObserver((entries) => entries.forEach((entry) => { if (entry.isIntersecting) { const nextId = entry.target.dataset.id; setActiveId(nextId); if (nextId !== id) window.history.replaceState(null, '', `/watch/${nextId}`); } }), { root: node, threshold: 0.75 }); node.querySelectorAll('.single-video-slide').forEach((item) => observer.observe(item)); return () => observer.disconnect(); }, [ordered.length, id]);
return <div className="single-video-page"><header className="single-video-toolbar"><button onClick={() => navigate(-1)}>←</button><img src="/brand/ymb-logo-blue.png" alt="YMB" /><span>{locale.swipeHint || 'Swipe up for the next video'}</span></header><div className="single-video-feed">{current.loading && <div className="api-note">{locale.loading}</div>}{ordered.map((video) => <div key={video.id} data-id={video.id}><SwipeVideo video={video} active={String(activeId) === String(video.id)} /></div>)}</div></div>;
const activeIndex = Math.max(0, ordered.findIndex((item) => String(item.id) === String(activeId))); const feedRef = useRef(null); const touchStart = useRef(0); const scrollToIndex = (index) => { const target = feedRef.current?.children[index]; target?.scrollIntoView({ behavior: 'smooth', block: 'start' }); }; const move = (delta) => scrollToIndex(Math.min(ordered.length - 1, Math.max(0, activeIndex + delta)));
useEffect(() => { const node = feedRef.current; if (!node) return undefined; const observer = new IntersectionObserver((entries) => entries.forEach((entry) => { if (entry.isIntersecting) { const nextId = entry.target.dataset.id; setActiveId(nextId); if (nextId !== id) window.history.replaceState(null, '', `/watch/${nextId}`); } }), { root: node, threshold: 0.75 }); node.querySelectorAll('[data-id]').forEach((item) => observer.observe(item)); const keydown = (event) => { if (event.key === 'ArrowDown' || event.key === 'PageDown') { event.preventDefault(); move(1); } if (event.key === 'ArrowUp' || event.key === 'PageUp') { event.preventDefault(); move(-1); } }; window.addEventListener('keydown', keydown); return () => { observer.disconnect(); window.removeEventListener('keydown', keydown); }; }, [ordered.length, id, activeIndex]);
return <div className="single-video-page"><header className="single-video-toolbar"><button onClick={() => navigate(-1)}>←</button><img src="/brand/ymb-logo-blue.png" alt="YMB" /><span>{locale.swipeHint || 'Swipe up for the next video'}</span></header><div ref={feedRef} className="single-video-feed" onTouchStart={(event) => { touchStart.current = event.touches[0].clientY; }} onTouchEnd={(event) => { const distance = touchStart.current - event.changedTouches[0].clientY; if (Math.abs(distance) > 45) move(distance > 0 ? 1 : -1); }} onWheel={(event) => { if (Math.abs(event.deltaY) > 20) { event.preventDefault(); move(event.deltaY > 0 ? 1 : -1); } }}>{current.loading && <div className="api-note">{locale.loading}</div>}{ordered.map((video) => <div key={video.id} data-id={video.id}><SwipeVideo video={video} active={String(activeId) === String(video.id)} /></div>)}<div className="feed-arrows"><button onClick={() => move(-1)} disabled={activeIndex === 0} aria-label="Previous video">↑</button><button onClick={() => move(1)} disabled={activeIndex === ordered.length - 1} aria-label="Next video">↓</button></div></div></div>;
}