From 5e9909ac7a40406498ac66d12bf9d11e1c3555ce Mon Sep 17 00:00:00 2001 From: lezi-fun <177434121+lezi-fun@users.noreply.github.com> Date: Wed, 12 Aug 2026 09:34:28 +0800 Subject: [PATCH] fix: reverse post return transition --- app/globals.css | 109 ++++++++++++++++++++++++++++++-------- components/AppProvider.js | 40 ++++++++++++-- locales/en.json | 3 +- locales/zh.json | 3 +- 4 files changed, 128 insertions(+), 27 deletions(-) diff --git a/app/globals.css b/app/globals.css index 2f59c1f..9586a66 100644 --- a/app/globals.css +++ b/app/globals.css @@ -1151,89 +1151,154 @@ html.home-view-transition::view-transition-new(root) { } html.home-view-transition.returning-home::view-transition-old(root) { - animation: homeSourceFadeOut 0.24s ease-out both; + animation: returnPostSurroundingsOut 0.24s 0.16s ease-out both; } html.home-view-transition.returning-home::view-transition-new(root) { - animation: homeFeedFadeIn 0.32s ease-out both; + animation: returnFeedReveal 0.28s 0.34s ease-out both; } html.home-view-transition.returning-home::view-transition-group(post-expand) { - animation-duration: 0.48s; + animation-duration: 0.96s; + animation-timing-function: cubic-bezier(0.42, 0, 0.58, 1); +} + +html.home-view-transition.returning-home::view-transition-group(post-sidebar) { + animation-duration: 0.72s; + animation-delay: 0.24s; + animation-fill-mode: both; + animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1); +} + +html.home-view-transition.returning-home::view-transition-group(post-heading) { + animation-duration: 0.64s; + animation-delay: 0.32s; + animation-fill-mode: both; + animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1); +} + +html.home-view-transition.returning-home::view-transition-group(post-time) { + animation-duration: 0.96s; + animation-fill-mode: both; animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1); } -html.home-view-transition.returning-home::view-transition-group(post-sidebar), -html.home-view-transition.returning-home::view-transition-group(post-heading), -html.home-view-transition.returning-home::view-transition-group(post-time), html.home-view-transition.returning-home::view-transition-group(post-avatar), html.home-view-transition.returning-home::view-transition-group(post-author), -html.home-view-transition.returning-home::view-transition-group(post-body), html.home-view-transition.returning-home::view-transition-group(post-pin-state), html.home-view-transition.returning-home::view-transition-group(post-edited-state) { - animation-duration: 0.48s; + animation-duration: 0.68s; + animation-delay: 0.28s; + animation-fill-mode: both; animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1); } html.home-view-transition.returning-home::view-transition-old(post-expand) { - animation: postDetailCollapse 0.24s 0.12s ease-out both; + animation: none; + width: 100%; + height: 100%; + opacity: 1; + object-fit: fill; + mix-blend-mode: normal; } html.home-view-transition.returning-home::view-transition-new(post-expand) { - animation: postCardFadeIn 0.24s 0.18s ease-out both; + animation: none; + width: 100%; + height: 100%; + opacity: 0; + mix-blend-mode: normal; } html.home-view-transition.returning-home::view-transition-old(post-heading) { - animation: sharedTitleMorphOut 0.42s ease-out both; + animation: returnSharedPartOut 0.24s 0.32s ease-out both; } html.home-view-transition.returning-home::view-transition-new(post-heading) { - animation: sharedTitleMorphIn 0.42s ease-out both; + animation: returnSharedPartIn 0.24s 0.32s ease-out both; +} + +html.home-view-transition.returning-home::view-transition-old(post-time) { + animation: returnSharedPartOut 0.2s 0.47s ease-out both; +} + +html.home-view-transition.returning-home::view-transition-new(post-time) { + animation: returnSharedPartIn 0.2s 0.47s ease-out both; } -html.home-view-transition.returning-home::view-transition-old(post-time), html.home-view-transition.returning-home::view-transition-old(post-sidebar) { - animation: sharedTimeOut 0.14s 0.24s ease-out both; + animation: sharedSidebarIn 0.2s 0.34s ease-out reverse both; } -html.home-view-transition.returning-home::view-transition-new(post-time), html.home-view-transition.returning-home::view-transition-new(post-sidebar) { - animation: sharedTimeIn 0.14s 0.26s ease-out both; + animation: sharedSidebarOut 0.2s 0.34s ease-out reverse both; } html.home-view-transition.returning-home::view-transition-old(post-avatar), html.home-view-transition.returning-home::view-transition-old(post-author), html.home-view-transition.returning-home::view-transition-old(post-pin-state), html.home-view-transition.returning-home::view-transition-old(post-edited-state) { - animation: sharedPartMorphOut 0.42s ease-out both; + animation: returnSharedPartOut 0.22s 0.28s ease-out both; } html.home-view-transition.returning-home::view-transition-new(post-avatar), html.home-view-transition.returning-home::view-transition-new(post-author), html.home-view-transition.returning-home::view-transition-new(post-pin-state), html.home-view-transition.returning-home::view-transition-new(post-edited-state) { - animation: sharedPartMorphIn 0.42s ease-out both; + animation: returnSharedPartIn 0.22s 0.28s ease-out both; } html.home-view-transition.returning-home::view-transition-old(post-detail-controls), html.home-view-transition.returning-home::view-transition-old(post-detail-signature), html.home-view-transition.returning-home::view-transition-old(post-detail-media) { - animation: feedOnlyPartOut 0.18s ease-out both; + animation: returnDetailOnlyPartOut 0.22s 0.12s ease-out both; } html.home-view-transition.returning-home::view-transition-new(post-feed-actions), html.home-view-transition.returning-home::view-transition-new(post-feed-media) { - animation: detailOnlyPartIn 0.18s 0.26s ease-out both; + animation: returnFeedOnlyPartIn 0.28s 0.44s ease-out both; } html.home-view-transition.returning-home::view-transition-old(post-body) { - animation: bodySourceOut 0.1s 0.35s ease-out both; + animation: none; + opacity: 1; object-fit: none; object-position: left top; } html.home-view-transition.returning-home::view-transition-new(post-body) { - animation: bodyTargetIn 0.1s 0.38s ease-out both; + animation: none; + opacity: 0; +} + +@keyframes returnPostSurroundingsOut { + from { opacity: 1; } + to { opacity: 0; } +} + +@keyframes returnFeedReveal { + from { opacity: 0; } + to { opacity: 1; } +} + +@keyframes returnSharedPartOut { + from { opacity: 1; } + to { opacity: 0; } +} + +@keyframes returnSharedPartIn { + from { opacity: 0; } + to { opacity: 1; } +} + +@keyframes returnDetailOnlyPartOut { + from { opacity: 1; } + to { opacity: 0; } +} + +@keyframes returnFeedOnlyPartIn { + from { opacity: 0; } + to { opacity: 1; } } @keyframes feedViewFadeOut { diff --git a/components/AppProvider.js b/components/AppProvider.js index cd49ef3..7670e8f 100644 --- a/components/AppProvider.js +++ b/components/AppProvider.js @@ -58,6 +58,7 @@ function stageSharedGeometry(transition, { moveOffset, moveEasing = 'cubic-bezier(0.16, 1, 0.3, 1)', resizeEasing = 'cubic-bezier(0.4, 0, 0.2, 1)', + reverse = false, }) { transition.ready.then(() => { const groupAnimation = document.getAnimations().find( @@ -68,7 +69,28 @@ function stageSharedGeometry(transition, { const start = frames[0]; const end = frames[frames.length - 1]; - groupAnimation.effect.setKeyframes([ + groupAnimation.effect.setKeyframes(reverse ? [ + { + offset: 0, + width: start.width, + height: start.height, + transform: start.transform, + easing: resizeEasing, + }, + { + offset: 1 - moveOffset, + width: start.width, + height: end.height, + transform: start.transform, + easing: moveEasing, + }, + { + offset: 1, + width: end.width, + height: end.height, + transform: end.transform, + }, + ] : [ { offset: 0, width: start.width, @@ -284,8 +306,20 @@ export default function AppProvider({ children, cachedName = '' }) { if (targetCard) targetCard.style.viewTransitionName = 'post-expand'; targetParts = namePostTransitionParts(targetCard); }); - stageSharedGeometry(transition, { name: 'post-expand', duration: 480, moveOffset: 0.72 }); - stageSharedGeometry(transition, { name: 'post-body', duration: 480, moveOffset: 0.72 }); + stageSharedGeometry(transition, { + name: 'post-expand', + duration: 960, + moveOffset: 0.62, + moveEasing: 'cubic-bezier(0.42, 0, 0.58, 1)', + resizeEasing: 'cubic-bezier(0.42, 0, 0.58, 1)', + reverse: true, + }); + stageSharedGeometry(transition, { + name: 'post-body', + duration: 960, + moveOffset: 0.62, + reverse: true, + }); const clearTargetNames = () => { if (targetCard) targetCard.style.viewTransitionName = ''; clearPostTransitionParts(targetParts); diff --git a/locales/en.json b/locales/en.json index 1c478e1..1c15931 100644 --- a/locales/en.json +++ b/locales/en.json @@ -17,6 +17,7 @@ "hot": "Latest replies", "newPost": "New post", "loading": "Loading...", + "loadFailed": "Load failed: {{msg}}", "empty": "No posts yet — be the first to publish!", "pinned": "Pinned", "deleted": "(edited)", @@ -278,4 +279,4 @@ "save": "Save" } } -} \ No newline at end of file +} diff --git a/locales/zh.json b/locales/zh.json index 367e4a3..6ce5516 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -17,6 +17,7 @@ "hot": "最新回复", "newPost": "发布新帖", "loading": "加载中...", + "loadFailed": "加载失败:{{msg}}", "empty": "还没有帖子,快来发布第一条吧!", "pinned": "置顶", "deleted": "(已编辑)", @@ -278,4 +279,4 @@ "save": "保存" } } -} \ No newline at end of file +}