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
28 changes: 28 additions & 0 deletions src/components/DatePicker/DatePickerModal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {setYear} from 'date-fns';
import React, {useEffect, useRef, useState} from 'react';
import type {View} from 'react-native';
import {isInternalPopstateInProgress} from '@components/Modal/internalPopstateGuard';
import PopoverWithMeasuredContent from '@components/PopoverWithMeasuredContent';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import getPlatform from '@libs/getPlatform';
import {setDraftValues} from '@userActions/FormActions';
import CONST from '@src/CONST';
import CalendarPicker from './CalendarPicker';
Expand Down Expand Up @@ -47,6 +49,32 @@ function DatePickerModal({
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {isSmallScreenWidth} = useResponsiveLayout();

useEffect(() => {
Comment thread
x-dev90 marked this conversation as resolved.
if (
getPlatform() !== CONST.PLATFORM.WEB ||
!isSmallScreenWidth ||
!isVisible ||
!shouldCloseWhenBrowserNavigationChanged ||
typeof window === 'undefined' ||
typeof window.addEventListener !== 'function'
) {
return;
}

const listener = () => {
if (isInternalPopstateInProgress()) {
return;
}

onClose?.();
};

window.addEventListener('popstate', listener);
return () => {
window.removeEventListener('popstate', listener);
};
}, [isSmallScreenWidth, isVisible, onClose, shouldCloseWhenBrowserNavigationChanged]);

useEffect(() => {
if (shouldSaveDraft && formID) {
setDraftValues(formID, {[inputID]: selectedDate});
Expand Down
Loading