import React, { useEffect } from 'react'; import { View } from 'react-native'; import { Text, useTheme } from 'native-base'; import Animated, { useAnimatedStyle, useSharedValue, withSequence, withTiming, withDelay, Easing, } from 'react-native-reanimated'; import { ColorSchemeType } from 'native-base/lib/typescript/components/types'; export type ScoreMessage = { content: string; color?: ColorSchemeType; id: number; }; type PlayScoreProps = { score: number; streak: number; message?: ScoreMessage; }; export const PlayScore = ({ score, streak, message }: PlayScoreProps) => { const scoreMessageScale = useSharedValue(0); // this style should bounce in on enter and fade away const scoreMsgStyle = useAnimatedStyle(() => { return { transform: [{ scale: scoreMessageScale.value }], }; }); const { colors } = useTheme(); const textColor = colors.text; useEffect(() => { if (message) { scoreMessageScale.value = withSequence( withTiming(1, { duration: 400, easing: Easing.elastic(3), }), withDelay( 700, withTiming(0, { duration: 300, easing: Easing.out(Easing.cubic), }) ) ); } }, [message]); return ( {score} {message && ( {message.content} {streak > 0 && ( {`x${streak}`} )} )} ); };