Skip to content

Commit cfc8583

Browse files
tom-unrnbot
andauthored
Add macOS secureTextEntry prop support to TextInput (#612)
* Update scripts to publish react-native-macos-init * Clean up merge markers * Restored ios:macos RNTester parity except for InputAccessoryView. * Revert "Restored ios:macos RNTester parity except for InputAccessoryView." This reverts commit 5a67ae0. * Remove unnecessary android builds and tar file upload. * Prototype implementation of using NSSecureTextField when secureTextEntry prop is true. * Moved useSecureTextField mapping to RCTSinglineTextInputView. Add _useSecureTextField ivar. Co-authored-by: React-Native Bot <[email protected]>
1 parent c5fa3de commit cfc8583

File tree

7 files changed

+62
-1
lines changed

7 files changed

+62
-1
lines changed

Libraries/Text/React-RCTText.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Pod::Spec.new do |s|
2727
s.platforms = { :ios => "9.0", :tvos => "9.2", :osx => "10.13" } # TODO(macOS GH#214)
2828
s.source = source
2929
s.source_files = "**/*.{h,m}"
30+
s.ios.exclude_files = "**/macOS/*" # TODO(macOS ISS#2323203)
3031
s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs"
3132
s.header_dir = "RCTText"
3233

Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputView.m

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99

1010
#import <React/RCTBridge.h>
1111

12-
#import <React/RCTUITextField.h>
12+
#include <React/RCTUITextField.h>
13+
#if TARGET_OS_OSX // [TODO(macOS ISS#2323203)
14+
#include <React/RCTUISecureTextField.h>
15+
#endif // ]TODO(macOS ISS#2323203)
1316

1417
@implementation RCTSinglelineTextInputView
1518
{
1619
RCTUITextField *_backedTextInputView;
20+
BOOL _useSecureTextField; // TODO(macOS ISS#2323203)
1721
}
1822

1923
- (instancetype)initWithBridge:(RCTBridge *)bridge
@@ -53,6 +57,22 @@ - (void)setReactBorderInsets:(UIEdgeInsets)reactBorderInsets
5357
((RCTUITextField*)self.backedTextInputView).frame = UIEdgeInsetsInsetRect(self.bounds, reactBorderInsets);
5458
[self setNeedsLayout];
5559
}
60+
61+
- (void)setUseSecureTextField:(BOOL)useSecureTextField {
62+
if (_useSecureTextField != useSecureTextField) {
63+
_useSecureTextField = useSecureTextField;
64+
RCTUITextField *previousTextField = _backedTextInputView;
65+
if (useSecureTextField) {
66+
_backedTextInputView = [[RCTUISecureTextField alloc] initWithFrame:self.bounds];
67+
} else {
68+
_backedTextInputView = [[RCTUITextField alloc] initWithFrame:self.bounds];
69+
}
70+
_backedTextInputView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
71+
_backedTextInputView.textInputDelegate = self;
72+
_backedTextInputView.text = previousTextField.text;
73+
[self replaceSubview:previousTextField with:_backedTextInputView];
74+
}
75+
}
5676
#endif // ]TODO(macOS ISS#2323203)
5777

5878
@end

Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputViewManager.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ - (RCTUIView *)view // TODO(macOS ISS#3536887)
2929
return [[RCTSinglelineTextInputView alloc] initWithBridge:self.bridge];
3030
}
3131

32+
RCT_REMAP_OSX_VIEW_PROPERTY(secureTextEntry, useSecureTextField, BOOL) // TODO(macOS ISS#2323203)
33+
3234
@end

Libraries/Text/TextInput/Singleline/RCTUITextField.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ NS_ASSUME_NONNULL_BEGIN
1616
/*
1717
* Just regular UITextField... but much better!
1818
*/
19+
#if RCT_SUBCLASS_SECURETEXTFIELD
20+
@interface RCTUISecureTextField : NSSecureTextField <RCTBackedTextInputViewProtocol>
21+
#else
1922
@interface RCTUITextField : UITextField <RCTBackedTextInputViewProtocol>
23+
#endif
2024

2125
- (instancetype)initWithCoder:(NSCoder *)decoder NS_UNAVAILABLE;
2226

Libraries/Text/TextInput/Singleline/RCTUITextField.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616

1717

1818
#if TARGET_OS_OSX // [TODO(macOS ISS#2323203)
19+
20+
#if RCT_SUBCLASS_SECURETEXTFIELD
21+
#define RCTUITextFieldCell RCTUISecureTextFieldCell
22+
@interface RCTUISecureTextFieldCell : NSSecureTextFieldCell
23+
#else
1924
@interface RCTUITextFieldCell : NSTextFieldCell
25+
#endif
2026

2127
@property (nonatomic, assign) UIEdgeInsets textContainerInset;
2228
@property (nonatomic, getter=isAutomaticTextReplacementEnabled) BOOL automaticTextReplacementEnabled;
@@ -75,7 +81,11 @@ - (NSText *)setUpFieldEditorAttributes:(NSText *)textObj
7581
@end
7682
#endif // ]TODO(macOS ISS#2323203)
7783

84+
#ifdef RCT_SUBCLASS_SECURETEXTFIELD
85+
@implementation RCTUISecureTextField {
86+
#else
7887
@implementation RCTUITextField {
88+
#endif
7989
RCTBackedTextFieldDelegateAdapter *_textInputDelegateAdapter;
8090
NSDictionary<NSAttributedStringKey, id> *_defaultTextAttributes;
8191
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
// TODO(macOS ISS#2323203)
9+
10+
#define RCT_SUBCLASS_SECURETEXTFIELD 1
11+
12+
#include <React/RCTUITextField.h>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
// TODO(macOS ISS#2323203)
9+
10+
#define RCT_SUBCLASS_SECURETEXTFIELD 1
11+
12+
#include "../RCTUITextField.m"

0 commit comments

Comments
 (0)