import React from 'react'
import { Touchable } from '../Touchable'
import { View } from '../View'
import { } from '../../utils'
import { BackdropProps } from './types'
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
import { MobileStyleRegistry } from '../../Registry'
import { useStylesFor } from '../../hooks'
import { FadeIn, FadeOut } from 'react-native-reanimated'
export * from './styles'
export * from './types'
export const Backdrop = (props: BackdropProps) => {
const {
visible,
children,
wrapperProps = {},
style,
entering,
exiting,
...rest
} = {
...Backdrop.defaultProps,
...props,
}
const styles = useStylesFor(Backdrop.styleRegistryName, style)
const isPressable = !!props?.onPress
/** Early return unmounts the node entirely when hidden, which means the `exiting` animation will NOT play — callers that need a fade-out must keep `visible` true until after the exit animation completes, or drive visibility through `opacity`/`pointerEvents` instead. */
if (!visible) return null
return (
{isPressable
?
: null}
{children}
)
}
Backdrop.styleRegistryName = 'Backdrop'
Backdrop.elements = ['wrapper', 'touchable', 'transition']
Backdrop.rootElement = 'wrapper'
Backdrop.withVariantTypes = (styles: S) => {
return Backdrop as (props: StyledComponentProps) => IJSX
}
Backdrop.defaultProps = {
entering: FadeIn.duration(100).build(),
exiting: FadeOut.duration(100).delay(100).build(),
} as Partial
MobileStyleRegistry.registerComponent(Backdrop)