From ae2d5e82caa0fc25642bd3f31e3870ea85f88573 Mon Sep 17 00:00:00 2001 From: lezi-fun <177434121+lezi-fun@users.noreply.github.com> Date: Tue, 11 Aug 2026 15:32:26 +0800 Subject: [PATCH] fix: smooth post title and card morph --- app/api/posts/route.js | 1 + app/globals.css | 34 +++++++++++++++++++++++----------- components/AppProvider.js | 16 ++-------------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app/api/posts/route.js b/app/api/posts/route.js index 56db7bb..fb631f1 100644 --- a/app/api/posts/route.js +++ b/app/api/posts/route.js @@ -31,6 +31,7 @@ export async function GET(req) { p.*, u.username, u.avatar_url, + u.signature, (SELECT COUNT(*) FROM replies WHERE post_id = p.id) as reply_count FROM posts p JOIN users u ON p.user_id = u.id diff --git a/app/globals.css b/app/globals.css index 53cc34b..6243a0a 100644 --- a/app/globals.css +++ b/app/globals.css @@ -920,6 +920,13 @@ html.home-view-transition.returning-home #pagePost .post-page-header h2 { view-transition-name: post-heading; } +html.post-view-transition .post-card .post-title, +html.home-view-transition.returning-home .post-card .post-title { + display: block; + width: max-content; + max-width: 100%; +} + html.post-view-transition::view-transition, html.home-view-transition::view-transition { background: linear-gradient(145deg, var(--bg-start) 0%, var(--bg-end) 100%); @@ -930,12 +937,16 @@ html.post-view-transition::view-transition-group(post-expand) { animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1); } -html.post-view-transition::view-transition-group(post-sidebar), -html.post-view-transition::view-transition-group(post-heading) { +html.post-view-transition::view-transition-group(post-sidebar) { animation-duration: 0.72s; animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1); } +html.post-view-transition::view-transition-group(post-heading) { + animation-duration: 0.64s; + animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1); +} + html.post-view-transition::view-transition-group(post-time) { animation-duration: 1.05s; animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1); @@ -968,11 +979,11 @@ html.post-view-transition::view-transition-new(post-expand) { } html.post-view-transition::view-transition-old(post-heading) { - animation: sharedTitleOut 0.14s 0.48s ease-out both; + animation: sharedTitleMorphOut 0.64s ease-out both; } html.post-view-transition::view-transition-new(post-heading) { - animation: sharedTitleIn 0.14s 0.82s ease-out both; + animation: sharedTitleMorphIn 0.64s ease-out both; } html.post-view-transition::view-transition-old(post-time) { @@ -1028,11 +1039,11 @@ html.home-view-transition.returning-home::view-transition-new(post-expand) { } html.home-view-transition.returning-home::view-transition-old(post-heading) { - animation: sharedTitleOut 0.12s 0.22s ease-out both; + animation: sharedTitleMorphOut 0.42s ease-out both; } html.home-view-transition.returning-home::view-transition-new(post-heading) { - animation: sharedTitleIn 0.12s 0.36s ease-out both; + animation: sharedTitleMorphIn 0.42s ease-out both; } html.home-view-transition.returning-home::view-transition-old(post-time), @@ -1082,13 +1093,14 @@ html.home-view-transition.returning-home::view-transition-new(post-sidebar) { to { opacity: 1; } } -@keyframes sharedTitleOut { - to { opacity: 0; } +@keyframes sharedTitleMorphOut { + 0%, 68% { opacity: 1; } + 100% { opacity: 0; } } -@keyframes sharedTitleIn { - from { opacity: 0; } - to { opacity: 1; } +@keyframes sharedTitleMorphIn { + 0%, 62% { opacity: 0; } + 100% { opacity: 1; } } @keyframes sharedTimeOut { diff --git a/components/AppProvider.js b/components/AppProvider.js index ec6d373..dc5c296 100644 --- a/components/AppProvider.js +++ b/components/AppProvider.js @@ -7,7 +7,7 @@ import { API, getTheme, setToken, getToken } from '@/lib/api'; const AppContext = createContext(null); -function stageSharedGeometry(transition, { name, duration, moveOffset, preserveSizeUntilMove = false }) { +function stageSharedGeometry(transition, { name, duration, moveOffset }) { transition.ready.then(() => { const groupAnimation = document.getAnimations().find( (animation) => animation.effect?.pseudoElement === `::view-transition-group(${name})` @@ -27,7 +27,7 @@ function stageSharedGeometry(transition, { name, duration, moveOffset, preserveS }, { offset: moveOffset, - width: preserveSizeUntilMove ? start.width : end.width, + width: end.width, height: start.height, transform: end.transform, easing: 'cubic-bezier(0.4, 0, 0.2, 1)', @@ -238,12 +238,6 @@ export default function AppProvider({ children, cachedName = '' }) { if (targetTime) targetTime.style.viewTransitionName = 'post-time'; }); stageSharedGeometry(transition, { name: 'post-expand', duration: 480, moveOffset: 0.72 }); - stageSharedGeometry(transition, { - name: 'post-heading', - duration: 480, - moveOffset: 0.72, - preserveSizeUntilMove: true, - }); const clearTargetNames = () => { if (targetCard) targetCard.style.viewTransitionName = ''; if (targetTitle) targetTitle.style.viewTransitionName = ''; @@ -284,12 +278,6 @@ export default function AppProvider({ children, cachedName = '' }) { flushSync(commitNavigation); }); stageSharedGeometry(transition, { name: 'post-expand', duration: 960, moveOffset: 0.62 }); - stageSharedGeometry(transition, { - name: 'post-heading', - duration: 960, - moveOffset: 0.62, - preserveSizeUntilMove: true, - }); const clearSourceNames = () => { sourceElement.style.viewTransitionName = ''; if (sourceTitle) sourceTitle.style.viewTransitionName = '';