diff --git a/src/components/Heart.tsx b/src/components/Heart.tsx index 9c17e6e..9f65d77 100644 --- a/src/components/Heart.tsx +++ b/src/components/Heart.tsx @@ -1,6 +1,7 @@ -import React, { memo } from 'react'; -import { Group, Path } from '@shopify/react-native-skia'; +import React, { memo, useCallback, useEffect } from 'react'; +import { Group, Path, runSpring, useValue } from '@shopify/react-native-skia'; import { palette } from '../constants/theming'; +import { screenHeight } from '../constants/dimensions'; interface HeartProps { x: number; @@ -8,6 +9,20 @@ interface HeartProps { } function Heart({ x, y }: HeartProps) { + const opacity = useValue(1); + + const changeOpacity = useCallback( + () => + runSpring(opacity, 0, { + mass: screenHeight / 3, + }), + [opacity] + ); + + useEffect(() => { + changeOpacity(); + }, [changeOpacity]); + return ( @@ -15,6 +30,7 @@ function Heart({ x, y }: HeartProps) { diff --git a/src/components/Star.tsx b/src/components/Star.tsx index 25b698b..bf609d5 100644 --- a/src/components/Star.tsx +++ b/src/components/Star.tsx @@ -1,6 +1,7 @@ -import React, { memo } from 'react'; -import { Group, Path } from '@shopify/react-native-skia'; +import React, { memo, useCallback, useEffect } from 'react'; +import { Group, Path, runSpring, useValue } from '@shopify/react-native-skia'; import { palette } from '../constants/theming'; +import { screenHeight } from '../constants/dimensions'; interface StarProps { x: number; @@ -8,6 +9,20 @@ interface StarProps { } function Star({ x, y }: StarProps) { + const opacity = useValue(1); + + const changeOpacity = useCallback( + () => + runSpring(opacity, 0, { + mass: screenHeight / 3, + }), + [opacity] + ); + + useEffect(() => { + changeOpacity(); + }, [changeOpacity]); + return ( @@ -15,6 +30,7 @@ function Star({ x, y }: StarProps) {