From 6c7302ef8d24bdac590211163a943d50755e6657 Mon Sep 17 00:00:00 2001 From: Hailey Date: Wed, 14 Feb 2024 20:35:25 -0800 Subject: [PATCH] animate grow/shrink selections --- .../StepProfile/SelectImageButton.tsx | 4 +- src/screens/Onboarding/StepProfile/index.tsx | 89 ++++++++++++------- 2 files changed, 60 insertions(+), 33 deletions(-) diff --git a/src/screens/Onboarding/StepProfile/SelectImageButton.tsx b/src/screens/Onboarding/StepProfile/SelectImageButton.tsx index 6a8ff58e5f..5cc897c6cb 100644 --- a/src/screens/Onboarding/StepProfile/SelectImageButton.tsx +++ b/src/screens/Onboarding/StepProfile/SelectImageButton.tsx @@ -78,8 +78,8 @@ const styles = StyleSheet.create({ justifyContent: 'center', }, paletteContainer: { - height: 80, - width: 80, + height: 70, + width: 70, marginHorizontal: 5, }, }) diff --git a/src/screens/Onboarding/StepProfile/index.tsx b/src/screens/Onboarding/StepProfile/index.tsx index f082771f40..714f47f63b 100644 --- a/src/screens/Onboarding/StepProfile/index.tsx +++ b/src/screens/Onboarding/StepProfile/index.tsx @@ -44,6 +44,11 @@ import { PlaceholderCanvasRef, } from '#/screens/Onboarding/StepProfile/PlaceholderCanvas' import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' +import Animated, { + useAnimatedStyle, + useSharedValue, + withTiming, +} from 'react-native-reanimated' interface Avatar { image?: { @@ -188,7 +193,7 @@ function AvatarCircle() { {height: 40, width: 40, bottom: 5, right: 5}, ]} onPress={onPressRemoveAvatar}> - + ) @@ -203,13 +208,45 @@ function AvatarCircle() { backgroundColor: avatar.backgroundColor, }, ]}> - + ) } -function ColorItem({color}: {color: AvatarColor}) { +function AnimatedCircle({ + selected, + children, +}: React.PropsWithChildren<{selected: boolean}>) { const t = useTheme() + const size = useSharedValue(selected ? 80 : 70) + + React.useEffect(() => { + if (selected && size.value !== 80) { + size.value = withTiming(80) + } else if (!selected && size.value !== 70) { + size.value = withTiming(70) + } + }, [selected, size]) + + const animatedStyle = useAnimatedStyle(() => ({ + height: size.value, + width: size.value, + })) + + return ( + + {children} + + ) +} + +function ColorItem({color}: {color: AvatarColor}) { const avatar = useAvatar() const setAvatar = useSetAvatar() @@ -221,19 +258,13 @@ function ColorItem({color}: {color: AvatarColor}) { }, [color, setAvatar]) return ( - + + + ) } function colorRenderItem({item}: ListRenderItemInfo) { @@ -258,19 +289,14 @@ function EmojiItem({emojiName}: {emojiName: EmojiName}) { } return ( - - - + + + + + ) } function emojiRenderItem({item}: ListRenderItemInfo) { @@ -367,8 +393,8 @@ const styles = StyleSheet.create({ justifyContent: 'center', }, paletteContainer: { - height: 80, - width: 80, + height: 70, + width: 70, marginHorizontal: 5, }, flatListOuter: { @@ -379,6 +405,7 @@ const styles = StyleSheet.create({ flatListContainer: { paddingLeft: 40, paddingRight: 40, + alignItems: 'center', }, })