import React, { forwardRef, useEffect, useImperativeHandle, useRef } from 'react' import { Animated, Dimensions, Image, Modal as RNModal, StyleProp, Text, TouchableOpacity, View, } from 'react-native' import R from '../../res' import s from './BottomSheetModalStyles' import { IBottomSheetModalProps } from './BottomSheetModalTypes' const animationDuration = 350 const { height: screenHeight } = Dimensions.get('window') export type BottomSheetHandle = { close(): void } const BottomSheetModal = forwardRef( ({ onClose, texts, styles, content, contentHeight = screenHeight / 2 }, ref) => { const contentYPosition = useRef(new Animated.Value(contentHeight)).current const showContent = () => { Animated.timing(contentYPosition, { toValue: 0, duration: animationDuration, useNativeDriver: true, }).start() } const hideContent = () => { Animated.timing(contentYPosition, { toValue: contentHeight, duration: animationDuration, useNativeDriver: true, }).start(onClose) } useEffect(() => { showContent() }) const onCloseHandler = () => { hideContent() } const animatedStyle: StyleProp = { height: contentHeight, transform: [ { translateY: contentYPosition, }, ], } useImperativeHandle(ref, () => ({ async close() { hideContent() }, })) const mergedStyle = [s.animatedContent, animatedStyle, styles?.content] const title = texts?.title || 'Title' return ( {title} {content} ) } ) export default BottomSheetModal