Polish Douyin reader: scroll-to-top fab, stable bodyReady, drop dead marktext images.
Avoid remount flicker on silent reload and strip three absolute local image paths that never resolve in-package. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
1313f24b10
commit
71157a2df4
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -115,26 +115,25 @@ export default function ReaderPage() {
|
||||
if (!loadedRef.current) load()
|
||||
}, [bookId])
|
||||
|
||||
// 抖音:首帧只画壳,下一帧再挂 Markdown;勿绑 activeChapter(滚动改章会整页重渲卡死)
|
||||
// 抖音:仅首次(或显式重置 bodyReady)挂 Markdown,避免 silent setData 整页卸装闪烁
|
||||
useEffect(() => {
|
||||
if (!isTt || !data) return
|
||||
setBodyReady(false)
|
||||
if (!isTt || !data || bodyReady) return
|
||||
const t = setTimeout(() => setBodyReady(true), 16)
|
||||
return () => clearTimeout(t)
|
||||
}, [data])
|
||||
}, [isTt, data, bodyReady])
|
||||
|
||||
const chapterTotal = data?.chapters?.length || 0
|
||||
|
||||
// 抖音:正文就绪后慢速预挂后续章。禁止 40ms 狂刷 setState——会抢滚动、把视口抖回封面
|
||||
useEffect(() => {
|
||||
if (!isTt || !bodyReady || !data) return
|
||||
const total = (data.chapters || []).length
|
||||
if (total <= 1) return
|
||||
if (!isTt || !bodyReady || chapterTotal <= 1) return
|
||||
// 首屏先多挂几章,目录跳转更稳;之后只慢速补,真正加速靠触底
|
||||
setMountedCount((n) => Math.max(n, Math.min(total, 3)))
|
||||
setMountedCount((n) => Math.max(n, Math.min(chapterTotal, 3)))
|
||||
const id = setInterval(() => {
|
||||
// 跳章回钉期间勿增 DOM,否则高度突变 + pageScrollTo 互抢 → 回封面/原地抖
|
||||
// 跳章回钉期间勿增章,否则高度突变 + pageScrollTo 互抢 → 回封面/原地抖
|
||||
if (Date.now() < jumpLockUntil.current) return
|
||||
setMountedCount((n) => {
|
||||
if (n >= total) {
|
||||
if (n >= chapterTotal) {
|
||||
clearInterval(id)
|
||||
return n
|
||||
}
|
||||
@ -142,7 +141,7 @@ export default function ReaderPage() {
|
||||
})
|
||||
}, 220)
|
||||
return () => clearInterval(id)
|
||||
}, [isTt, bodyReady, data])
|
||||
}, [isTt, bodyReady, chapterTotal])
|
||||
|
||||
async function load(silent = false) {
|
||||
try {
|
||||
@ -156,7 +155,10 @@ export default function ReaderPage() {
|
||||
setActiveChapter(0)
|
||||
setProgress(0)
|
||||
restored.current = false
|
||||
if (isTt) setMountedCount(1)
|
||||
if (isTt) {
|
||||
setMountedCount(1)
|
||||
setBodyReady(false)
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
if (!silent) Taro.showToast({ title: e.message || '加载失败', icon: 'none' })
|
||||
@ -912,7 +914,13 @@ export default function ReaderPage() {
|
||||
</View>
|
||||
|
||||
{showTopFab ? (
|
||||
<View className="top-fab" onClick={() => jumpToChapter(0)}>
|
||||
<View
|
||||
className="top-fab"
|
||||
onClick={() => {
|
||||
clearPinWatch()
|
||||
Taro.pageScrollTo({ scrollTop: 0, duration: 280 }).catch(() => {})
|
||||
}}
|
||||
>
|
||||
<Text className="top-fab-text">↑</Text>
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user