From c38e69af160a82ea393a3e0fdf27041d7cc31151 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 25 Apr 2024 16:27:11 -0500 Subject: [PATCH] Simplify avi creator --- .../StepProfile/AvatarCreatorCircle.tsx | 7 +- .../StepProfile/AvatarCreatorItems.tsx | 252 ++++++++---------- src/screens/Onboarding/StepProfile/index.tsx | 29 +- 3 files changed, 128 insertions(+), 160 deletions(-) diff --git a/src/screens/Onboarding/StepProfile/AvatarCreatorCircle.tsx b/src/screens/Onboarding/StepProfile/AvatarCreatorCircle.tsx index a81bef1d34..1cd68eb61b 100644 --- a/src/screens/Onboarding/StepProfile/AvatarCreatorCircle.tsx +++ b/src/screens/Onboarding/StepProfile/AvatarCreatorCircle.tsx @@ -1,8 +1,8 @@ import React from 'react' import {View} from 'react-native' -import {Avatar} from '#/screens/Onboarding/StepProfile/index' -import {atoms as a, native, useTheme, web} from '#/alf' +import {Avatar} from '#/screens/Onboarding/StepProfile/index' +import {atoms as a, useTheme} from '#/alf' export function AvatarCreatorCircle({ avatar, @@ -21,14 +21,13 @@ export function AvatarCreatorCircle({ a.overflow_hidden, a.align_center, a.justify_center, + a.border, t.atoms.border_contrast_high, { height: size, width: size, backgroundColor: avatar.backgroundColor, }, - web({borderWidth: 2}), - native({borderWidth: 1}), ], }), [avatar.backgroundColor, size, t.atoms.border_contrast_high], diff --git a/src/screens/Onboarding/StepProfile/AvatarCreatorItems.tsx b/src/screens/Onboarding/StepProfile/AvatarCreatorItems.tsx index 19cdd363d3..98c01ce7dc 100644 --- a/src/screens/Onboarding/StepProfile/AvatarCreatorItems.tsx +++ b/src/screens/Onboarding/StepProfile/AvatarCreatorItems.tsx @@ -1,10 +1,8 @@ import React from 'react' -import {ListRenderItemInfo, Pressable, View} from 'react-native' -// Using the FlatList from RNGH allows us to nest the scroll views on Android. The default FlatList won't allow -// scrolling inside of the vertical ScrollView -import {FlatList} from 'react-native-gesture-handler' +import {View} from 'react-native' +import {msg, Trans} from '@lingui/macro' +import {useLingui} from '@lingui/react' -import {atoms as a, native, useBreakpoints, useTheme, web} from '#/alf' import {Avatar} from '#/screens/Onboarding/StepProfile/index' import { AvatarColor, @@ -13,100 +11,18 @@ import { EmojiName, emojiNames, } from '#/screens/Onboarding/StepProfile/types' +import {atoms as a, useTheme} from '#/alf' +import {Button, ButtonIcon} from '#/components/Button' +import {Text} from '#/components/Typography' -function Circle({children}: React.PropsWithChildren<{}>) { - const t = useTheme() - - const styles = React.useMemo( - () => ({ - container: [ - a.rounded_full, - a.overflow_hidden, - a.align_center, - a.justify_center, - t.atoms.bg_contrast_25, - web({borderWidth: 2}), - native({borderWidth: 1}), - { - height: 60, - width: 60, - margin: 4, - }, - ], - }), - [t.atoms.bg_contrast_25], - ) - - return ( - - {children} - - ) -} - -function ColorItem({ - color, - setAvatar, -}: { - color: AvatarColor - setAvatar: React.Dispatch> -}) { - const onPress = React.useCallback(() => { - setAvatar(prev => ({ - ...prev, - backgroundColor: color, - })) - }, [color, setAvatar]) - - return ( - - - - ) -} - -function EmojiItem({ - emojiName, - avatar, - setAvatar, -}: { - emojiName: EmojiName - avatar: Avatar - setAvatar: React.Dispatch> -}) { - const t = useTheme() - const Icon = React.useMemo(() => emojiItems[emojiName].component, [emojiName]) - - const onPress = React.useCallback(() => { - setAvatar(prev => ({ - ...prev, - placeholder: emojiItems[emojiName], - })) - }, [emojiName, setAvatar]) - - const selected = React.useMemo( - () => avatar.placeholder.name === emojiName, - [avatar.placeholder.name, emojiName], - ) - - return ( - - - - - - ) +const ACTIVE_BORDER_WIDTH = 3 +const ACTIVE_BORDER_STYLES = { + top: -ACTIVE_BORDER_WIDTH, + bottom: -ACTIVE_BORDER_WIDTH, + left: -ACTIVE_BORDER_WIDTH, + right: -ACTIVE_BORDER_WIDTH, + opacity: 0.5, + borderWidth: 3, } export function AvatarCreatorItems({ @@ -118,58 +34,112 @@ export function AvatarCreatorItems({ avatar: Avatar setAvatar: React.Dispatch> }) { - const {gtMobile} = useBreakpoints() + const {_} = useLingui() + const t = useTheme() + const isEmojis = type === 'emojis' - const styles = React.useMemo( - () => ({ - flatListOuter: gtMobile - ? { - height: 338, - } - : [a.flex_row, a.align_center, {height: 70}], - }), - [gtMobile], - ) - - const colorRenderItem = React.useCallback( - ({item}: ListRenderItemInfo) => { - return + const onSelectEmoji = React.useCallback( + (emoji: EmojiName) => { + setAvatar(prev => ({ + ...prev, + placeholder: emojiItems[emoji], + })) }, [setAvatar], ) - const emojiRenderItem = React.useCallback( - ({item}: ListRenderItemInfo) => { - return ( - - ) + const onSelectColor = React.useCallback( + (color: AvatarColor) => { + setAvatar(prev => ({ + ...prev, + backgroundColor: color, + })) }, - [avatar, setAvatar], + [setAvatar], ) return ( - - - // Changing the value of numColumns on the fly isn't supported, so we want the flatlist to re-render whenever - // the size of the screen changes. Should only happen when `isTabletOrDesktop` changes. - key={gtMobile ? 0 : 1} - data={type === 'colors' ? avatarColors : emojiNames} - renderItem={type === 'colors' ? colorRenderItem : emojiRenderItem} - keyExtractor={item => item} - style={[gtMobile && {marginHorizontal: 10}]} - contentContainerStyle={[ - a.align_center, - gtMobile && type === 'colors' && a.pr_xs, - !gtMobile && {paddingHorizontal: 40}, - ]} - numColumns={gtMobile && type === 'emojis' ? 4 : undefined} - showsHorizontalScrollIndicator={gtMobile && type === 'colors'} - horizontal={!gtMobile} - /> + + + {isEmojis ? ( + Select an emoji + ) : ( + Select a color + )} + + + + {isEmojis + ? emojiNames.map(emojiName => ( + + )) + : avatarColors.map(color => ( + + ))} + ) } diff --git a/src/screens/Onboarding/StepProfile/index.tsx b/src/screens/Onboarding/StepProfile/index.tsx index 89426b7e35..023c19f35f 100644 --- a/src/screens/Onboarding/StepProfile/index.tsx +++ b/src/screens/Onboarding/StepProfile/index.tsx @@ -63,7 +63,7 @@ export function StepProfile() { const {requestPhotoAccessIfNeeded} = usePhotoLibraryPermission() const creatorControl = Dialog.useDialogControl() - const {state, dispatch} = React.useContext(Context) + const {dispatch} = React.useContext(Context) const [avatar, setAvatar] = React.useState({ placeholder: emojiItems.at, backgroundColor: randomColor, @@ -173,18 +173,17 @@ export function StepProfile() { an avatar. - + -