Skip to content

Commit 1a83dc3

Browse files
kmsbernardfacebook-github-bot
authored andcommitted
Fix a broken input for the Korean alphabet in TextInput (#32523)
Summary: <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? --> Fix #32503 Updating the attributed text in TextView/TextField while inputting Korean language will break input mechanism of the Korean alphabet. This results unexpected text input. This PR supersedes the previous fixes: #19809, #22546 ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [iOS] [Fixed] - Fix a broken input for the Korean alphabet in TextInput Pull Request resolved: #32523 Test Plan: https://user-images.githubusercontent.com/20317121/140013434-1674c391-54d6-4410-b4c1-c633697e639d.mov Reviewed By: lunaleaps, sammy-SC Differential Revision: D32470543 Pulled By: philIip fbshipit-source-id: e7e34bd362fa2ab2ca579103db01ad8d1a891c35
1 parent f7e7e89 commit 1a83dc3

File tree

3 files changed

+7
-31
lines changed

3 files changed

+7
-31
lines changed

Libraries/Text/TextInput/Multiline/RCTUITextView.m

+1-29
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,7 @@ - (void)setTextAlignment:(NSTextAlignment)textAlignment
147147

148148
- (void)setAttributedText:(NSAttributedString *)attributedText
149149
{
150-
// Using `setAttributedString:` while user is typing breaks some internal mechanics
151-
// when entering complex input languages such as Chinese, Korean or Japanese.
152-
// see: https://github.com/facebook/react-native/issues/19339
153-
154-
// We try to avoid calling this method as much as we can.
155-
// If the text has changed, there is nothing we can do.
156-
if (![super.attributedText.string isEqualToString:attributedText.string]) {
157-
[super setAttributedText:attributedText];
158-
} else {
159-
// But if the text is preserved, we just copying the attributes from the source string.
160-
if (![super.attributedText isEqualToAttributedString:attributedText]) {
161-
[self copyTextAttributesFrom:attributedText];
162-
}
163-
}
164-
150+
[super setAttributedText:attributedText];
165151
[self textDidChange];
166152
}
167153

@@ -311,18 +297,4 @@ - (CGRect)caretRectForPosition:(UITextPosition *)position
311297

312298
#pragma mark - Utility Methods
313299

314-
- (void)copyTextAttributesFrom:(NSAttributedString *)sourceString
315-
{
316-
[self.textStorage beginEditing];
317-
318-
NSTextStorage *textStorage = self.textStorage;
319-
[sourceString enumerateAttributesInRange:NSMakeRange(0, sourceString.length)
320-
options:NSAttributedStringEnumerationReverse
321-
usingBlock:^(NSDictionary<NSAttributedStringKey,id> * _Nonnull attrs, NSRange range, BOOL * _Nonnull stop) {
322-
[textStorage setAttributes:attrs range:range];
323-
}];
324-
325-
[self.textStorage endEditing];
326-
}
327-
328300
@end

Libraries/Text/TextInput/RCTBaseTextInputView.m

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ - (BOOL)textOf:(NSAttributedString*)newText equals:(NSAttributedString*)oldText{
104104
// Similarly, when the user is in the middle of inputting some text in Japanese/Chinese, there will be styling on the
105105
// text that we should disregard. See https://developer.apple.com/documentation/uikit/uitextinput/1614489-markedtextrange?language=objc
106106
// for more info.
107+
// Also, updating the attributed text while inputting Korean language will break input mechanism.
107108
// If the user added an emoji, the system adds a font attribute for the emoji and stores the original font in NSOriginalFont.
108109
// Lastly, when entering a password, etc., there will be additional styling on the field as the native text view
109110
// handles showing the last character for a split second.
@@ -116,6 +117,7 @@ - (BOOL)textOf:(NSAttributedString*)newText equals:(NSAttributedString*)oldText{
116117

117118
BOOL shouldFallbackToBareTextComparison =
118119
[self.backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"dictation"] ||
120+
[self.backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"ko-KR"] ||
119121
self.backedTextInputView.markedTextRange ||
120122
self.backedTextInputView.isSecureTextEntry ||
121123
fontHasBeenUpdatedBySystem;

React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm

+4-2
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,9 @@ - (BOOL)_textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldTe
617617
// the settings on a dictation.
618618
// Similarly, when the user is in the middle of inputting some text in Japanese/Chinese, there will be styling on the
619619
// text that we should disregard. See
620-
// https://developer.apple.com/documentation/uikit/uitextinput/1614489-markedtextrange?language=objc for more info. If
621-
// the user added an emoji, the system adds a font attribute for the emoji and stores the original font in
620+
// https://developer.apple.com/documentation/uikit/uitextinput/1614489-markedtextrange?language=objc for more info.
621+
// Also, updating the attributed text while inputting Korean language will break input mechanism.
622+
// If the user added an emoji, the system adds a font attribute for the emoji and stores the original font in
622623
// NSOriginalFont. Lastly, when entering a password, etc., there will be additional styling on the field as the native
623624
// text view handles showing the last character for a split second.
624625
__block BOOL fontHasBeenUpdatedBySystem = false;
@@ -633,6 +634,7 @@ - (BOOL)_textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldTe
633634

634635
BOOL shouldFallbackToBareTextComparison =
635636
[_backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"dictation"] ||
637+
[_backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"ko-KR"] ||
636638
_backedTextInputView.markedTextRange || _backedTextInputView.isSecureTextEntry || fontHasBeenUpdatedBySystem;
637639

638640
if (shouldFallbackToBareTextComparison) {

0 commit comments

Comments
 (0)