From 76ff627ef4f54118375f7bd43b8680b5b8303595 Mon Sep 17 00:00:00 2001 From: magicien Date: Fri, 9 Mar 2018 01:41:10 +0900 Subject: [PATCH 1/5] Add text property to RCTBaseTextInputView - Add text VIEW_PROPERTY to RCTBaseTextInputViewManager.m - Add text accessor to RCTBaseTextInputView.m --- Libraries/Text/TextInput/RCTBaseTextInputView.m | 10 ++++++++++ Libraries/Text/TextInput/RCTBaseTextInputViewManager.m | 1 + 2 files changed, 11 insertions(+) diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index d9c47ff16311d4..e3dffecd584681 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -93,6 +93,16 @@ - (void)setReactBorderInsets:(UIEdgeInsets)reactBorderInsets [self setNeedsLayout]; } +- (NSString *)text +{ + return [self attributedText].string; +} + +- (void)setText:(NSString *)text +{ + [self setAttributedText:[[NSAttributedString alloc] initWithString: text]]; +} + - (NSAttributedString *)attributedText { return self.backedTextInputView.attributedText; diff --git a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m index aaead20b0b9c1c..efb6fa64f757ec 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m @@ -60,6 +60,7 @@ @implementation RCTBaseTextInputViewManager RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock) RCT_EXPORT_VIEW_PROPERTY(onTextInput, RCTDirectEventBlock) RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock) +RCT_EXPORT_VIEW_PROPERTY(text, NSString) RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger) From f7adee62111a70512af76efc16d51acc7a974367 Mon Sep 17 00:00:00 2001 From: magicien Date: Tue, 20 Mar 2018 12:15:16 +0900 Subject: [PATCH 2/5] Change textInputDidChange handling Change textInputDidChange handling not to send onChange event while building Chinese characters --- Libraries/Text/TextInput/RCTBaseTextInputView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index 3c957a8c81f41b..0b011c8da9ca14 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -331,7 +331,7 @@ - (void)textInputDidChange _nativeEventCount++; - if (_onChange) { + if (_onChange && backedTextInputView.markedText == nil) { _onChange(@{ @"text": self.attributedText.string, @"target": self.reactTag, From bd62a117db5fede79b2d6b97feb90536d1b30ee9 Mon Sep 17 00:00:00 2001 From: magicien Date: Tue, 20 Mar 2018 13:24:13 +0900 Subject: [PATCH 3/5] Fix typo --- Libraries/Text/TextInput/RCTBaseTextInputView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index 0b011c8da9ca14..1b3186fd518ab3 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -331,7 +331,7 @@ - (void)textInputDidChange _nativeEventCount++; - if (_onChange && backedTextInputView.markedText == nil) { + if (_onChange && backedTextInputView.markedTextRange == nil) { _onChange(@{ @"text": self.attributedText.string, @"target": self.reactTag, From 207b76357fb24ceb1f849addc67b60b14cae2714 Mon Sep 17 00:00:00 2001 From: magicien Date: Tue, 20 Mar 2018 13:45:04 +0900 Subject: [PATCH 4/5] Remove unnecessary changes --- Libraries/Text/TextInput/RCTBaseTextInputView.m | 10 ---------- Libraries/Text/TextInput/RCTBaseTextInputViewManager.m | 1 - 2 files changed, 11 deletions(-) diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index 1b3186fd518ab3..d53857904ad4f5 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -93,16 +93,6 @@ - (void)setReactBorderInsets:(UIEdgeInsets)reactBorderInsets [self setNeedsLayout]; } -- (NSString *)text -{ - return [self attributedText].string; -} - -- (void)setText:(NSString *)text -{ - [self setAttributedText:[[NSAttributedString alloc] initWithString: text]]; -} - - (NSAttributedString *)attributedText { return self.backedTextInputView.attributedText; diff --git a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m index efb6fa64f757ec..aaead20b0b9c1c 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m @@ -60,7 +60,6 @@ @implementation RCTBaseTextInputViewManager RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock) RCT_EXPORT_VIEW_PROPERTY(onTextInput, RCTDirectEventBlock) RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock) -RCT_EXPORT_VIEW_PROPERTY(text, NSString) RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger) From f13805afb6246ee8141be6cf0bda6b9f18d3e821 Mon Sep 17 00:00:00 2001 From: magicien Date: Tue, 20 Mar 2018 16:45:56 +0900 Subject: [PATCH 5/5] Inlucde #18278 --- .../Text/TextInput/RCTBaseTextInputShadowView.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m b/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m index f5a7ca1724754d..611d76855eab24 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m @@ -23,6 +23,7 @@ @implementation RCTBaseTextInputShadowView NSAttributedString *_Nullable _localAttributedText; CGSize _previousContentSize; + NSString *_text; NSTextStorage *_textStorage; NSTextContainer *_textContainer; NSLayoutManager *_layoutManager; @@ -101,6 +102,17 @@ - (void)invalidateContentSize }); } +- (NSString *)text +{ + return _text; +} + +- (void)setText:(NSString *)text +{ + _text = text; + _previousAttributedText = _localAttributedText; +} + #pragma mark - RCTUIManagerObserver - (void)uiManagerWillPerformMounting