import React, {useEffect, useState} from 'react' import {View} from 'react-native' import Animated, {FadeInUp, FadeOutUp} from 'react-native-reanimated' import RootSiblings from 'react-native-root-siblings' import {useSafeAreaInsets} from 'react-native-safe-area-context' import { FontAwesomeIcon, Props as FontAwesomeProps, } from '@fortawesome/react-native-fontawesome' import {atoms as a, useTheme} from '#/alf' import {Text} from '#/components/Typography' import {IS_TEST} from '#/env' const TIMEOUT = 2e3 export function show( message: string, icon: FontAwesomeProps['icon'] = 'check', ) { if (IS_TEST) return const item = new RootSiblings() // timeout has some leeway to account for the animation setTimeout(() => { item.destroy() }, TIMEOUT + 1e3) } function Toast({ message, icon, }: { message: string icon: FontAwesomeProps['icon'] }) { const t = useTheme() const {top} = useSafeAreaInsets() // for the exit animation to work on iOS the animated component // must not be the root component // so we need to wrap it in a view and unmount the toast ahead of time const [alive, setAlive] = useState(true) useEffect(() => { setTimeout(() => { setAlive(false) }, TIMEOUT) }, []) return ( {alive && ( {message} )} ) }