11import { AnimatePresence , m } from 'motion/react'
22import type { FC } from 'react'
3- import { useCallback , useRef } from 'react'
3+ import { useCallback } from 'react'
44import { useTranslation } from 'react-i18next'
55
66import { clsxm } from '~/lib/cn'
@@ -13,7 +13,6 @@ export const LivePhotoBadge: FC<LivePhotoBadgeProps> = ({
1313 isLivePhotoPlaying,
1414} ) => {
1515 const { t } = useTranslation ( )
16- const hoverTimerRef = useRef < NodeJS . Timeout | null > ( null )
1716
1817 const handlePlay = useCallback ( async ( ) => {
1918 if ( ! livePhotoRef . current ?. getIsVideoLoaded ( ) || isLivePhotoPlaying ) return
@@ -25,32 +24,36 @@ export const LivePhotoBadge: FC<LivePhotoBadgeProps> = ({
2524 livePhotoRef . current ?. stop ( )
2625 } , [ livePhotoRef , isLivePhotoPlaying ] )
2726
28- // Desktop hover logic
29- const handleBadgeMouseEnter = useCallback ( ( ) => {
30- if ( isMobileDevice ) return
31- if ( hoverTimerRef . current ) clearTimeout ( hoverTimerRef . current )
32- hoverTimerRef . current = setTimeout ( handlePlay , 200 )
33- } , [ handlePlay ] )
27+ const handleClick = useCallback ( ( ) => {
28+ if ( ! livePhotoRef . current ?. getIsVideoLoaded ( ) ) return
3429
35- const handleBadgeMouseLeave = useCallback ( ( ) => {
36- if ( isMobileDevice ) return
37- if ( hoverTimerRef . current ) clearTimeout ( hoverTimerRef . current )
38- handleStop ( )
39- } , [ handleStop ] )
30+ if ( isLivePhotoPlaying ) {
31+ handleStop ( )
32+ } else {
33+ handlePlay ( )
34+ }
35+ } , [ livePhotoRef , isLivePhotoPlaying , handlePlay , handleStop ] )
4036
4137 return (
4238 < >
4339 { /* Live Photo 标识 */ }
4440 < div
4541 className = { clsxm (
4642 'absolute z-20 flex items-center space-x-1 rounded-xl bg-black/50 px-1 py-1 text-xs text-white transition-all duration-200' ,
47- ! isMobileDevice && 'cursor-pointer hover:bg-black/70' ,
43+ 'cursor-pointer hover:bg-black/70' ,
44+ isLivePhotoPlaying && 'bg-accent/70 hover:bg-accent/80' ,
4845 import . meta. env . DEV ? 'top-16 right-4' : 'top-12 lg:top-4 left-4' ,
4946 ) }
50- onMouseEnter = { handleBadgeMouseEnter }
51- onMouseLeave = { handleBadgeMouseLeave }
47+ onClick = { handleClick }
5248 >
53- < i className = "i-mingcute-live-photo-line size-4" />
49+ < i
50+ className = { clsxm (
51+ 'size-4' ,
52+ isLivePhotoPlaying
53+ ? 'i-mingcute-live-photo-fill'
54+ : 'i-mingcute-live-photo-line' ,
55+ ) }
56+ />
5457 < span className = "mr-1" > { t ( 'photo.live.badge' ) } </ span >
5558 </ div >
5659
@@ -64,7 +67,7 @@ export const LivePhotoBadge: FC<LivePhotoBadgeProps> = ({
6467 className = "pointer-events-none absolute bottom-4 left-1/2 z-20 -translate-x-1/2"
6568 >
6669 < div className = "flex items-center gap-2 rounded bg-black/50 px-2 py-1 text-xs text-white" >
67- < i className = "i-mingcute-live-photo-line " />
70+ < i className = "i-mingcute-live-photo-fill " />
6871 < span > { t ( 'photo.live.playing' ) } </ span >
6972 </ div >
7073 </ m . div >
0 commit comments