animate picture selection/removal

This commit is contained in:
Hailey
2024-02-14 14:26:46 -08:00
parent 647045d5b1
commit ecf28c5b08
2 changed files with 22 additions and 24 deletions
@@ -1,5 +1,5 @@
import React from 'react' import React from 'react'
import {Pressable, StyleSheet} from 'react-native' import {LayoutAnimation, Pressable, StyleSheet} from 'react-native'
import {Camera_Stroke2_Corner0_Rounded as Camera} from '#/components/icons/Camera' import {Camera_Stroke2_Corner0_Rounded as Camera} from '#/components/icons/Camera'
import {useSetAvatar} from '#/screens/Onboarding/StepProfile/index' import {useSetAvatar} from '#/screens/Onboarding/StepProfile/index'
import {useTheme} from '#/alf' import {useTheme} from '#/alf'
@@ -22,33 +22,25 @@ export function SelectImageButton() {
const items = await openPicker({ const items = await openPicker({
aspect: [1, 1], aspect: [1, 1],
}) })
const item = items[0] let image = items[0]
if (!item) return if (!image) return
// TODO we need an alf modal for the cropper // TODO we need an alf modal for the cropper
if (isWeb) { if (!isWeb) {
const compressedImage = await compressIfNeeded(item) image = await openCropper({
mediaType: 'photo',
setAvatar(prev => ({ cropperCircleOverlay: true,
...prev, height: image.height,
image: compressedImage, width: image.width,
})) path: image.path,
return })
} }
image = await compressIfNeeded(image)
const croppedImage = await openCropper({ LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
mediaType: 'photo',
cropperCircleOverlay: true,
height: item.height,
width: item.width,
path: item.path,
})
const compressedImage = await compressIfNeeded(croppedImage)
setAvatar(prev => ({ setAvatar(prev => ({
...prev, ...prev,
image: compressedImage, image,
})) }))
}, [requestPhotoAccessIfNeeded, setAvatar]) }, [requestPhotoAccessIfNeeded, setAvatar])
+8 -2
View File
@@ -2,6 +2,7 @@ import React from 'react'
import { import {
FlatList, FlatList,
FlatListProps, FlatListProps,
LayoutAnimation,
ListRenderItemInfo, ListRenderItemInfo,
Pressable, Pressable,
StyleSheet, StyleSheet,
@@ -110,8 +111,12 @@ export function StepProfile() {
<View style={[a.align_center, a.pb_5xl]}> <View style={[a.align_center, a.pb_5xl]}>
<AvatarCircle /> <AvatarCircle />
</View> </View>
<Items type="emojis" /> {!avatar.image && (
<Items type="colors" /> <>
<Items type="emojis" />
<Items type="colors" />
</>
)}
</View> </View>
<OnboardingControls.Portal> <OnboardingControls.Portal>
@@ -143,6 +148,7 @@ function AvatarCircle() {
const Icon = avatar.placeholder.component const Icon = avatar.placeholder.component
const onPressRemoveAvatar = React.useCallback(() => { const onPressRemoveAvatar = React.useCallback(() => {
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
setAvatar(prev => ({ setAvatar(prev => ({
...prev, ...prev,
image: undefined, image: undefined,