Commit 0f5a2097 authored by hewenhao's avatar hewenhao

feat: update

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