import type { ReactNode } from 'react'; import { useCallback } from 'react'; import React from 'react'; import type { ViewStyle } from 'react-native'; import Animated from 'react-native-reanimated'; import { useAlertAnimatedStyle } from '../hooks/useAlertAnimatedStyle'; import { useModalsContext } from '../hooks/useModalsContext'; import { hideAnimationFinished, hideAnimationStart } from '../state/action-creators'; import AvoidDismiss from './AvoidDismiss'; import type { CreateActionCallback } from '../types'; export interface WrapperComponentProps { children: (data: unknown, createActionCallback: CreateActionCallback) => ReactNode; style?: ViewStyle; } function WrapperComponent({ children, style }: WrapperComponentProps) { const { dispatch, options, state } = useModalsContext(); const wrapperStyle = useAlertAnimatedStyle(!!state.renderList[0]?.visible, options, () => dispatch(hideAnimationFinished()), ); const actionCallback = useCallback>( (fn) => () => { dispatch(hideAnimationStart()); if (fn) { fn(); } }, [dispatch], ); if (!state.renderList[0]) { return null; } return ( {children(state.renderList[0].data, actionCallback)} ); } export default WrapperComponent;