forked from microsoft/react-native-macos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRCTUISecureTextField.mm
More file actions
83 lines (63 loc) · 3.05 KB
/
RCTUISecureTextField.mm
File metadata and controls
83 lines (63 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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