import React, { useState, useCallback, useEffect } from "react";
import { Keyboard, StyleSheet } from "react-native";
import { AnimatePresence, Motion } from "@legendapp/motion";
import { useKeyboard } from "@react-native-community/hooks";
import BottomSheet from "./BottomSheet";
import { Palette } from "../styles";
import useLayoutType from "../hooks/useLayoutType";
export default ({
children,
bottomSheetRef,
snapPoints = ["25%", "50%"],
handleStyle = {},
...rest
}) => {
const [currentSnapPointIndex, setCurrentSnapPointIndex] = useState(0);
const { keyboardShown = false } = useKeyboard();
const { isWeb } = useLayoutType();
const handleSheetChanges = useCallback((index) => {
setCurrentSnapPointIndex(index);
if (index <= 0) {
Keyboard.dismiss();
}
}, []);
useEffect(() => {
if (bottomSheetRef.current && !isWeb && currentSnapPointIndex > 0) {
if (keyboardShown) {
bottomSheetRef.current.expand();
} else {
bottomSheetRef.current.snapToIndex(1);
}
}
}, [keyboardShown]);
return (
<>
{currentSnapPointIndex > 0 ? (
bottomSheetRef?.current?.close()}
>
) : null}
{children}
>
);
};