Skip to content

Instantly share code, notes, and snippets.

@Palisand
Created October 9, 2017 21:13
Show Gist options
  • Save Palisand/e91fb7bed4facd9af0df6b68b33d25f6 to your computer and use it in GitHub Desktop.
Save Palisand/e91fb7bed4facd9af0df6b68b33d25f6 to your computer and use it in GitHub Desktop.
Changes for scroll-to-cursor functionality.
- (RCTTextSelection *)selection
{
id<RCTBackedTextInputViewProtocol> backedTextInput = self.backedTextInputView;
UITextRange *selectedTextRange = backedTextInput.selectedTextRange;
return [[RCTTextSelection new] initWithStart:[backedTextInput offsetFromPosition:backedTextInput.beginningOfDocument toPosition:selectedTextRange.start]
end:[backedTextInput offsetFromPosition:backedTextInput.beginningOfDocument toPosition:selectedTextRange.end]
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
cursorPosition:[backedTextInput caretRectForPosition:selectedTextRange.start].origin];
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
}
...
- (void)textInputDidChangeSelection
{
if (!_onSelectionChange) {
return;
}
RCTTextSelection *selection = self.selection;
_onSelectionChange(@{
@"selection": @{
@"start": @(selection.start),
@"end": @(selection.end),
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
@"cursorPositionX": @(selection.cursorPosition.x),
@"cursorPositionY": @(selection.cursorPosition.y)
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
},
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment