Commit 0f5a2097 authored by hewenhao's avatar hewenhao

feat: update

parent adedecb8
...@@ -3,3 +3,4 @@ export * from './use-countdown' ...@@ -3,3 +3,4 @@ export * from './use-countdown'
export * from './use-format-tick' export * from './use-format-tick'
export * from './use-request' export * from './use-request'
export * from './use-toggle' export * from './use-toggle'
export * from './use-focus'
import { useState } from 'react'
import { useDidHide, useDidShow } from '@tarojs/taro'
export function useFocus () {
const [isFocus, setIsFocus] = useState(true)
useDidHide(() => {
setIsFocus(false)
})
useDidShow(() => {
setIsFocus(true)
})
return isFocus
}
import { Image } from '@tarojs/components' import { Image } from '@tarojs/components'
import { useEffect, useRef, useMemo } from 'react' import { useEffect, useRef, useMemo, useState } from 'react'
import assets from '@/assets/oss/assets-round' import assets from '@/assets/oss/assets-round'
import { useFocus } from '@/hooks'
import { usePageScroll, createIntersectionObserver, getCurrentInstance, getMenuButtonBoundingClientRect, IntersectionObserver, nextTick } from '@tarojs/taro' import { usePageScroll, createIntersectionObserver, getCurrentInstance, getMenuButtonBoundingClientRect, IntersectionObserver, nextTick } from '@tarojs/taro'
type StageTagProps = { type StageTagProps = {
...@@ -11,27 +12,33 @@ type StageTagProps = { ...@@ -11,27 +12,33 @@ type StageTagProps = {
} }
const StageTag = (props: StageTagProps) => { const StageTag = (props: StageTagProps) => {
const page = useMemo(() => getCurrentInstance().page, [])
const nav = useRef(getMenuButtonBoundingClientRect()) const nav = useRef(getMenuButtonBoundingClientRect())
const { url, className, id, ready } = props const { url, className, id, ready } = props
const [isAnimated, setIsAnimated] = useState(false)
const isFocus = useFocus()
const scrollRef = useRef(0) const scrollRef = useRef(0)
usePageScroll(payload => { usePageScroll(payload => {
scrollRef.current = payload.scrollTop scrollRef.current = payload.scrollTop
}) })
useEffect(() => {
setIsAnimated(false)
}, [url])
const uid = useMemo(() => `tag_${id}`, [id]) const uid = useMemo(() => `tag_${id}`, [id])
const bgid = useMemo(() => `bg_${id}`, [id]) const bgid = useMemo(() => `bg_${id}`, [id])
useEffect(() => { useEffect(() => {
let observer: IntersectionObserver | null = null let observer: IntersectionObserver | null = null
const fn = () => { const fn = () => {
if (ready) { console.log(ready, isFocus, 111)
if (ready && isFocus) {
const navVal = nav.current const navVal = nav.current
// @ts-ignore // @ts-ignore
observer = createIntersectionObserver() observer = createIntersectionObserver()
let isAnimated = false
const animateBg = () => { const animateBg = () => {
const page = getCurrentInstance().page
page?.animate?.(`#${bgid}`, [ page?.animate?.(`#${bgid}`, [
{ opacity: 1 }, { opacity: 1 },
{ opacity: 0 }, { opacity: 0 },
...@@ -51,8 +58,8 @@ const StageTag = (props: StageTagProps) => { ...@@ -51,8 +58,8 @@ const StageTag = (props: StageTagProps) => {
clearTimeout(timer) clearTimeout(timer)
} }
timer = setTimeout(() => { timer = setTimeout(() => {
isAnimated = true setIsAnimated(true)
getCurrentInstance().page?.animate?.(`#${uid}`, [ page?.animate?.(`#${uid}`, [
{ opacity: 0, translateY: 50, scale: [1, 1] }, { opacity: 0, translateY: 50, scale: [1, 1] },
{ opacity: 1, translateY: -20, scale: [1.5, 1.5], offset: 0.5 }, { opacity: 1, translateY: -20, scale: [1.5, 1.5], offset: 0.5 },
{ opacity: 1, translateY: -20, scale: [1.5, 1.5], offset: 0.75 }, { opacity: 1, translateY: -20, scale: [1.5, 1.5], offset: 0.75 },
...@@ -71,7 +78,7 @@ const StageTag = (props: StageTagProps) => { ...@@ -71,7 +78,7 @@ const StageTag = (props: StageTagProps) => {
clearTimeout(timer) clearTimeout(timer)
} }
timer = setTimeout(() => { timer = setTimeout(() => {
isAnimated = true setIsAnimated(true)
animateBg() animateBg()
}, 900) }, 900)
} }
...@@ -88,7 +95,7 @@ const StageTag = (props: StageTagProps) => { ...@@ -88,7 +95,7 @@ const StageTag = (props: StageTagProps) => {
observer = null observer = null
} }
} }
}, [uid, ready, bgid, url]) }, [uid, ready, bgid, url, page, isFocus, isAnimated])
if (!ready) { if (!ready) {
return null return 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