65 lines
2.6 KiB
TypeScript
65 lines
2.6 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { View } from 'react-native';
|
|
import Animated, { Easing, interpolate, useAnimatedStyle, useReducedMotion, useSharedValue, withDelay, withTiming } from 'react-native-reanimated';
|
|
import Svg, { Path } from 'react-native-svg';
|
|
|
|
import { HEART } from '@/components/post/icons';
|
|
|
|
// 튀어 나가는 작은 하트: x·y 이동, 회전, 색 (웹 BURST)
|
|
const BURST: [number, number, number, string][] = [
|
|
[-86, -60, -24, '#ff3b5c'],
|
|
[84, -66, 22, '#ff8e4e'],
|
|
[-104, 18, -40, '#ffc86e'],
|
|
[102, 24, 36, '#ff3b5c'],
|
|
[-48, -104, -8, '#ff8aa0'],
|
|
[52, -100, 12, '#ffc86e'],
|
|
];
|
|
|
|
function Bit({ dx, dy, rot, color }: { dx: number; dy: number; rot: number; color: string }) {
|
|
const p = useSharedValue(0);
|
|
useEffect(() => {
|
|
p.value = withDelay(80, withTiming(1, { duration: 900, easing: Easing.bezier(0.2, 0.8, 0.3, 1) }));
|
|
}, [p]);
|
|
const style = useAnimatedStyle(() => ({
|
|
opacity: interpolate(p.value, [0, 0.25, 1], [0, 1, 0]),
|
|
transform: [{ translateX: dx * p.value }, { translateY: dy * p.value }, { scale: interpolate(p.value, [0, 1], [0.4, 1.1]) }, { rotate: `${rot * p.value}deg` }],
|
|
}));
|
|
return (
|
|
<Animated.View style={[{ position: 'absolute' }, style]}>
|
|
<Svg viewBox="0 0 24 24" width={20} height={20} fill={color}>
|
|
<Path d={HEART} />
|
|
</Svg>
|
|
</Animated.View>
|
|
);
|
|
}
|
|
|
|
function Toast() {
|
|
const p = useSharedValue(0);
|
|
useEffect(() => {
|
|
p.value = withTiming(1, { duration: 1300, easing: Easing.bezier(0.2, 0.9, 0.3, 1) });
|
|
}, [p]);
|
|
const style = useAnimatedStyle(() => ({
|
|
opacity: interpolate(p.value, [0, 0.18, 0.78, 1], [0, 1, 1, 0]),
|
|
transform: [{ translateY: interpolate(p.value, [0, 0.18, 0.78, 1], [14, 0, 0, -8]) }, { scale: interpolate(p.value, [0, 0.18, 0.3, 1], [0.85, 1.06, 1, 1]) }],
|
|
}));
|
|
return (
|
|
<Animated.View className="absolute top-[58%] rounded-full bg-white px-4 py-2" style={[{ boxShadow: '0 8px 18px rgb(40 48 74 / 0.18)' }, style]}>
|
|
<Animated.Text className="font-jua text-[17px] text-heart">좋아요했어요!</Animated.Text>
|
|
</Animated.View>
|
|
);
|
|
}
|
|
|
|
/** 좋아요 때 하트 조각이 튀어 나가고 '좋아요했어요!' 가 떴다 사라진다 */
|
|
export function LikeBurst() {
|
|
const reduce = useReducedMotion();
|
|
if (reduce) return null;
|
|
return (
|
|
<View pointerEvents="none" className="absolute inset-0 items-center justify-center" accessibilityElementsHidden importantForAccessibility="no-hide-descendants">
|
|
{BURST.map(([dx, dy, rot, color], k) => (
|
|
<Bit key={k} dx={dx} dy={dy} rot={rot} color={color} />
|
|
))}
|
|
<Toast />
|
|
</View>
|
|
);
|
|
}
|