From 8c392ff25750129d54d7d475d08dc4dd17869457 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Sat, 2 May 2020 20:38:04 +0800 Subject: [PATCH 1/4] [iOS] Fixes TextInput shaking when typing Chinese --- Libraries/Text/TextInput/RCTBaseTextInputView.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index aa69593f68fa25..262f90afab6f8c 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -72,6 +72,10 @@ - (void)enforceTextAttributesIfNeeded if ([textAttributes valueForKey:NSForegroundColorAttributeName] == nil) { [textAttributes setValue:[UIColor blackColor] forKey:NSForegroundColorAttributeName]; } + // We need to add check here.See https://github.com/facebook/react-native/issues/28488 + if ([backedTextInputView.defaultTextAttributes isEqualToDictionary:textAttributes]) { + return; + } backedTextInputView.defaultTextAttributes = textAttributes; } From b3224ffaa9158ab10676b550fd7b6a8d9b8631c8 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Sun, 3 May 2020 14:52:32 +0800 Subject: [PATCH 2/4] Move check to concrete class of backTextInputView --- Libraries/Text/TextInput/Multiline/RCTUITextView.m | 3 +++ Libraries/Text/TextInput/RCTBaseTextInputView.m | 4 ---- Libraries/Text/TextInput/Singleline/RCTUITextField.m | 4 ++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Libraries/Text/TextInput/Multiline/RCTUITextView.m b/Libraries/Text/TextInput/Multiline/RCTUITextView.m index 11f3ec291ad863..c502090b83d8a6 100644 --- a/Libraries/Text/TextInput/Multiline/RCTUITextView.m +++ b/Libraries/Text/TextInput/Multiline/RCTUITextView.m @@ -104,6 +104,9 @@ - (void)setPlaceholderColor:(UIColor *)placeholderColor - (void)setDefaultTextAttributes:(NSDictionary *)defaultTextAttributes { + if ([_defaultTextAttributes isEqualToDictionary:defaultTextAttributes]) { + return; + } _defaultTextAttributes = defaultTextAttributes; self.typingAttributes = defaultTextAttributes; [self _updatePlaceholder]; diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index 262f90afab6f8c..aa69593f68fa25 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -72,10 +72,6 @@ - (void)enforceTextAttributesIfNeeded if ([textAttributes valueForKey:NSForegroundColorAttributeName] == nil) { [textAttributes setValue:[UIColor blackColor] forKey:NSForegroundColorAttributeName]; } - // We need to add check here.See https://github.com/facebook/react-native/issues/28488 - if ([backedTextInputView.defaultTextAttributes isEqualToDictionary:textAttributes]) { - return; - } backedTextInputView.defaultTextAttributes = textAttributes; } diff --git a/Libraries/Text/TextInput/Singleline/RCTUITextField.m b/Libraries/Text/TextInput/Singleline/RCTUITextField.m index de8f6efe844971..973c1835112e37 100644 --- a/Libraries/Text/TextInput/Singleline/RCTUITextField.m +++ b/Libraries/Text/TextInput/Singleline/RCTUITextField.m @@ -68,6 +68,10 @@ - (void)setPlaceholderColor:(UIColor *)placeholderColor - (void)setDefaultTextAttributes:(NSDictionary *)defaultTextAttributes { + // We need to add check here.See https://github.com/facebook/react-native/issues/28488 + if ([_defaultTextAttributes isEqualToDictionary:defaultTextAttributes]) { + return; + } _defaultTextAttributes = defaultTextAttributes; [super setDefaultTextAttributes:defaultTextAttributes]; [self _updatePlaceholder]; From 5a20e814784c647232345a69cd96cc55add479b1 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sun, 3 May 2020 23:34:29 -0700 Subject: [PATCH 3/4] Update RCTUITextField.m --- Libraries/Text/TextInput/Singleline/RCTUITextField.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Text/TextInput/Singleline/RCTUITextField.m b/Libraries/Text/TextInput/Singleline/RCTUITextField.m index 973c1835112e37..1dae92a3096bb9 100644 --- a/Libraries/Text/TextInput/Singleline/RCTUITextField.m +++ b/Libraries/Text/TextInput/Singleline/RCTUITextField.m @@ -68,10 +68,10 @@ - (void)setPlaceholderColor:(UIColor *)placeholderColor - (void)setDefaultTextAttributes:(NSDictionary *)defaultTextAttributes { - // We need to add check here.See https://github.com/facebook/react-native/issues/28488 if ([_defaultTextAttributes isEqualToDictionary:defaultTextAttributes]) { return; } + _defaultTextAttributes = defaultTextAttributes; [super setDefaultTextAttributes:defaultTextAttributes]; [self _updatePlaceholder]; From 53f2b0c738131b4ef2c641a0d04646e03b61b2b5 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sun, 3 May 2020 23:34:52 -0700 Subject: [PATCH 4/4] Update RCTUITextView.m --- Libraries/Text/TextInput/Multiline/RCTUITextView.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Libraries/Text/TextInput/Multiline/RCTUITextView.m b/Libraries/Text/TextInput/Multiline/RCTUITextView.m index c502090b83d8a6..88d3183f4df345 100644 --- a/Libraries/Text/TextInput/Multiline/RCTUITextView.m +++ b/Libraries/Text/TextInput/Multiline/RCTUITextView.m @@ -107,6 +107,7 @@ - (void)setDefaultTextAttributes:(NSDictionary *)defa if ([_defaultTextAttributes isEqualToDictionary:defaultTextAttributes]) { return; } + _defaultTextAttributes = defaultTextAttributes; self.typingAttributes = defaultTextAttributes; [self _updatePlaceholder];