From f032e7afafda5f4683574fb5699d25ea364829d2 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Thu, 28 Feb 2019 17:54:05 +0800 Subject: [PATCH 1/3] [iOS] Fixed onChange prop of textinput not be called in some cases --- .../Text/TextInput/RCTBaseTextInputView.m | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index 0a8ea15b7c0e..d105f3c03b0d 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -392,6 +392,16 @@ - (BOOL)textInputShouldChangeTextInRange:(NSRange)range replacementText:(NSStrin notifyDelegate:YES]; [self textInputDidChange]; + + _nativeEventCount++; + + if (_onChange) { + _onChange(@{ + @"text": _predictedText, + @"target": self.reactTag, + @"eventCount": @(_nativeEventCount), + }); + } } return NO; @@ -423,6 +433,16 @@ - (BOOL)textInputShouldChangeTextInRange:(NSRange)range replacementText:(NSStrin @"eventCount": @(_nativeEventCount), }); } + + _nativeEventCount++; + + if (_onChange) { + _onChange(@{ + @"text": _predictedText, + @"target": self.reactTag, + @"eventCount": @(_nativeEventCount), + }); + } return YES; } @@ -446,16 +466,6 @@ - (void)textInputDidChange [self textInputDidChangeSelection]; _predictedText = backedTextInputView.attributedText.string; } - - _nativeEventCount++; - - if (_onChange) { - _onChange(@{ - @"text": self.attributedText.string, - @"target": self.reactTag, - @"eventCount": @(_nativeEventCount), - }); - } } - (void)textInputDidChangeSelection From c3d7aab26c876eed26c3f745fd8783397bcc3289 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Fri, 15 Mar 2019 15:00:33 +0800 Subject: [PATCH 2/3] Consolidated onChange to textInputDidChange method --- .../Text/TextInput/RCTBaseTextInputView.m | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index d105f3c03b0d..98cb098521a4 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -392,16 +392,6 @@ - (BOOL)textInputShouldChangeTextInRange:(NSRange)range replacementText:(NSStrin notifyDelegate:YES]; [self textInputDidChange]; - - _nativeEventCount++; - - if (_onChange) { - _onChange(@{ - @"text": _predictedText, - @"target": self.reactTag, - @"eventCount": @(_nativeEventCount), - }); - } } return NO; @@ -434,21 +424,17 @@ - (BOOL)textInputShouldChangeTextInRange:(NSRange)range replacementText:(NSStrin }); } - _nativeEventCount++; - - if (_onChange) { - _onChange(@{ - @"text": _predictedText, - @"target": self.reactTag, - @"eventCount": @(_nativeEventCount), - }); - } + // Sometimes, even we return YES, UIKit may not call textInputDidChange delegate, like click keyboard predictive text. So we have trick here, perform textInputDidChange by ourself. + [self performSelector:@selector(textInputDidChange) withObject:nil afterDelay:0.1]; return YES; } - (void)textInputDidChange { + // If textInputDidChange be called by UIKit delegate, we cancel our own perform operation + [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(textInputDidChange) object:nil]; + [self updateLocalData]; id backedTextInputView = self.backedTextInputView; @@ -466,6 +452,16 @@ - (void)textInputDidChange [self textInputDidChangeSelection]; _predictedText = backedTextInputView.attributedText.string; } + + _nativeEventCount++; + + if (_onChange) { + _onChange(@{ + @"text": self.attributedText.string, + @"target": self.reactTag, + @"eventCount": @(_nativeEventCount), + }); + } } - (void)textInputDidChangeSelection From 2d66dfd75db65a604a464fc8fed980146613b86a Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Tue, 21 May 2019 11:51:37 +0800 Subject: [PATCH 3/3] Revert "Consolidated onChange to textInputDidChange method" This reverts commit c3d7aab26c876eed26c3f745fd8783397bcc3289. --- .../Text/TextInput/RCTBaseTextInputView.m | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index 98cb098521a4..d105f3c03b0d 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -392,6 +392,16 @@ - (BOOL)textInputShouldChangeTextInRange:(NSRange)range replacementText:(NSStrin notifyDelegate:YES]; [self textInputDidChange]; + + _nativeEventCount++; + + if (_onChange) { + _onChange(@{ + @"text": _predictedText, + @"target": self.reactTag, + @"eventCount": @(_nativeEventCount), + }); + } } return NO; @@ -424,17 +434,21 @@ - (BOOL)textInputShouldChangeTextInRange:(NSRange)range replacementText:(NSStrin }); } - // Sometimes, even we return YES, UIKit may not call textInputDidChange delegate, like click keyboard predictive text. So we have trick here, perform textInputDidChange by ourself. - [self performSelector:@selector(textInputDidChange) withObject:nil afterDelay:0.1]; + _nativeEventCount++; + + if (_onChange) { + _onChange(@{ + @"text": _predictedText, + @"target": self.reactTag, + @"eventCount": @(_nativeEventCount), + }); + } return YES; } - (void)textInputDidChange { - // If textInputDidChange be called by UIKit delegate, we cancel our own perform operation - [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(textInputDidChange) object:nil]; - [self updateLocalData]; id backedTextInputView = self.backedTextInputView; @@ -452,16 +466,6 @@ - (void)textInputDidChange [self textInputDidChangeSelection]; _predictedText = backedTextInputView.attributedText.string; } - - _nativeEventCount++; - - if (_onChange) { - _onChange(@{ - @"text": self.attributedText.string, - @"target": self.reactTag, - @"eventCount": @(_nativeEventCount), - }); - } } - (void)textInputDidChangeSelection