fix: clean up home top mask measurement
This commit is contained in:
@@ -90,10 +90,15 @@ export default function Index() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
let cancelled = false
|
||||||
|
let measureTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
|
||||||
const measureTitle = () => {
|
const measureTitle = () => {
|
||||||
|
if (cancelled) return
|
||||||
Taro.createSelectorQuery()
|
Taro.createSelectorQuery()
|
||||||
.select('.home-header')
|
.select('.home-header')
|
||||||
.boundingClientRect((rect: { top?: number; bottom?: number; height?: number } | null) => {
|
.boundingClientRect((rect: any) => {
|
||||||
|
if (cancelled) return
|
||||||
if (!rect || typeof rect.bottom !== 'number' || typeof rect.height !== 'number') {
|
if (!rect || typeof rect.bottom !== 'number' || typeof rect.height !== 'number') {
|
||||||
const fallbackRange = Math.max(48, safe.headerPaddingTop * 0.45)
|
const fallbackRange = Math.max(48, safe.headerPaddingTop * 0.45)
|
||||||
titleMetricsRef.current = {
|
titleMetricsRef.current = {
|
||||||
@@ -113,10 +118,15 @@ export default function Index() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Taro.nextTick(() => {
|
Taro.nextTick(() => {
|
||||||
setTimeout(measureTitle, 80)
|
if (cancelled) return
|
||||||
|
measureTimer = setTimeout(measureTitle, 80)
|
||||||
})
|
})
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
cancelled = true
|
||||||
|
if (measureTimer !== null) {
|
||||||
|
clearTimeout(measureTimer)
|
||||||
|
}
|
||||||
if (scrollFrameRef.current !== null) {
|
if (scrollFrameRef.current !== null) {
|
||||||
clearTimeout(scrollFrameRef.current)
|
clearTimeout(scrollFrameRef.current)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user