Skip to content

Commit 0327e88

Browse files
ericlewiscpojer
authored andcommitted
1 parent 4a80776 commit 0327e88

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Libraries/Text/TextInput/RCTBaseTextInputView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ NS_ASSUME_NONNULL_BEGIN
4343
@property (nonatomic, assign) BOOL blurOnSubmit;
4444
@property (nonatomic, assign) BOOL selectTextOnFocus;
4545
@property (nonatomic, assign) BOOL clearTextOnFocus;
46+
@property (nonatomic, assign) BOOL secureTextEntry;
4647
@property (nonatomic, copy) RCTTextSelection *selection;
4748
@property (nonatomic, strong, nullable) NSNumber *maxLength;
4849
@property (nonatomic, copy) NSAttributedString *attributedText;

Libraries/Text/TextInput/RCTBaseTextInputView.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,25 @@ - (void)setKeyboardType:(UIKeyboardType)keyboardType
283283
}
284284
}
285285

286+
- (BOOL)secureTextEntry {
287+
return self.backedTextInputView.secureTextEntry;
288+
}
289+
290+
- (void)setSecureTextEntry:(BOOL)secureTextEntry {
291+
UIView<RCTBackedTextInputViewProtocol> *textInputView = self.backedTextInputView;
292+
293+
if (textInputView.secureTextEntry != secureTextEntry) {
294+
textInputView.secureTextEntry = secureTextEntry;
295+
296+
// Fix #5859
297+
// Reason works: https://stackoverflow.com/questions/14220187/uitextfield-has-trailing-whitespace-after-securetextentry-toggle/22537788#22537788
298+
NSAttributedString *originalText = [textInputView.attributedText copy];
299+
self.backedTextInputView.attributedText = [NSAttributedString new];
300+
self.backedTextInputView.attributedText = originalText;
301+
}
302+
303+
}
304+
286305
#pragma mark - RCTBackedTextInputDelegate
287306

288307
- (BOOL)textInputShouldBeginEditing

Libraries/Text/TextInput/RCTBaseTextInputViewManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ @implementation RCTBaseTextInputViewManager
4343
RCT_REMAP_VIEW_PROPERTY(placeholder, backedTextInputView.placeholder, NSString)
4444
RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, backedTextInputView.placeholderColor, UIColor)
4545
RCT_REMAP_VIEW_PROPERTY(returnKeyType, backedTextInputView.returnKeyType, UIReturnKeyType)
46-
RCT_REMAP_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BOOL)
4746
RCT_REMAP_VIEW_PROPERTY(selectionColor, backedTextInputView.tintColor, UIColor)
4847
RCT_REMAP_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingType, UITextSpellCheckingType)
4948
RCT_REMAP_VIEW_PROPERTY(caretHidden, backedTextInputView.caretHidden, BOOL)
5049
RCT_REMAP_VIEW_PROPERTY(clearButtonMode, backedTextInputView.clearButtonMode, UITextFieldViewMode)
5150
RCT_REMAP_VIEW_PROPERTY(scrollEnabled, backedTextInputView.scrollEnabled, BOOL)
51+
RCT_EXPORT_VIEW_PROPERTY(secureTextEntry, BOOL)
5252
RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL)
5353
RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)
5454
RCT_EXPORT_VIEW_PROPERTY(keyboardType, UIKeyboardType)

0 commit comments

Comments
 (0)