Skip to content

Commit

Permalink
feat: 바텀시트에 드래그로 닫기 기능 추가
Browse files Browse the repository at this point in the history
드래그 기능 세부 조절은 나중에
  • Loading branch information
happyGyu committed Jun 29, 2024
1 parent 0496667 commit 2846416
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/common/BottomSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnimatePresence, motion } from "framer-motion";
import { AnimatePresence, motion, useDragControls } from "framer-motion";
import { type ReactNode, useEffect } from "react";

type BottomSheetProps = {
Expand All @@ -12,6 +12,8 @@ const BottomSheet: React.FC<BottomSheetProps> = ({
onClose,
children,
}) => {
const dragControls = useDragControls();

useEffect(() => {
if (isOpen) {
document.body.style.overflow = "hidden";
Expand All @@ -38,6 +40,15 @@ const BottomSheet: React.FC<BottomSheetProps> = ({
exit={{ y: "100%" }}
transition={{ duration: 0.3, ease: "easeInOut" }}
onClick={(e) => e.stopPropagation()}
drag="y"
dragElastic={0}
dragConstraints={{ top: 0 }}
dragControls={dragControls}
onDragEnd={(_, info) => {
if (info.offset.y > 10) {
onClose();
}
}}
>
{children}
</motion.div>
Expand Down

0 comments on commit 2846416

Please # to comment.