From e38be82dfa8b49385b990629318f027de26500cf Mon Sep 17 00:00:00 2001 From: Peter Argany Date: Fri, 22 Feb 2019 10:55:58 -0800 Subject: [PATCH] Revert of [D13948951]Apply the fix for CJK languages on single-line test fields. Summary: This PR (https://github.com/facebook/react-native/pull/22546) broke single line text inputs. After inputting some text and tapping away, the text input reverts back to default text. Revert solved the issue. Reviewed By: cpojer Differential Revision: D14185897 fbshipit-source-id: cc7f0f2ebfb0494062afbc628c4fe27ad27fb1c6 --- .../TextInput/Singleline/RCTUITextField.m | 44 ------------------- 1 file changed, 44 deletions(-) diff --git a/Libraries/Text/TextInput/Singleline/RCTUITextField.m b/Libraries/Text/TextInput/Singleline/RCTUITextField.m index 6549f203c..03a9198e1 100644 --- a/Libraries/Text/TextInput/Singleline/RCTUITextField.m +++ b/Libraries/Text/TextInput/Singleline/RCTUITextField.m @@ -14,7 +14,6 @@ @implementation RCTUITextField { RCTBackedTextFieldDelegateAdapter *_textInputDelegateAdapter; - NSMutableAttributedString *_attributesHolder; } - (instancetype)initWithFrame:(CGRect)frame @@ -26,7 +25,6 @@ object:self]; _textInputDelegateAdapter = [[RCTBackedTextFieldDelegateAdapter alloc] initWithTextField:self]; - _attributesHolder = [[NSMutableAttributedString alloc] init]; } return self; @@ -119,48 +117,6 @@ return [super caretRectForPosition:position]; } -#pragma mark - Fix for CJK Languages - -/* - * The workaround to fix inputting complex locales (like CJK languages). - * When we use `setAttrbutedText:` while user is inputting text in a complex - * locale (like Chinese, Japanese or Korean), some internal state breaks and - * input stops working. - * - * To workaround that, we don't skip underlying attributedString in the text - * field if only attributes were changed. We keep track of these attributes in - * a local variable. - * - * There are two methods that are altered by this workaround: - * - * (1) `-setAttributedText:` - * Applies the attributed string change to a local variable `_attributesHolder` instead of calling `-[super setAttributedText:]`. - * If new attributed text differs from the existing one only in attributes, - * skips `-[super setAttributedText:`] completely. - * - * (2) `-attributedText` - * Return `_attributesHolder` context. - * Updates `_atributesHolder` before returning if the underlying `super.attributedText.string` was changed. - * - */ -- (void)setAttributedText:(NSAttributedString *)attributedText -{ - BOOL textWasChanged = ![_attributesHolder.string isEqualToString:attributedText.string]; - [_attributesHolder setAttributedString:attributedText]; - - if (textWasChanged) { - [super setAttributedText:attributedText]; - } -} - -- (NSAttributedString *)attributedText -{ - if (![super.attributedText.string isEqualToString:_attributesHolder.string]) { - [_attributesHolder setAttributedString:super.attributedText]; - } - - return _attributesHolder; -} #pragma mark - Positioning Overrides