Skip to content

Commit

Permalink
Pass grammarCheck to text input views for Mac
Browse files Browse the repository at this point in the history
Similar to #1292 this adds a macOS only property to toggle grammarCheck on RCTUITextField
  • Loading branch information
Alex Chiu authored and christophpurrer committed Jul 26, 2022
1 parent d69fa5b commit 12fca25
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions Libraries/Components/TextInput/RCTTextInputViewConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ const RCTTextInputViewConfig = {
autoCapitalize: true,
keyboardAppearance: true,
passwordRules: true,
grammarCheck: true, // TODO(macOS GH#774)
spellCheck: true,
selectTextOnFocus: true,
text: true,
Expand Down
8 changes: 8 additions & 0 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@ type IOSProps = $ReadOnly<{|
*/
scrollEnabled?: ?boolean,

// [TODO(macOS GH#774)
/**
* If `false`, disables grammar-check.
* @platform macOS
*/
grammarCheck?: ?boolean,
// ]TODO(macOS GH#774)

/**
* If `false`, disables spell-check style (i.e. red underlines).
* The default value is inherited from `autoCorrect`.
Expand Down
1 change: 1 addition & 0 deletions Libraries/Text/TextInput/RCTBaseTextInputViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ @implementation RCTBaseTextInputViewManager
RCT_REMAP_NOT_OSX_VIEW_PROPERTY(returnKeyType, backedTextInputView.returnKeyType, UIReturnKeyType) // TODO(macOS GH#774)
RCT_REMAP_NOT_OSX_VIEW_PROPERTY(selectionColor, backedTextInputView.tintColor, UIColor) // TODO(macOS GH#774)
RCT_REMAP_OSX_VIEW_PROPERTY(selectionColor, backedTextInputView.selectionColor, UIColor) // TODO(macOS GH#774)
RCT_REMAP_OSX_VIEW_PROPERTY(grammarCheck, backedTextInputView.grammarCheckingEnabled, BOOL) // TODO(macOS GH#774)
RCT_REMAP_NOT_OSX_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingType, UITextSpellCheckingType) // TODO(macOS GH#774)
RCT_REMAP_OSX_VIEW_PROPERTY(spellCheck, backedTextInputView.continuousSpellCheckingEnabled, BOOL) // TODO(macOS GH#774)
RCT_REMAP_NOT_OSX_VIEW_PROPERTY(caretHidden, backedTextInputView.caretHidden, BOOL) // TODO(macOS GH#774)
Expand Down
1 change: 1 addition & 0 deletions Libraries/Text/TextInput/Singleline/RCTUITextField.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ NS_ASSUME_NONNULL_BEGIN
@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, assign) BOOL enableFocusRing;
@property (nonatomic, strong, nullable) RCTUIColor *selectionColor;
@property (weak, nullable) id<RCTUITextFieldDelegate> delegate;
Expand Down
12 changes: 12 additions & 0 deletions Libraries/Text/TextInput/Singleline/RCTUITextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ @interface RCTUITextFieldCell : NSTextFieldCell
@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) RCTUIColor *selectionColor;

@end
Expand Down Expand Up @@ -72,6 +73,7 @@ - (NSText *)setUpFieldEditorAttributes:(NSText *)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;
Expand Down Expand Up @@ -208,6 +210,16 @@ - (BOOL)isContinuousSpellCheckingEnabled
return ((RCTUITextFieldCell*)self.cell).isContinuousSpellCheckingEnabled;
}

- (void)setGrammarCheckingEnabled:(BOOL)grammarCheckingEnabled
{
((RCTUITextFieldCell*)self.cell).grammarCheckingEnabled = grammarCheckingEnabled;
}

- (BOOL)isGrammarCheckingEnabled
{
return ((RCTUITextFieldCell*)self.cell).isGrammarCheckingEnabled;
}

- (void)setSelectionColor:(RCTUIColor *)selectionColor // TODO(OSS Candidate ISS#2710739)
{
((RCTUITextFieldCell*)self.cell).selectionColor = selectionColor;
Expand Down

0 comments on commit 12fca25

Please sign in to comment.