diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.mm b/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.mm index d337699674b2..18bbe64f657a 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.mm +++ b/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.mm @@ -8,7 +8,7 @@ #import #import "RCTBackedTextInputViewProtocol.h" // [macOS #import "RCTBackedTextInputDelegate.h" -#import "../RCTTextUIKit.h" // macOS] +#import // macOS] #pragma mark - RCTBackedTextFieldDelegateAdapter (for UITextField) diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm index c4422af316b4..cac171e70c9f 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm +++ b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm @@ -21,8 +21,11 @@ #import #import #import // [macOS] -#import "../RCTTextUIKit.h" // [macOS] +#import // [macOS] #import // [macOS] +#if TARGET_OS_OSX // [macOS +#import +#endif // macOS] /** Native iOS text field bottom keyboard offset amount */ static const CGFloat kSingleLineKeyboardBottomOffset = 15.0; @@ -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; diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.h b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.h index ff30d49d7f7f..61242af88da2 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.h +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.h @@ -20,11 +20,7 @@ NS_ASSUME_NONNULL_BEGIN #if !TARGET_OS_OSX // [macOS] @interface RCTUITextField : UITextField #else // [macOS -#if RCT_SUBCLASS_SECURETEXTFIELD -@interface RCTUISecureTextField : NSSecureTextField -#else @interface RCTUITextField : NSTextField -#endif // RCT_SUBCLASS_SECURETEXTFIELD #endif // macOS] diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm index c30fdfea6a27..b1a968f7cd1d 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm @@ -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; @@ -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); @@ -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]; @@ -86,11 +73,7 @@ - (NSText *)setUpFieldEditorAttributes:(NSText *)textObj @end #endif // macOS] -#ifdef RCT_SUBCLASS_SECURETEXTFIELD -@implementation RCTUISecureTextField { -#else @implementation RCTUITextField { -#endif RCTBackedTextFieldDelegateAdapter *_textInputDelegateAdapter; NSDictionary *_defaultTextAttributes; #if !TARGET_OS_OSX // [macOS] diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.h b/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.h index c0586c7be5db..8fb7ad6d23fc 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.h +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.h @@ -8,8 +8,10 @@ // [macOS] #if TARGET_OS_OSX -#define RCT_SUBCLASS_SECURETEXTFIELD 1 -#endif -#include +#import + +@interface RCTUISecureTextField : RCTUITextField +@end +#endif diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.m b/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.m deleted file mode 100644 index 41d4f4c9b7b3..000000000000 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.m +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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 -#define RCT_SUBCLASS_SECURETEXTFIELD 1 -#endif - -#include "../RCTUITextField.mm" diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.mm b/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.mm new file mode 100644 index 000000000000..6f332dc1701c --- /dev/null +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.mm @@ -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 +#import + +#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 diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm index 04447911810d..0c445ba303b2 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm @@ -1220,7 +1220,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;