Skip to content

Commit d96427c

Browse files
thomasvoclaude
andcommitted
chore: split and improve onLayoutWorklet comments
Split the single block comment into two focused comments — one per branch — so readers understand each path independently. Add ref safety comment on measureInWindow call. Remove debug console.log. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7286b9d commit d96427c

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/components/KeyboardAvoidingView/index.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,17 @@ 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.
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.
151151
// eslint-disable-next-line react-compiler/react-compiler
152152
initialFrame.value = {
153153
x: layout.x,
@@ -164,6 +164,7 @@ const KeyboardAvoidingView = forwardRef<
164164
const layout = e.nativeEvent.layout;
165165

166166
if (automaticOffset) {
167+
// ref is always set here — onLayout only fires after mount
167168
internalRef.current?.measureInWindow((x, y) => {
168169
runOnUI(onLayoutWorklet)({
169170
x,

0 commit comments

Comments
 (0)