11import { circularDeepEqual , deepEqual } from 'fast-equals' ;
2- import React , { useContext , useMemo , useState } from 'react' ;
2+ import React , { useContext , useEffect , useMemo , useState } from 'react' ;
33import type { LayoutChangeEvent } from 'react-native' ;
44import { View } from 'react-native' ;
55import 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