Skip to content

Commit 62fc88a

Browse files
committed
Handle textfield focus in inverted scroll views
1 parent 08078a4 commit 62fc88a

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

packages/react-native/React/Views/ScrollView/RCTScrollView.m

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,21 +327,22 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)notification
327327
CGPoint newContentOffset = _scrollView.contentOffset;
328328
self.firstResponderFocus = CGRectNull;
329329

330+
CGFloat contentDiff = 0;
330331
if ([[UIApplication sharedApplication] sendAction:@selector(reactUpdateResponderOffsetForScrollView:) to:nil from:self forEvent:nil]) {
331332
// Inner text field focused
332333
CGFloat focusEnd = self.firstResponderFocus.origin.y + self.firstResponderFocus.size.height;
333334
if (focusEnd > endFrame.origin.y && focusEnd != INFINITY) {
334-
// Text field active region is below visible area with keyboard - update offset to bring into view
335-
newContentOffset.y += focusEnd - endFrame.origin.y;
335+
// Text field active region is below visible area with keyboard - update diff to bring into view
336+
contentDiff = endFrame.origin.y - focusEnd;
336337
}
337338
} else if (endFrame.origin.y <= beginFrame.origin.y) {
338339
// Keyboard opened for other reason
339-
CGFloat contentDiff = endFrame.origin.y - beginFrame.origin.y;
340-
if (self.inverted) {
341-
newContentOffset.y += contentDiff;
342-
} else {
343-
newContentOffset.y -= contentDiff;
344-
}
340+
contentDiff = endFrame.origin.y - beginFrame.origin.y;
341+
}
342+
if (self.inverted) {
343+
newContentOffset.y += contentDiff;
344+
} else {
345+
newContentOffset.y -= contentDiff;
345346
}
346347

347348
if (@available(iOS 14.0, *)) {

0 commit comments

Comments
 (0)