import { OverlayContainer } from '@react-native-aria/overlays' ; import React from 'react' ; import { Platform } from 'react-native' ; import { Modal } from 'react-native' ; import { useKeyboardDismissable } from '../../../hooks' ; import { ExitAnimationContext } from './ExitAnimationContext' ; interface IOverlayProps { isOpen ? : boolean ; children ? : any ; useRNModalOnAndroid ? : boolean ; onRequestClose ? : ( ( ) => any ) | undefined ; isKeyboardDismissable ? : boolean ; animationPreset ? : string ; } export function Overlay ( { children , isOpen , useRNModalOnAndroid = false , isKeyboardDismissable = true , animationPreset = 'fade' , onRequestClose , } ) { const [ exited , setExited ] = React . useState ( ! isOpen ) ; useKeyboardDismissable ( { enabled : isOpen && isKeyboardDismissable , callback : onRequestClose ? onRequestClose : ( ) => { } , } ) ; if ( exited && ! isOpen ) { return null ; } if ( Platform . OS === 'android' && useRNModalOnAndroid ) { return ( < ExitAnimationContext . Provider value = { { exited , setExited } } > < Modal transparent visible = { true } onRequestClose = { onRequestClose } > { children } < /Modal> < /ExitAnimationContext.Provider>); } return ( < OverlayContainer > < ExitAnimationContext . Provider value = { { exited , setExited } } > { children } < /ExitAnimationContext.Provider> < /OverlayContainer>); }