Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ - (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics
_previousContentSize = _backedTextInputView.contentSize;
static_cast<const TextInputEventEmitter &>(*_eventEmitter).onContentSizeChange([self _textInputMetrics]);
}

if (layoutMetrics.frame.size.height > oldLayoutMetrics.frame.size.height) {
[self _scrollCaretIntoEnclosingScrollView];
}
}

- (void)prepareForRecycle
Expand Down Expand Up @@ -843,6 +847,38 @@ - (void)scrollCursorIntoView
}
}

- (void)_scrollCaretIntoEnclosingScrollView
{
if (![_backedTextInputView isKindOfClass:[UITextView class]] || !_backedTextInputView.isFirstResponder) {
return;
}

UIScrollView *enclosingScrollView = nil;
for (UIView *view = self.superview; view != nil; view = view.superview) {
if ([view isKindOfClass:[UIScrollView class]]) {
enclosingScrollView = (UIScrollView *)view;
break;
}
}
if (enclosingScrollView == nil) {
return;
}

UITextRange *selectedTextRange = _backedTextInputView.selectedTextRange;
if (selectedTextRange == nil) {
return;
}

[_backedTextInputView layoutIfNeeded];
CGRect caretRect = [_backedTextInputView caretRectForPosition:selectedTextRange.end];
if (CGRectIsNull(caretRect) || CGRectIsInfinite(caretRect) || CGRectGetMaxY(caretRect) <= 0) {
return;
}

CGRect caretRectInScrollView = [_backedTextInputView convertRect:caretRect toView:enclosingScrollView];
[enclosingScrollView scrollRectToVisible:CGRectInset(caretRectInScrollView, 0, -4) animated:NO];
}

- (void)_setMultiline:(BOOL)multiline
{
[_backedTextInputView removeFromSuperview];
Expand Down
Loading