Commit 37d4ffa2 authored by hewenhao's avatar hewenhao

feat: type

parent eba4c7b1
import { Image } from '@tarojs/components' import { Image } from '@tarojs/components'
import { useEffect, useRef, useMemo } from 'react' import { useEffect, useRef, useMemo } from 'react'
import { usePageScroll, createIntersectionObserver, getCurrentInstance, getMenuButtonBoundingClientRect } from '@tarojs/taro' import { usePageScroll, createIntersectionObserver, getCurrentInstance, getMenuButtonBoundingClientRect, IntersectionObserver } from '@tarojs/taro'
type RoundTagProps = { type RoundTagProps = {
url: string; url: string;
...@@ -22,11 +22,14 @@ const RoundTag = (props: RoundTagProps) => { ...@@ -22,11 +22,14 @@ const RoundTag = (props: RoundTagProps) => {
const uid = useMemo(() => `tag_${id}`, [id]) const uid = useMemo(() => `tag_${id}`, [id])
useEffect(() => { useEffect(() => {
let observer let observer: IntersectionObserver | null = null
if (ready) { if (ready) {
lastEffectedScroll.current = scrollRef.current lastEffectedScroll.current = scrollRef.current
const navVal = nav.current const navVal = nav.current
observer = (createIntersectionObserver as any)().relativeToViewport({ bottom: 0, top: -navVal.height - navVal.top - 5 }) // @ts-ignore
observer = createIntersectionObserver()
observer
.relativeToViewport({ bottom: 0, top: -navVal.height - navVal.top - 5 })
.observe(`#${uid}`, ({ intersectionRatio }) => { .observe(`#${uid}`, ({ intersectionRatio }) => {
const show = intersectionRatio > 0 const show = intersectionRatio > 0
......
...@@ -23,7 +23,10 @@ const ShortCut = (props: ShortCutProps) => { ...@@ -23,7 +23,10 @@ const ShortCut = (props: ShortCutProps) => {
useEffect(() => { useEffect(() => {
lastEffectedScroll.current = scrollRef.current lastEffectedScroll.current = scrollRef.current
let observer = (createIntersectionObserver as any)().relativeToViewport({ bottom: 0 }) // @ts-ignore
let observer = createIntersectionObserver()
observer
.relativeToViewport({ bottom: 0 })
.observe(`#${CurrentRoundId}`, ({ intersectionRatio }) => { .observe(`#${CurrentRoundId}`, ({ intersectionRatio }) => {
const show = intersectionRatio > 0 const show = intersectionRatio > 0
setIsShow(show) setIsShow(show)
...@@ -36,7 +39,7 @@ const ShortCut = (props: ShortCutProps) => { ...@@ -36,7 +39,7 @@ const ShortCut = (props: ShortCutProps) => {
return () => { return () => {
if (observer) { if (observer) {
observer.disconnect() observer.disconnect()
observer = null observer = null!
} }
} }
}, []) }, [])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment