Toggle secureTextEntry cursor spacing (#23524)

Summary:
This is a fix for #5859, based on the feedback in #18587. Instead of using `didSetProps` it uses a setter. I will also note that setting to `nil` no longer works (crashes) so setting it to a blank string then back to the original works fine.

[iOS] [Fixed] - Toggling secureTextEntry correctly places cursor.
Pull Request resolved: https://github.com/facebook/react-native/pull/23524

Differential Revision: D14143028

Pulled By: cpojer

fbshipit-source-id: 5f3203d56b1329eb7359465f8ab50eb4f4fa5507
This commit is contained in:
Eric Lewis
2019-02-27 21:22:31 +01:00
committed by Mike Grabowski
parent 8e5eb6389f
commit c1392c2ff3
4 changed files with 45 additions and 2 deletions
@@ -283,6 +283,24 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
}
}
- (BOOL)secureTextEntry {
return self.backedTextInputView.secureTextEntry;
}
- (void)setSecureTextEntry:(BOOL)secureTextEntry {
UIView<RCTBackedTextInputViewProtocol> *textInputView = self.backedTextInputView;
if (textInputView.secureTextEntry != secureTextEntry) {
textInputView.secureTextEntry = secureTextEntry;
// Fix #5859, see https://stackoverflow.com/questions/14220187/uitextfield-has-trailing-whitespace-after-securetextentry-toggle/22537788#22537788
NSAttributedString *originalText = [textInputView.attributedText copy];
self.backedTextInputView.attributedText = [NSAttributedString new];
self.backedTextInputView.attributedText = originalText;
}
}
#pragma mark - RCTBackedTextInputDelegate
- (BOOL)textInputShouldBeginEditing