import React, { createContext, useState, useRef } from "react"; import { Comment as CommentType } from "replyke-core"; import BottomSheet from "@gorhom/bottom-sheet"; import { BottomSheetMethods } from "@gorhom/bottom-sheet/lib/typescript/types"; type SheetManagerContext = { commentOptionsSheetRef: React.RefObject; reportCommentSheetRef: React.RefObject; openCommentOptionsSheet: (newComment?: CommentType) => void; closeCommentOptionsSheet: () => void; openReportCommentSheet: () => void; closeReportCommentSheet: () => void; optionsComment: CommentType | null; setOptionsComment: React.Dispatch>; reportedComment: CommentType | null; setReportedComment: React.Dispatch>; }; export const SheetManagerContext = createContext>( {} ); export const SheetManagerProvider = ({ children, }: { children: React.ReactNode; }) => { const commentOptionsSheetRef = useRef(null); const reportCommentSheetRef = useRef(null); const [optionsComment, setOptionsComment] = useState( null ); const [reportedComment, setReportedComment] = useState( null ); const openCommentOptionsSheet = (newComment?: CommentType) => { if (newComment) setOptionsComment(newComment); commentOptionsSheetRef.current?.snapToIndex(0); }; const closeCommentOptionsSheet = () => { commentOptionsSheetRef.current?.close(); }; const openReportCommentSheet = (newComment?: CommentType) => { if (newComment) setOptionsComment(newComment); reportCommentSheetRef.current?.snapToIndex(0); }; const closeReportCommentSheet = () => { reportCommentSheetRef.current?.close(); }; return ( {children} ); };