feat: replace alert with toast message

This commit is contained in:
Vinicius Souza 2024-10-28 10:57:50 -03:00
parent 5cc80a35df
commit 938f378e89
2 changed files with 19 additions and 4 deletions

View file

@ -20,7 +20,8 @@ export function ToastMessage({
<Toast
nativeID={`toast=${id}`}
action={action}
bgColor={action === 'success' ? '$green500' : '$red500'}>
bgColor={action === 'success' ? '$green500' : '$red500'}
mt="$10">
<VStack space="xs" w="$full">
<Pressable onPress={onClose} alignSelf="flex-end">
<Icon as={X} color="$coolGray50" size="md" />

View file

@ -1,6 +1,6 @@
import { useState } from 'react';
import { Alert, ScrollView, TouchableOpacity } from 'react-native';
import { Center, Heading, Text, VStack } from '@gluestack-ui/themed';
import { ScrollView, TouchableOpacity } from 'react-native';
import { Center, Heading, Text, useToast, VStack } from '@gluestack-ui/themed';
import * as ImagePicker from 'expo-image-picker';
import * as FileSystem from 'expo-file-system';
@ -8,10 +8,13 @@ import { Button } from '@components/Button';
import { Input } from '@components/Input';
import { ScreenHeader } from '@components/ScreenHeader';
import { UserPhoto } from '@components/UserPhoto';
import { ToastMessage } from '@components/ToastMessage';
export function Profile() {
const [userPhoto, setUserPhoto] = useState('https://i.pravatar.cc/200');
const toast = useToast();
async function handleUserPhotoSelection() {
try {
const photoSelection = await ImagePicker.launchImageLibraryAsync({
@ -33,7 +36,18 @@ export function Profile() {
};
if (photoInfo.size && photoInfo.size > 5242880) {
return Alert.alert('Essa imagem é muito grande. Escolha uma de até 5MB');
return toast.show({
placement: 'top',
render: ({ id }) => (
<ToastMessage
id={id}
action="error"
onClose={() => toast.close(id)}
title="Imagem muito grande!"
description="Por favor, escolha uma de até 5MB"
/>
),
});
}
setUserPhoto(photoURI);