diff --git a/src/screens/Onboarding/StepProfile/index.tsx b/src/screens/Onboarding/StepProfile/index.tsx index ab9a1dd5d6..3c83cab9f3 100644 --- a/src/screens/Onboarding/StepProfile/index.tsx +++ b/src/screens/Onboarding/StepProfile/index.tsx @@ -2,7 +2,9 @@ import React from 'react' import { ColorValue, FlatList, + FlatListProps, ListRenderItemInfo, + Pressable, StyleSheet, View, } from 'react-native' @@ -34,10 +36,17 @@ type AvatarPlaceholder = 'thinking' | 'heart' | 'laughing' interface Avatar { imageUri?: string - backgroundColor?: ColorValue - placeholder?: AvatarPlaceholder + backgroundColor?: Color + placeholder?: Emoji } +const AvatarContext = React.createContext({} as Avatar) +const SetAvatarContext = React.createContext< + React.Dispatch> +>({} as React.Dispatch>) +const useAvatar = () => React.useContext(AvatarContext) +const useSetAvatar = () => React.useContext(SetAvatarContext) + export function StepProfile() { const {_} = useLingui() const t = useTheme() @@ -56,46 +65,46 @@ export function StepProfile() { }, [track, dispatch]) return ( - - + + + + - - <Trans>Upload a profile picture</Trans> - - - Help people know you're not a bot! - + + <Trans>Upload a profile picture</Trans> + + + Help people know you're not a bot! + - - - - + + + + - - - - + + + + + + ) } -function AvatarCircle({ - avatar, - setAvatar, -}: { - avatar: Avatar - setAvatar: React.Dispatch> -}) { +function AvatarCircle() { + const avatar = useAvatar() + if (avatar.imageUri) { return ( @@ -127,15 +136,30 @@ const emojiItems: Record = { } function ColorItem({color}: {color: Color}) { + const avatar = useAvatar() + const setAvatar = useSetAvatar() + + const onPress = React.useCallback(() => { + setAvatar(prev => ({ + ...prev, + backgroundColor: color, + })) + }, [color, setAvatar]) + if (color === 'image') return null return ( - ) } @@ -144,10 +168,31 @@ function colorRenderItem({item}: ListRenderItemInfo) { } function EmojiItem({emoji}: {emoji: Emoji}) { + const avatar = useAvatar() + const setAvatar = useSetAvatar() + + const onPress = React.useCallback(() => { + setAvatar(prev => ({ + ...prev, + placeholder: emoji, + })) + }, [emoji, setAvatar]) + return ( - - {emojiItems[emoji]} - + + {emojiItems[emoji]} + ) } function emojiRenderItem({item}: ListRenderItemInfo) { @@ -157,23 +202,25 @@ function emojiRenderItem({item}: ListRenderItemInfo) { function Items({type}: {type: 'emojis' | 'colors'}) { if (type === 'colors') { return ( - - style={{height: 100}} - data={colors} - renderItem={colorRenderItem} - horizontal - contentContainerStyle={styles.flatListContainer} - /> + + + style={{height: 100}} + data={colors} + renderItem={colorRenderItem} + {...commonFlatListProps} + /> + ) } return ( - - data={emojis} - renderItem={emojiRenderItem} - horizontal - contentContainerStyle={styles.flatListContainer} - /> + + + data={emojis} + renderItem={emojiRenderItem} + {...commonFlatListProps} + /> + ) } @@ -189,8 +236,17 @@ const styles = StyleSheet.create({ width: 90, marginHorizontal: 5, }, + flatListOuter: { + height: 100, + }, flatListContainer: { paddingLeft: 40, paddingRight: 40, }, }) + +const commonFlatListProps: Partial> = { + horizontal: true, + contentContainerStyle: styles.flatListContainer, + showsHorizontalScrollIndicator: false, +}