Skip to content

Commit 946930d

Browse files
Alex Chiuchristophpurrer
authored andcommitted
Pass grammarCheck to text input views for Mac
Similar to #1292 this adds a macOS only property to toggle grammarCheck on RCTUITextField
1 parent 84c0863 commit 946930d

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

Libraries/Components/TextInput/RCTTextInputViewConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ const RCTTextInputViewConfig = {
141141
autoCapitalize: true,
142142
keyboardAppearance: true,
143143
passwordRules: true,
144+
grammarCheck: true, // TODO(macOS GH#774)
144145
spellCheck: true,
145146
selectTextOnFocus: true,
146147
text: true,

Libraries/Components/TextInput/TextInput.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,14 @@ type IOSProps = $ReadOnly<{|
303303
*/
304304
scrollEnabled?: ?boolean,
305305

306+
// [TODO(macOS GH#774)
307+
/**
308+
* If `false`, disables grammar-check.
309+
* @platform macOS
310+
*/
311+
grammarCheck?: ?boolean,
312+
// ]TODO(macOS GH#774)
313+
306314
/**
307315
* If `false`, disables spell-check style (i.e. red underlines).
308316
* The default value is inherited from `autoCorrect`.

Libraries/Text/TextInput/RCTBaseTextInputViewManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ @implementation RCTBaseTextInputViewManager
4848
RCT_REMAP_NOT_OSX_VIEW_PROPERTY(returnKeyType, backedTextInputView.returnKeyType, UIReturnKeyType) // TODO(macOS GH#774)
4949
RCT_REMAP_NOT_OSX_VIEW_PROPERTY(selectionColor, backedTextInputView.tintColor, UIColor) // TODO(macOS GH#774)
5050
RCT_REMAP_OSX_VIEW_PROPERTY(selectionColor, backedTextInputView.selectionColor, UIColor) // TODO(macOS GH#774)
51+
RCT_REMAP_OSX_VIEW_PROPERTY(grammarCheck, backedTextInputView.grammarCheckingEnabled, BOOL) // TODO(macOS GH#774)
5152
RCT_REMAP_NOT_OSX_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingType, UITextSpellCheckingType) // TODO(macOS GH#774)
5253
RCT_REMAP_OSX_VIEW_PROPERTY(spellCheck, backedTextInputView.automaticSpellingCorrectionEnabled, BOOL) // TODO(macOS GH#774)
5354
RCT_REMAP_NOT_OSX_VIEW_PROPERTY(caretHidden, backedTextInputView.caretHidden, BOOL) // TODO(macOS GH#774)

Libraries/Text/TextInput/Singleline/RCTUITextField.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ NS_ASSUME_NONNULL_BEGIN
5454
@property (nonatomic, assign) NSTextAlignment textAlignment;
5555
@property (nonatomic, getter=isAutomaticTextReplacementEnabled) BOOL automaticTextReplacementEnabled;
5656
@property (nonatomic, getter=isAutomaticSpellingCorrectionEnabled) BOOL automaticSpellingCorrectionEnabled;
57+
@property (nonatomic, getter=isGrammarCheckingEnabled) BOOL grammarCheckingEnabled;
5758
@property (nonatomic, assign) BOOL enableFocusRing;
5859
@property (nonatomic, strong, nullable) RCTUIColor *selectionColor;
5960
@property (weak, nullable) id<RCTUITextFieldDelegate> delegate;

Libraries/Text/TextInput/Singleline/RCTUITextField.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ @interface RCTUITextFieldCell : NSTextFieldCell
2626
@property (nonatomic, assign) UIEdgeInsets textContainerInset;
2727
@property (nonatomic, getter=isAutomaticTextReplacementEnabled) BOOL automaticTextReplacementEnabled;
2828
@property (nonatomic, getter=isAutomaticSpellingCorrectionEnabled) BOOL automaticSpellingCorrectionEnabled;
29+
@property (nonatomic, getter=isGrammarCheckingEnabled) BOOL grammarCheckingEnabled;
2930
@property (nonatomic, strong, nullable) RCTUIColor *selectionColor;
3031

3132
@end
@@ -70,6 +71,7 @@ - (NSText *)setUpFieldEditorAttributes:(NSText *)textObj
7071
NSTextView *fieldEditor = (NSTextView *)[super setUpFieldEditorAttributes:textObj];
7172
fieldEditor.automaticSpellingCorrectionEnabled = self.isAutomaticSpellingCorrectionEnabled;
7273
fieldEditor.automaticTextReplacementEnabled = self.isAutomaticTextReplacementEnabled;
74+
fieldEditor.grammarCheckingEnabled = self.isGrammarCheckingEnabled;
7375
NSMutableDictionary *selectTextAttributes = fieldEditor.selectedTextAttributes.mutableCopy;
7476
selectTextAttributes[NSBackgroundColorAttributeName] = self.selectionColor ?: [NSColor selectedControlColor];
7577
fieldEditor.selectedTextAttributes = selectTextAttributes;
@@ -193,6 +195,16 @@ - (BOOL)isAutomaticSpellingCorrectionEnabled
193195
return ((RCTUITextFieldCell*)self.cell).isAutomaticSpellingCorrectionEnabled;
194196
}
195197

198+
- (void)setGrammarCheckingEnabled:(BOOL)grammarCheckingEnabled
199+
{
200+
((RCTUITextFieldCell*)self.cell).grammarCheckingEnabled = grammarCheckingEnabled;
201+
}
202+
203+
- (BOOL)isGrammarCheckingEnabled
204+
{
205+
return ((RCTUITextFieldCell*)self.cell).isGrammarCheckingEnabled;
206+
}
207+
196208
- (void)setSelectionColor:(RCTUIColor *)selectionColor // TODO(OSS Candidate ISS#2710739)
197209
{
198210
((RCTUITextFieldCell*)self.cell).selectionColor = selectionColor;

0 commit comments

Comments
 (0)