Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/contexts/ModalProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const ModalProvider = ({ children }) => {
const [isOpen, setIsOpen] = useState(false);
const [isClosing, setIsClosing] = useState(false);

const onModalCloseEventRef = useRef(null);

const modalWrapperRef = useRef(null);
const isMouseDownInsideModal = useRef(false);

Expand All @@ -27,17 +29,20 @@ export const ModalProvider = ({ children }) => {

const pendingForClosingAnimation = () => {
closeTimeoutRef.current = setTimeout(() => {
setIsOpen(false);
setIsClosing(false);
closeTimeoutRef.current = null;
if (isClosing) {
setIsOpen(false);
setIsClosing(false);
closeTimeoutRef.current = null;
}
}, MODAL_CLOSE_DELAY);
};

const showModal = (ModalComponent) => {
const showModal = (ModalComponent, { onModalClose } = {}) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onModalClose 추가된 것 확인하였습니다. 롤링 상세에 추가 후 확인해보겠습니다!

resetTimer();
setModal(ModalComponent);
setIsOpen(true);
setIsClosing(false);
onModalCloseEventRef.current = onModalClose;
};

const closeModal = () => {
Expand All @@ -64,7 +69,12 @@ export const ModalProvider = ({ children }) => {
!modalWrapperRef.current?.contains(e.target) &&
isMouseDownInsideModal.current === false
) {
closeModal();
if (typeof onModalCloseEventRef.current === 'function') {
onModalCloseEventRef.current();
closeModal();
} else {
closeModal();
}
}
};

Expand Down
Loading