Fixed incorrect selection coordinates when text gets moved to a new line and text input grows.
💡 Motivation and Context
The problem happens because our text is bigger and can not fit into current layout. If we read coordinates we get +Inf and of course it's not reasonable to send such events to JS.
To fix this problem we need to wait for layout update (next frame) and send event only after that. This is exactly what i did in this PR:
if textView.canSelectionFitIntoLayout {
updateSelectionPosition(textInput: textView, sendEvent: onSelectionChange)
} else {
// when multiline input grows we need to wait for layout to be updated
// otherwise start/end positions will be incorrect (0/-1)
DispatchQueue.main.asyncAfter(deadline: .now() + UIUtils.nextFrame) {
updateSelectionPosition(textInput: textView, sendEvent: self.onSelectionChange)
}
}
added canSelectionFitIntoLayout property extension to UITextInput;
use canSelectionFitIntoLayout to detect whether we can send event immediately or need to wait for one frmae for layout to be updated and send event only after that;
🤔 How Has This Been Tested?
Tested manually using code sample provided in the issue.
📸 Screenshots (if appropriate):
Before
After
📝 Checklist
[x] CI successfully passed
[x] I added new mocks and corresponding unit-tests if library API was changed
📜 Description
Fixed incorrect selection coordinates when text gets moved to a new line and text input grows.
💡 Motivation and Context
The problem happens because our text is bigger and can not fit into current layout. If we read coordinates we get
+Inf
and of course it's not reasonable to send such events to JS.To fix this problem we need to wait for layout update (next frame) and send event only after that. This is exactly what i did in this PR:
Closes https://github.com/kirillzyusko/react-native-keyboard-controller/issues/489
📢 Changelog
iOS
canSelectionFitIntoLayout
property extension toUITextInput
;canSelectionFitIntoLayout
to detect whether we can send event immediately or need to wait for one frmae for layout to be updated and send event only after that;🤔 How Has This Been Tested?
Tested manually using code sample provided in the issue.
📸 Screenshots (if appropriate):
📝 Checklist