import React, { ReactNode, useMemo } from 'react' import { useWindowDimensions, View } from 'react-native' import Animated from 'react-native-reanimated' import { GestureDetector } from 'react-native-gesture-handler' import type { AnimationAPI } from '../hooks/useAnimationAPI' import type { NotificationState } from '../hooks/useNotificationsStates' import { styles } from '../utils/styles' import { Constants } from '../config' import { calculateNotificationPositionCoordintates } from '../utils/calculateNotificationPositionCoordintates' type Props = { children: ReactNode state: Pick< NotificationState, | 'longPressHandlerRef' | 'panHandlerRef' | 'setNotificationHeight' | 'notificationOffset' | 'isPortrait' | 'notificationWidth' > animationAPI: Pick notificationTopPosition?: number } export const GestureHandler = ({ children, state, animationAPI, notificationTopPosition, }: Props) => { const { width } = useWindowDimensions() const { calculatedNotificationWidth, top, left, right } = calculateNotificationPositionCoordintates({ screenWidth: width, notificationOffset: state.notificationOffset, notificationWidth: state.notificationWidth, notificationTopPosition, }) // Get the gesture from the animationAPI const gesture = useMemo(() => { return animationAPI.dragGesture }, [animationAPI.dragGesture]) return ( state.setNotificationHeight(e.nativeEvent.layout.height)} style={[ animationAPI.animatedStyles, styles.container, Constants.isAndroid ? styles.containerAndroid : styles.containerIos, { top, left, right, width: calculatedNotificationWidth, }, ]}> {children} ) }