diff --git a/Libraries/Text/React-RCTText.podspec b/Libraries/Text/React-RCTText.podspec index d90a382463fb79..b98edce8607f87 100644 --- a/Libraries/Text/React-RCTText.podspec +++ b/Libraries/Text/React-RCTText.podspec @@ -27,6 +27,7 @@ Pod::Spec.new do |s| s.platforms = { :ios => "9.0", :tvos => "9.2", :osx => "10.13" } # TODO(macOS GH#214) s.source = source s.source_files = "**/*.{h,m}" + s.ios.exclude_files = "**/macOS/*" # TODO(macOS ISS#2323203) s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs" s.header_dir = "RCTText" diff --git a/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputView.m b/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputView.m index 4f88f4ea80f4ec..c303a225a08c20 100644 --- a/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputView.m +++ b/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputView.m @@ -9,11 +9,15 @@ #import -#import +#include +#if TARGET_OS_OSX // [TODO(macOS ISS#2323203) +#include +#endif // ]TODO(macOS ISS#2323203) @implementation RCTSinglelineTextInputView { RCTUITextField *_backedTextInputView; + BOOL _useSecureTextField; // TODO(macOS ISS#2323203) } - (instancetype)initWithBridge:(RCTBridge *)bridge @@ -53,6 +57,22 @@ - (void)setReactBorderInsets:(UIEdgeInsets)reactBorderInsets ((RCTUITextField*)self.backedTextInputView).frame = UIEdgeInsetsInsetRect(self.bounds, reactBorderInsets); [self setNeedsLayout]; } + +- (void)setUseSecureTextField:(BOOL)useSecureTextField { + if (_useSecureTextField != useSecureTextField) { + _useSecureTextField = useSecureTextField; + RCTUITextField *previousTextField = _backedTextInputView; + if (useSecureTextField) { + _backedTextInputView = [[RCTUISecureTextField alloc] initWithFrame:self.bounds]; + } else { + _backedTextInputView = [[RCTUITextField alloc] initWithFrame:self.bounds]; + } + _backedTextInputView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + _backedTextInputView.textInputDelegate = self; + _backedTextInputView.text = previousTextField.text; + [self replaceSubview:previousTextField with:_backedTextInputView]; + } +} #endif // ]TODO(macOS ISS#2323203) @end diff --git a/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputViewManager.m b/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputViewManager.m index bf725fdb0bd8c0..07be3b844219a7 100644 --- a/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputViewManager.m +++ b/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputViewManager.m @@ -29,4 +29,6 @@ - (RCTUIView *)view // TODO(macOS ISS#3536887) return [[RCTSinglelineTextInputView alloc] initWithBridge:self.bridge]; } +RCT_REMAP_OSX_VIEW_PROPERTY(secureTextEntry, useSecureTextField, BOOL) // TODO(macOS ISS#2323203) + @end diff --git a/Libraries/Text/TextInput/Singleline/RCTUITextField.h b/Libraries/Text/TextInput/Singleline/RCTUITextField.h index 026f258e305bfe..d48d3b96bf8398 100644 --- a/Libraries/Text/TextInput/Singleline/RCTUITextField.h +++ b/Libraries/Text/TextInput/Singleline/RCTUITextField.h @@ -16,7 +16,11 @@ NS_ASSUME_NONNULL_BEGIN /* * Just regular UITextField... but much better! */ +#if RCT_SUBCLASS_SECURETEXTFIELD +@interface RCTUISecureTextField : NSSecureTextField +#else @interface RCTUITextField : UITextField +#endif - (instancetype)initWithCoder:(NSCoder *)decoder NS_UNAVAILABLE; diff --git a/Libraries/Text/TextInput/Singleline/RCTUITextField.m b/Libraries/Text/TextInput/Singleline/RCTUITextField.m index c975946f0ef068..b36546f97f4e04 100644 --- a/Libraries/Text/TextInput/Singleline/RCTUITextField.m +++ b/Libraries/Text/TextInput/Singleline/RCTUITextField.m @@ -16,7 +16,13 @@ #if TARGET_OS_OSX // [TODO(macOS ISS#2323203) + +#if RCT_SUBCLASS_SECURETEXTFIELD +#define RCTUITextFieldCell RCTUISecureTextFieldCell +@interface RCTUISecureTextFieldCell : NSSecureTextFieldCell +#else @interface RCTUITextFieldCell : NSTextFieldCell +#endif @property (nonatomic, assign) UIEdgeInsets textContainerInset; @property (nonatomic, getter=isAutomaticTextReplacementEnabled) BOOL automaticTextReplacementEnabled; @@ -75,7 +81,11 @@ - (NSText *)setUpFieldEditorAttributes:(NSText *)textObj @end #endif // ]TODO(macOS ISS#2323203) +#ifdef RCT_SUBCLASS_SECURETEXTFIELD +@implementation RCTUISecureTextField { +#else @implementation RCTUITextField { +#endif RCTBackedTextFieldDelegateAdapter *_textInputDelegateAdapter; NSDictionary *_defaultTextAttributes; } diff --git a/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.h b/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.h new file mode 100644 index 00000000000000..3252ba585f9d54 --- /dev/null +++ b/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.h @@ -0,0 +1,12 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// TODO(macOS ISS#2323203) + +#define RCT_SUBCLASS_SECURETEXTFIELD 1 + +#include diff --git a/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.m b/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.m new file mode 100644 index 00000000000000..402ce7b4cb0fb9 --- /dev/null +++ b/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.m @@ -0,0 +1,12 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// TODO(macOS ISS#2323203) + +#define RCT_SUBCLASS_SECURETEXTFIELD 1 + +#include "../RCTUITextField.m"