import Icon from '@components/Icon' import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import { getColors, Theme } from '@utils/styles/themes' import React, { RefObject } from 'react' import { AccessibilityInfo } from 'react-native' import FlashMessage, { hideMessage, showMessage } from 'react-native-flash-message' import { useSafeAreaInsets } from 'react-native-safe-area-context' import haptics from './haptics' const displayMessage = ({ ref, duration = 'short', autoHide = true, message, description, onPress, theme, type }: | { ref?: RefObject duration?: 'short' | 'long' autoHide?: boolean message: string description?: string onPress?: () => void theme?: undefined type?: undefined } | { ref?: RefObject duration?: 'short' | 'long' autoHide?: boolean message: string description?: string onPress?: () => void theme: Theme type: 'success' | 'error' | 'warning' }) => { AccessibilityInfo.announceForAccessibility(message + '.' + description) enum iconMapping { success = 'CheckCircle', error = 'XCircle', warning = 'AlertCircle' } enum colorMapping { success = 'blue', error = 'red', warning = 'secondary' } if (type && type === 'error') { haptics('Error') } if (ref) { ref.current?.showMessage({ duration: type === 'error' ? 8000 : duration === 'short' ? 3000 : 5000, autoHide, message, description, onPress, ...(theme && type && { renderFlashMessageIcon: () => { return ( ) } }) }) } else { showMessage({ duration: type === 'error' ? 8000 : duration === 'short' ? 3000 : 5000, autoHide, message, description, onPress, ...(theme && type && { renderFlashMessageIcon: () => { return ( ) } }) }) } } const removeMessage = () => { // if (ref) { // ref.current?.hideMessage() // } else { hideMessage() // } } const Message = React.forwardRef((_, ref) => { const { colors, theme } = useTheme() const insets = useSafeAreaInsets() return ( ) }) export { Message, displayMessage, removeMessage }