Skip to content

Commit

Permalink
Fabric: Fixes insets not adjust when keyboard disappear (#47924)
Browse files Browse the repository at this point in the history
Summary:
Fixes #47731 .

[IOS] [FIXED] - Fabric: Fixes insets not adjust when keyboard disappear

Pull Request resolved: #47924

Test Plan: Demo in #47731

Reviewed By: blakef

Differential Revision: D66651865

Pulled By: cipolleschi

fbshipit-source-id: a75afbd1a7651f0c77022d913f910821c482fcf7
  • Loading branch information
zhongwuzw authored and blakef committed Dec 9, 2024
1 parent 7ea8e50 commit d105c2c
Showing 1 changed file with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,11 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)notification

UIEdgeInsets newEdgeInsets = _scrollView.contentInset;
CGFloat inset = MAX(scrollViewLowerY - keyboardEndFrame.origin.y, 0);
const auto &props = static_cast<const ScrollViewProps &>(*_props);
if (isInverted) {
newEdgeInsets.top = MAX(inset, _scrollView.contentInset.top);
newEdgeInsets.top = MAX(inset, props.contentInset.top);
} else {
newEdgeInsets.bottom = MAX(inset, _scrollView.contentInset.bottom);
newEdgeInsets.bottom = MAX(inset, props.contentInset.bottom);
}

CGPoint newContentOffset = _scrollView.contentOffset;
Expand All @@ -203,21 +204,18 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)notification
from:self
forEvent:nil]) {
if (CGRectEqualToRect(_firstResponderFocus, CGRectNull)) {
// Text input view is outside of the scroll view.
return;
}

CGRect viewIntersection = CGRectIntersection(self.firstResponderFocus, keyboardEndFrame);

if (CGRectIsNull(viewIntersection)) {
return;
}

// Inner text field focused
CGFloat focusEnd = CGRectGetMaxY(self.firstResponderFocus);
if (focusEnd > keyboardEndFrame.origin.y) {
// Text field active region is below visible area with keyboard - update diff to bring into view
contentDiff = keyboardEndFrame.origin.y - focusEnd;
UIView *inputAccessoryView = _firstResponderViewOutsideScrollView.inputAccessoryView;
if (inputAccessoryView) {
// Text input view is within the inputAccessoryView.
contentDiff = keyboardEndFrame.origin.y - keyboardBeginFrame.origin.y;
}
} else {
// Inner text field focused
CGFloat focusEnd = CGRectGetMaxY(self.firstResponderFocus);
if (focusEnd > keyboardEndFrame.origin.y) {
// Text field active region is below visible area with keyboard - update diff to bring into view
contentDiff = keyboardEndFrame.origin.y - focusEnd;
}
}
}

Expand All @@ -243,7 +241,7 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)notification
animations:^{
self->_scrollView.contentInset = newEdgeInsets;
self->_scrollView.verticalScrollIndicatorInsets = newEdgeInsets;
[self scrollToOffset:newContentOffset animated:NO];
[self scrollTo:newContentOffset.x y:newContentOffset.y animated:NO];
}
completion:nil];
}
Expand Down

0 comments on commit d105c2c

Please sign in to comment.