Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#import <React/RCTBackedTextInputDelegateAdapter.h>
#import "RCTBackedTextInputViewProtocol.h" // [macOS
#import "RCTBackedTextInputDelegate.h"
#import "../RCTTextUIKit.h" // macOS]
#import <React/RCTTextUIKit.h> // macOS]

#pragma mark - RCTBackedTextFieldDelegateAdapter (for UITextField)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
#import <React/RCTTextAttributes.h>
#import <React/RCTTextSelection.h>
#import <React/RCTUITextView.h> // [macOS]
#import "../RCTTextUIKit.h" // [macOS]
#import <React/RCTTextUIKit.h> // [macOS]
#import <React/RCTHandledKey.h> // [macOS]
#if TARGET_OS_OSX // [macOS
#import <React/RCTUISecureTextField.h>
#endif // macOS]

/** Native iOS text field bottom keyboard offset amount */
static const CGFloat kSingleLineKeyboardBottomOffset = 15.0;
Expand Down Expand Up @@ -194,7 +197,7 @@ - (BOOL)textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldTex
BOOL shouldFallbackToBareTextComparison =
// There are multiple Korean input sources (2-Set, 3-Set, etc). Check substring instead instead
[[[self.backedTextInputView inputContext] selectedKeyboardInputSource] containsString:@"com.apple.inputmethod.Korean"] ||
[self.backedTextInputView hasMarkedText] || [self.backedTextInputView isKindOfClass:[NSSecureTextField class]] ||
[self.backedTextInputView hasMarkedText] || [self.backedTextInputView isKindOfClass:[RCTUISecureTextField class]] ||
#endif // macOS]
fontHasBeenUpdatedBySystem;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
#if !TARGET_OS_OSX // [macOS]
@interface RCTUITextField : UITextField <RCTBackedTextInputViewProtocol>
#else // [macOS
#if RCT_SUBCLASS_SECURETEXTFIELD
@interface RCTUISecureTextField : NSSecureTextField <RCTBackedTextInputViewProtocol>
#else
@interface RCTUITextField : NSTextField <RCTBackedTextInputViewProtocol>
#endif // RCT_SUBCLASS_SECURETEXTFIELD
#endif // macOS]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@

#if TARGET_OS_OSX // [macOS

#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 All @@ -36,11 +31,6 @@ @interface RCTUITextFieldCell : NSTextFieldCell

@implementation RCTUITextFieldCell

- (void)setTextContainerInset:(UIEdgeInsets)textContainerInset
{
_textContainerInset = textContainerInset;
}

- (NSRect)titleRectForBounds:(NSRect)rect
{
return UIEdgeInsetsInsetRect([super titleRectForBounds:rect], self.textContainerInset);
Expand All @@ -58,12 +48,9 @@ - (void)selectWithFrame:(NSRect)rect inView:(NSView *)controlView editor:(NSText

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
if (self.drawsBackground) {
if (self.backgroundColor && self.backgroundColor.alphaComponent > 0) {

[self.backgroundColor set];
NSRectFill(cellFrame);
}
if (self.drawsBackground && self.backgroundColor && self.backgroundColor.alphaComponent > 0) {
[self.backgroundColor set];
NSRectFill(cellFrame);
}

[super drawInteriorWithFrame:[self titleRectForBounds:cellFrame] inView:controlView];
Expand All @@ -86,11 +73,7 @@ - (NSText *)setUpFieldEditorAttributes:(NSText *)textObj
@end
#endif // macOS]

#ifdef RCT_SUBCLASS_SECURETEXTFIELD
@implementation RCTUISecureTextField {
#else
@implementation RCTUITextField {
#endif
RCTBackedTextFieldDelegateAdapter *_textInputDelegateAdapter;
NSDictionary<NSAttributedStringKey, id> *_defaultTextAttributes;
#if !TARGET_OS_OSX // [macOS]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
// [macOS]

#if TARGET_OS_OSX
#define RCT_SUBCLASS_SECURETEXTFIELD 1
#endif

#include <React/RCTUITextField.h>
#import <React/RCTUITextField.h>

@interface RCTUISecureTextField : RCTUITextField
@end

#endif

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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.
*/

// [macOS]

#if TARGET_OS_OSX

#import <React/RCTUISecureTextField.h>
#import <React/RCTUIKit.h>

#pragma mark - RCTUISecureTextFieldCell

@interface RCTUISecureTextFieldCell : NSSecureTextFieldCell

@property (nonatomic, assign) UIEdgeInsets textContainerInset;
@property (nonatomic, getter=isAutomaticTextReplacementEnabled) BOOL automaticTextReplacementEnabled;
@property (nonatomic, getter=isAutomaticSpellingCorrectionEnabled) BOOL automaticSpellingCorrectionEnabled;
@property (nonatomic, getter=isContinuousSpellCheckingEnabled) BOOL continuousSpellCheckingEnabled;
@property (nonatomic, getter=isGrammarCheckingEnabled) BOOL grammarCheckingEnabled;
@property (nonatomic, strong, nullable) RCTPlatformColor *selectionColor;
@property (nonatomic, strong, nullable) RCTPlatformColor *insertionPointColor;

@end

@implementation RCTUISecureTextFieldCell

- (NSRect)titleRectForBounds:(NSRect)rect
{
return UIEdgeInsetsInsetRect([super titleRectForBounds:rect], self.textContainerInset);
}

- (void)editWithFrame:(NSRect)rect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)delegate event:(NSEvent *)event
{
[super editWithFrame:[self titleRectForBounds:rect] inView:controlView editor:textObj delegate:delegate event:event];
}

- (void)selectWithFrame:(NSRect)rect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)delegate start:(NSInteger)selStart length:(NSInteger)selLength
{
[super selectWithFrame:[self titleRectForBounds:rect] inView:controlView editor:textObj delegate:delegate start:selStart length:selLength];
}

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
if (self.drawsBackground && self.backgroundColor && self.backgroundColor.alphaComponent > 0) {
[self.backgroundColor set];
NSRectFill(cellFrame);
}

[super drawInteriorWithFrame:[self titleRectForBounds:cellFrame] inView:controlView];
}

- (NSText *)setUpFieldEditorAttributes:(NSText *)textObj
{
NSTextView *fieldEditor = (NSTextView *)[super setUpFieldEditorAttributes:textObj];
fieldEditor.automaticSpellingCorrectionEnabled = self.isAutomaticSpellingCorrectionEnabled;
fieldEditor.automaticTextReplacementEnabled = self.isAutomaticTextReplacementEnabled;
fieldEditor.continuousSpellCheckingEnabled = self.isContinuousSpellCheckingEnabled;
fieldEditor.grammarCheckingEnabled = self.isGrammarCheckingEnabled;
NSMutableDictionary *selectTextAttributes = fieldEditor.selectedTextAttributes.mutableCopy;
selectTextAttributes[NSBackgroundColorAttributeName] = self.selectionColor ?: [NSColor selectedControlColor];
fieldEditor.selectedTextAttributes = selectTextAttributes;
fieldEditor.insertionPointColor = self.insertionPointColor ?: [NSColor textColor];
return fieldEditor;
}

@end

#pragma mark - RCTUISecureTextField

@implementation RCTUISecureTextField

+ (Class)cellClass
{
return RCTUISecureTextFieldCell.class;
}

@end

#endif // TARGET_OS_OSX
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ - (BOOL)_textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldTe
// There are multiple Korean input sources (2-Set, 3-Set, etc). Check substring instead instead
[[[_backedTextInputView inputContext] selectedKeyboardInputSource] containsString:@"com.apple.inputmethod.Korean"] ||
[_backedTextInputView hasMarkedText] ||
[_backedTextInputView isKindOfClass:[NSSecureTextField class]] ||
[_backedTextInputView isKindOfClass:[RCTUISecureTextField class]] ||
#endif // macOS]
fontHasBeenUpdatedBySystem;

Expand Down
Loading