Skip to content

Commit f707703

Browse files
authored
Merge pull request Expensify#65807 from dukenv0307/fix/65736
[NO QA] Console error displayed on date selection for per-diem expenses
2 parents 8b943bb + 953cc8e commit f707703

1 file changed

Lines changed: 28 additions & 7 deletions

File tree

src/components/PopoverWithMeasuredContent.tsx

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {circularDeepEqual, deepEqual} from 'fast-equals';
2-
import React, {useContext, useMemo, useState} from 'react';
2+
import React, {useContext, useEffect, useMemo, useState} from 'react';
33
import type {LayoutChangeEvent} from 'react-native';
44
import {View} from 'react-native';
55
import usePrevious from '@hooks/usePrevious';
@@ -84,11 +84,18 @@ function PopoverWithMeasuredContent({
8484

8585
const modalId = useMemo(() => ComposerFocusManager.getId(), []);
8686

87-
if (!prevIsVisible && isVisible && shouldEnableNewFocusManagement) {
87+
useEffect(() => {
88+
if (prevIsVisible || !isVisible || !shouldEnableNewFocusManagement) {
89+
return;
90+
}
8891
ComposerFocusManager.saveFocusState(modalId);
89-
}
92+
}, [isVisible, shouldEnableNewFocusManagement, prevIsVisible, modalId]);
93+
94+
useEffect(() => {
95+
if (prevIsVisible || !isVisible || !isContentMeasured || shouldSkipRemeasurement) {
96+
return;
97+
}
9098

91-
if (!prevIsVisible && isVisible && isContentMeasured && !shouldSkipRemeasurement) {
9299
// Check if anything significant changed that would require re-measurement
93100
const hasAnchorPositionChanged = !deepEqual(prevAnchorPosition, anchorPosition);
94101
const hasWindowSizeChanged = !deepEqual(prevWindowDimensions, {windowWidth, windowHeight});
@@ -98,10 +105,24 @@ function PopoverWithMeasuredContent({
98105
// 1. We don't have static dimensions, OR
99106
// 2. The anchor position changed significantly, OR
100107
// 3. The window size changed significantly
101-
if (!hasStaticDimensions || hasAnchorPositionChanged || hasWindowSizeChanged) {
102-
setIsContentMeasured(false);
108+
if (hasStaticDimensions && !hasAnchorPositionChanged && !hasWindowSizeChanged) {
109+
return;
103110
}
104-
}
111+
112+
setIsContentMeasured(false);
113+
}, [
114+
prevIsVisible,
115+
isVisible,
116+
isContentMeasured,
117+
shouldSkipRemeasurement,
118+
prevAnchorPosition,
119+
anchorPosition,
120+
prevWindowDimensions,
121+
windowWidth,
122+
windowHeight,
123+
popoverDimensions.width,
124+
popoverDimensions.height,
125+
]);
105126

106127
/**
107128
* Measure the size of the popover's content.

0 commit comments

Comments
 (0)