TextInput: Hacks related to missed textInputDidChange were moved to adapter

Summary:
iOS has tendency to skip `textInputDidChange` event (irregulary, across all dispatch ways: target-action, delegate, notification center)
when text input looses focus. Usually it happens when autocorrection applies some changes automatically on loosing focus, but I think these are bunch of different cases.
So, the workaround is pretty simple: if there was no `textInputDidChange` event between `shouldChangeText` and `didEndEditing`, we create it manually.

Previously these workaround complicate our business logic, now they was decoupled in separate adapter.

Reviewed By: mmmulani

Differential Revision: D5317651

fbshipit-source-id: 138143213e8752fe9682229c51685aef614c00dd
This commit is contained in:
Valentin Shergin
2017-07-18 14:33:43 -07:00
committed by Facebook Github Bot
parent d69e60bb7a
commit 4ff3e101ac
3 changed files with 28 additions and 18 deletions

View File

@@ -28,7 +28,6 @@
{
RCTUITextField *_backedTextInput;
BOOL _submitted;
NSString *_finalText;
CGSize _previousContentSize;
}
@@ -164,7 +163,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
- (BOOL)textInputShouldEndEditing
{
_finalText = _backedTextInput.text;
return YES;
}
@@ -176,14 +174,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
key:nil
eventCount:_nativeEventCount];
if (![_finalText isEqualToString:_backedTextInput.text]) {
_finalText = nil;
// iOS does't send event `UIControlEventEditingChanged` if the change was happened because of autocorrection
// which was triggered by loosing focus. We assume that if `text` was changed in the middle of loosing focus process,
// we did not receive that event. So, we call `textFieldDidChange` manually.
[self textInputDidChange];
}
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeEnd
reactTag:self.reactTag
text:_backedTextInput.text