diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index 0d085c19cac616..88798f42a61c3b 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -99,11 +99,19 @@ - (NSAttributedString *)attributedText } - (BOOL)textOf:(NSAttributedString*)newText equals:(NSAttributedString*)oldText{ - UITextInputMode *currentInputMode = self.backedTextInputView.textInputMode; - if ([currentInputMode.primaryLanguage isEqualToString:@"dictation"]) { - // When the dictation is running we can't update the attibuted text on the backed up text view - // because setting the attributed string will kill the dictation. This means that we can't impose - // the settings on a dictation. + // When the dictation is running we can't update the attibuted text on the backed up text view + // because setting the attributed string will kill the dictation. This means that we can't impose + // the settings on a dictation. + // Similarly, when the user is in the middle of inputting some text in Japanese/Chinese, there will be styling on the + // text that we should disregard. See https://developer.apple.com/documentation/uikit/uitextinput/1614489-markedtextrange?language=objc + // for more info. + // Lastly, when entering a password, etc., there will be additional styling on the field as the native text view + // handles showing the last character for a split second. + BOOL shouldFallbackToBareTextComparison = + [self.backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"dictation"] || + self.backedTextInputView.markedTextRange || + self.backedTextInputView.isSecureTextEntry; + if (shouldFallbackToBareTextComparison) { return ([newText.string isEqualToString:oldText.string]); } else { return ([newText isEqualToAttributedString:oldText]); diff --git a/RNTester/js/TextInputExample.ios.js b/RNTester/js/TextInputExample.ios.js index d536d46d8b235c..39fc77f82ee68c 100644 --- a/RNTester/js/TextInputExample.ios.js +++ b/RNTester/js/TextInputExample.ios.js @@ -173,6 +173,48 @@ class RewriteExampleInvalidCharacters extends React.Component< } } +class RewriteExampleKana extends React.Component<$FlowFixMeProps, any> { + constructor(props) { + super(props); + this.state = {text: ''}; + } + render() { + return ( + + { + this.setState({text: text.replace(/ひ/g, '日')}); + }} + style={styles.default} + value={this.state.text} + /> + + ); + } +} + +class SecureEntryExample extends React.Component<$FlowFixMeProps, any> { + constructor(props) { + super(props); + this.state = {text: ''}; + } + render() { + return ( + + this.setState({text})} + value={this.state.text} + /> + Current text is: {this.state.text} + + ); + } +} + class TokenizedTextExample extends React.Component<$FlowFixMeProps, any> { constructor(props) { super(props); @@ -524,6 +566,12 @@ exports.examples = [ return ; }, }, + { + title: 'Live Re-Write (ひ -> 日)', + render: function() { + return ; + }, + }, { title: 'Keyboard Accessory View', render: function() { @@ -677,17 +725,7 @@ exports.examples = [ { title: 'Secure text entry', render: function() { - return ( - - - - - - ); + return ; }, }, {