diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.h b/Libraries/Text/TextInput/RCTBaseTextInputView.h index 67c1e54a9db..5b62f902514 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.h +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.h @@ -43,6 +43,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign) BOOL blurOnSubmit; @property (nonatomic, assign) BOOL selectTextOnFocus; @property (nonatomic, assign) BOOL clearTextOnFocus; +@property (nonatomic, assign) BOOL secureTextEntry; @property (nonatomic, copy) RCTTextSelection *selection; @property (nonatomic, strong, nullable) NSNumber *maxLength; @property (nonatomic, copy) NSAttributedString *attributedText; diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index 4b84de26029..a0621bfea53 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -283,6 +283,24 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) } } +- (BOOL)secureTextEntry { + return self.backedTextInputView.secureTextEntry; +} + +- (void)setSecureTextEntry:(BOOL)secureTextEntry { + UIView *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 diff --git a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m index 6d5f7ec5aa0..d226782be62 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m @@ -43,12 +43,12 @@ RCT_REMAP_VIEW_PROPERTY(keyboardAppearance, backedTextInputView.keyboardAppearan RCT_REMAP_VIEW_PROPERTY(placeholder, backedTextInputView.placeholder, NSString) RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, backedTextInputView.placeholderColor, UIColor) RCT_REMAP_VIEW_PROPERTY(returnKeyType, backedTextInputView.returnKeyType, UIReturnKeyType) -RCT_REMAP_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BOOL) RCT_REMAP_VIEW_PROPERTY(selectionColor, backedTextInputView.tintColor, UIColor) RCT_REMAP_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingType, UITextSpellCheckingType) RCT_REMAP_VIEW_PROPERTY(caretHidden, backedTextInputView.caretHidden, BOOL) RCT_REMAP_VIEW_PROPERTY(clearButtonMode, backedTextInputView.clearButtonMode, UITextFieldViewMode) RCT_REMAP_VIEW_PROPERTY(scrollEnabled, backedTextInputView.scrollEnabled, BOOL) +RCT_EXPORT_VIEW_PROPERTY(secureTextEntry, BOOL) RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL) RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL) RCT_EXPORT_VIEW_PROPERTY(keyboardType, UIKeyboardType) diff --git a/RNTester/js/TextInputExample.ios.js b/RNTester/js/TextInputExample.ios.js index 5529db69a06..c2a73781a7b 100644 --- a/RNTester/js/TextInputExample.ios.js +++ b/RNTester/js/TextInputExample.ios.js @@ -212,7 +212,11 @@ class SecureEntryExample extends React.Component<$FlowFixMeProps, any> { * comment and run Flow. */ constructor(props) { super(props); - this.state = {text: ''}; + this.state = { + text: '', + password: '', + isSecureTextEntry: true, + }; } render() { return ( @@ -225,6 +229,26 @@ class SecureEntryExample extends React.Component<$FlowFixMeProps, any> { value={this.state.text} /> Current text is: {this.state.text} + + this.setState({password: text})} + secureTextEntry={this.state.isSecureTextEntry} + value={this.state.password} + /> + { + this.setState({isSecureTextEntry: value}); + }} + style={{marginLeft: 4}} + value={this.state.isSecureTextEntry} + /> + ); }