Skip to content

Commit

Permalink
Add macOS secureTextEntry prop support to TextInput (#612)
Browse files Browse the repository at this point in the history
* 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 <53619745+rnbot@users.noreply.github.com>
  • Loading branch information
tom-un and rnbot committed Sep 28, 2020
1 parent c5fa3de commit cfc8583
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions Libraries/Text/React-RCTText.podspec
Expand Up @@ -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"

Expand Down
22 changes: 21 additions & 1 deletion Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputView.m
Expand Up @@ -9,11 +9,15 @@

#import <React/RCTBridge.h>

#import <React/RCTUITextField.h>
#include <React/RCTUITextField.h>
#if TARGET_OS_OSX // [TODO(macOS ISS#2323203)
#include <React/RCTUISecureTextField.h>
#endif // ]TODO(macOS ISS#2323203)

@implementation RCTSinglelineTextInputView
{
RCTUITextField *_backedTextInputView;
BOOL _useSecureTextField; // TODO(macOS ISS#2323203)
}

- (instancetype)initWithBridge:(RCTBridge *)bridge
Expand Down Expand Up @@ -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
Expand Up @@ -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
4 changes: 4 additions & 0 deletions Libraries/Text/TextInput/Singleline/RCTUITextField.h
Expand Up @@ -16,7 +16,11 @@ NS_ASSUME_NONNULL_BEGIN
/*
* Just regular UITextField... but much better!
*/
#if RCT_SUBCLASS_SECURETEXTFIELD
@interface RCTUISecureTextField : NSSecureTextField <RCTBackedTextInputViewProtocol>
#else
@interface RCTUITextField : UITextField <RCTBackedTextInputViewProtocol>
#endif

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

Expand Down
10 changes: 10 additions & 0 deletions Libraries/Text/TextInput/Singleline/RCTUITextField.m
Expand Up @@ -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;
Expand Down Expand Up @@ -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<NSAttributedStringKey, id> *_defaultTextAttributes;
}
Expand Down
12 changes: 12 additions & 0 deletions 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 <React/RCTUITextField.h>
12 changes: 12 additions & 0 deletions 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"

0 comments on commit cfc8583

Please sign in to comment.