@@ -137,24 +137,18 @@ const KeyboardAvoidingView = forwardRef<
137137 initialFrame . value === null ||
138138 behavior !== "height"
139139 ) {
140+ // When the keyboard is open in height mode, storing the shrunk
141+ // frame would cause a feedback loop (resize → recalculate →
142+ // resize), so that case falls through to the else-if below.
140143 // eslint-disable-next-line react-compiler/react-compiler
141144 initialFrame . value = layout ;
142145 } else if ( automaticOffset ) {
143- // The if-branch above skips layout updates in height mode while
144- // the keyboard is open to prevent a feedback loop (shrunk height
145- // stored → animatedStyle recalculates → view resizes → repeat).
146- // But automaticOffset uses measureInWindow which can return stale
147- // y=0 during modal animation — the corrected y arrives on the
148- // next onLayout (when the view resizes for the keyboard) and
149- // would be dropped without this branch. So accept position
150- // updates but keep the original height.
151- // eslint-disable-next-line react-compiler/react-compiler
152- initialFrame . value = {
153- x : layout . x ,
154- y : layout . y ,
155- width : layout . width ,
156- height : initialFrame . value . height ,
157- } ;
146+ // automaticOffset uses measureInWindow, which may return stale
147+ // y=0 during modal animation. The corrected y arrives on a
148+ // later onLayout that falls through here. Accept the corrected
149+ // position but preserve the original height to avoid the same
150+ // feedback loop.
151+ initialFrame . value = { ...layout , height : initialFrame . value . height } ;
158152 }
159153 } ,
160154 [ behavior , automaticOffset ] ,
@@ -164,13 +158,9 @@ const KeyboardAvoidingView = forwardRef<
164158 const layout = e . nativeEvent . layout ;
165159
166160 if ( automaticOffset ) {
161+ // ref is always set here — onLayout only fires after mount
167162 internalRef . current ?. measureInWindow ( ( x , y ) => {
168- runOnUI ( onLayoutWorklet ) ( {
169- x,
170- y,
171- width : layout . width ,
172- height : layout . height ,
173- } ) ;
163+ runOnUI ( onLayoutWorklet ) ( { ...layout , x, y } ) ;
174164 } ) ;
175165 } else {
176166 runOnUI ( onLayoutWorklet ) ( layout ) ;
0 commit comments