animate picture selection/removal
This commit is contained in:
@@ -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({
|
||||||
|
|
||||||
setAvatar(prev => ({
|
|
||||||
...prev,
|
|
||||||
image: compressedImage,
|
|
||||||
}))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const croppedImage = await openCropper({
|
|
||||||
mediaType: 'photo',
|
mediaType: 'photo',
|
||||||
cropperCircleOverlay: true,
|
cropperCircleOverlay: true,
|
||||||
height: item.height,
|
height: image.height,
|
||||||
width: item.width,
|
width: image.width,
|
||||||
path: item.path,
|
path: image.path,
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
image = await compressIfNeeded(image)
|
||||||
|
|
||||||
const compressedImage = await compressIfNeeded(croppedImage)
|
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
|
||||||
|
|
||||||
setAvatar(prev => ({
|
setAvatar(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
image: compressedImage,
|
image,
|
||||||
}))
|
}))
|
||||||
}, [requestPhotoAccessIfNeeded, setAvatar])
|
}, [requestPhotoAccessIfNeeded, setAvatar])
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
|
{!avatar.image && (
|
||||||
|
<>
|
||||||
<Items type="emojis" />
|
<Items type="emojis" />
|
||||||
<Items type="colors" />
|
<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,
|
||||||
|
|||||||
Reference in New Issue
Block a user