fix: stabilize markdown post transition
This commit is contained in:
1 parent
0060034dec
commit
cb89f1190c
3 files changed
+37
-10
No files matched your search
+8
-5
@@ -1071,17 +1071,20 @@ html.post-view-transition::view-transition-old(post-feed-actions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
html.post-view-transition::view-transition-old(post-body) {
|
html.post-view-transition::view-transition-old(post-body) {
|
||||||
animation: bodySourceOut 0.08s 0.56s ease-out both;
|
animation: none;
|
||||||
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
html.post-view-transition::view-transition-new(post-body) {
|
html.post-view-transition::view-transition-new(post-body) {
|
||||||
animation: bodyTargetIn 0.1s 0.59s ease-out both;
|
animation: none;
|
||||||
|
opacity: 1;
|
||||||
object-fit: none;
|
object-fit: none;
|
||||||
object-position: left top;
|
object-position: left top;
|
||||||
}
|
}
|
||||||
|
|
||||||
html.post-view-transition::view-transition-old(post-feed-media) {
|
html.post-view-transition::view-transition-old(post-feed-media) {
|
||||||
animation: feedOnlyPartOut 0.24s 0.32s ease-out both;
|
animation: none;
|
||||||
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
html.post-view-transition::view-transition-new(post-detail-controls),
|
html.post-view-transition::view-transition-new(post-detail-controls),
|
||||||
@@ -1387,8 +1390,8 @@ html.home-view-transition.returning-home::view-transition-new(post-body) {
|
|||||||
box-shadow: var(--glass-shadow);
|
box-shadow: var(--glass-shadow);
|
||||||
}
|
}
|
||||||
#pagePost .post-detail-card .post-content {
|
#pagePost .post-detail-card .post-content {
|
||||||
font-size: 16px;
|
font-size: 15px;
|
||||||
line-height: 1.8;
|
line-height: 1.7;
|
||||||
}
|
}
|
||||||
#pagePost .post-detail-card .post-title {
|
#pagePost .post-detail-card .post-title {
|
||||||
font-size: 22px;
|
font-size: 22px;
|
||||||
|
|||||||
@@ -35,6 +35,23 @@ function clearPostTransitionParts(elements) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function waitForPostImages(container) {
|
||||||
|
const images = Array.from(container?.querySelectorAll('img') || []);
|
||||||
|
if (images.length === 0) return Promise.resolve();
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
let settled = false;
|
||||||
|
const finish = () => {
|
||||||
|
if (settled) return;
|
||||||
|
settled = true;
|
||||||
|
clearTimeout(timeout);
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
const timeout = setTimeout(finish, 1200);
|
||||||
|
Promise.all(images.map((image) => image.decode?.().catch(() => {}) || Promise.resolve())).then(finish);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function stageSharedGeometry(transition, { name, duration, moveOffset }) {
|
function stageSharedGeometry(transition, { name, duration, moveOffset }) {
|
||||||
transition.ready.then(() => {
|
transition.ready.then(() => {
|
||||||
const groupAnimation = document.getAnimations().find(
|
const groupAnimation = document.getAnimations().find(
|
||||||
@@ -295,8 +312,9 @@ export default function AppProvider({ children, cachedName = '' }) {
|
|||||||
sourceElement.style.viewTransitionName = 'post-expand';
|
sourceElement.style.viewTransitionName = 'post-expand';
|
||||||
const sourceParts = namePostTransitionParts(sourceElement);
|
const sourceParts = namePostTransitionParts(sourceElement);
|
||||||
document.documentElement.classList.add('post-view-transition');
|
document.documentElement.classList.add('post-view-transition');
|
||||||
const transition = document.startViewTransition(() => {
|
const transition = document.startViewTransition(async () => {
|
||||||
flushSync(commitNavigation);
|
flushSync(commitNavigation);
|
||||||
|
await waitForPostImages(document.querySelector('#pagePost .post-detail-card'));
|
||||||
});
|
});
|
||||||
stageSharedGeometry(transition, { name: 'post-expand', duration: 960, moveOffset: 0.62 });
|
stageSharedGeometry(transition, { name: 'post-expand', duration: 960, moveOffset: 0.62 });
|
||||||
stageSharedGeometry(transition, { name: 'post-body', duration: 960, moveOffset: 0.62 });
|
stageSharedGeometry(transition, { name: 'post-body', duration: 960, moveOffset: 0.62 });
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
// 帖子详情页
|
// 帖子详情页
|
||||||
import { useEffect, useState, useCallback, useRef } from 'react';
|
import { useEffect, useState, useCallback, useMemo, useRef } from 'react';
|
||||||
import { API, uploadImage } from '@/lib/api';
|
import { API, uploadImage } from '@/lib/api';
|
||||||
import { useApp } from './AppProvider';
|
import { useApp } from './AppProvider';
|
||||||
import ReplyList from './ReplyList';
|
import ReplyList from './ReplyList';
|
||||||
@@ -39,7 +39,13 @@ export default function PostDetail({ postId, initialPost = null }) {
|
|||||||
}
|
}
|
||||||
}, [postId, refreshKey]);
|
}, [postId, refreshKey]);
|
||||||
|
|
||||||
useEffect(() => { load(); }, [load]);
|
const initialRefreshKey = useRef(refreshKey);
|
||||||
|
useEffect(() => {
|
||||||
|
if (initialPost?.id === postId && refreshKey === initialRefreshKey.current) return;
|
||||||
|
load();
|
||||||
|
}, [initialPost?.id, load, postId, refreshKey]);
|
||||||
|
const renderedContent = useMemo(() => renderMarkdown(post?.content), [post?.content]);
|
||||||
|
const renderedSignature = useMemo(() => renderMarkdown(post?.signature), [post?.signature]);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
@@ -165,7 +171,7 @@ export default function PostDetail({ postId, initialPost = null }) {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="post-content" style={{ fontSize: 16, lineHeight: 1.8 }} dangerouslySetInnerHTML={{ __html: renderMarkdown(post.content) }} />
|
<div className="post-content" dangerouslySetInnerHTML={{ __html: renderedContent }} />
|
||||||
{post.images && post.images.length > 0 && (
|
{post.images && post.images.length > 0 && (
|
||||||
<div className="post-images">
|
<div className="post-images">
|
||||||
{post.images.map((img, i) => (
|
{post.images.map((img, i) => (
|
||||||
@@ -174,7 +180,7 @@ export default function PostDetail({ postId, initialPost = null }) {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{post.signature && (
|
{post.signature && (
|
||||||
<div className="post-detail-signature" style={{ marginTop: 16, paddingTop: 12, borderTop: '1px solid var(--border-light)', fontSize: 12, color: 'var(--text-secondary)' }} dangerouslySetInnerHTML={{ __html: renderMarkdown(post.signature) }} />
|
<div className="post-detail-signature" style={{ marginTop: 16, paddingTop: 12, borderTop: '1px solid var(--border-light)', fontSize: 12, color: 'var(--text-secondary)' }} dangerouslySetInnerHTML={{ __html: renderedSignature }} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<ReplyList postId={postId} onRefresh={load} />
|
<ReplyList postId={postId} onRefresh={load} />
|
||||||
|
|||||||
Reference in new issue
Block a user