Skip to content

Commit 0e55f5b

Browse files
Adam ComellaFacebook Github Bot
authored andcommitted
iOS: Introduce spellCheck prop to TextInput
Summary: This exposes iOS's spellCheckingType functionality to JavaScript. The native functionality is a three state enum. It gets exposed to JavaScript as a boolean. The initial value and JS null map to the third state. An alternative design for this API would have been to expose a three state enum to JavaScript: - "on" which maps to UITextSpellCheckingTypeYes - "off" which maps to UITextSpellCheckingTypeNo - "auto" (default) which maps to UITextSpellCheckingTypeDefault For consistency, I decided to use the same API design as spellCheck. We don't have many options for fixing spellCheck in #11055 without introducing a breaking change. **Test plan (required)** Verified that switching `spellCheck` between `true`, `false`, and `null` all work correctly in single line and multiline `TextInputs`. Closes #11056 Differential Revision: D4232802 Pulled By: javache fbshipit-source-id: 79e03307fa6a30a169f7e2fd0ec5ac826663e7c1
1 parent 9c7952d commit 0e55f5b

File tree

7 files changed

+28
-0
lines changed

7 files changed

+28
-0
lines changed

Libraries/Components/TextInput/TextInput.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ const TextInput = React.createClass({
194194
* If `false`, disables auto-correct. The default value is `true`.
195195
*/
196196
autoCorrect: PropTypes.bool,
197+
/**
198+
* If `false`, disables spell-check style (i.e. red underlines).
199+
* The default value is inherited from `autoCorrect`.
200+
* @platform ios
201+
*/
202+
spellCheck: PropTypes.bool,
197203
/**
198204
* If `true`, focuses the input on `componentDidMount`.
199205
* The default value is `false`.

Libraries/Text/RCTConvert+Text.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
@interface RCTConvert (Text)
1313

1414
+ (UITextAutocorrectionType)UITextAutocorrectionType:(id)json;
15+
+ (UITextSpellCheckingType)UITextSpellCheckingType:(id)json;
1516

1617
@end

Libraries/Text/RCTConvert+Text.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,12 @@ + (UITextAutocorrectionType)UITextAutocorrectionType:(id)json
1919
UITextAutocorrectionTypeNo;
2020
}
2121

22+
+ (UITextSpellCheckingType)UITextSpellCheckingType:(id)json
23+
{
24+
return
25+
json == nil ? UITextSpellCheckingTypeDefault :
26+
[RCTConvert BOOL:json] ? UITextSpellCheckingTypeYes :
27+
UITextSpellCheckingTypeNo;
28+
}
29+
2230
@end

Libraries/Text/RCTTextFieldManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ - (BOOL)textFieldShouldEndEditing:(RCTTextField *)textField
7878

7979
RCT_EXPORT_VIEW_PROPERTY(caretHidden, BOOL)
8080
RCT_REMAP_VIEW_PROPERTY(autoCorrect, autocorrectionType, UITextAutocorrectionType)
81+
RCT_REMAP_VIEW_PROPERTY(spellCheck, spellCheckingType, UITextSpellCheckingType)
8182
RCT_REMAP_VIEW_PROPERTY(editable, enabled, BOOL)
8283
RCT_EXPORT_VIEW_PROPERTY(placeholder, NSString)
8384
RCT_EXPORT_VIEW_PROPERTY(placeholderTextColor, UIColor)

Libraries/Text/RCTTextView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
@interface RCTTextView : RCTView <UITextViewDelegate>
1818

1919
@property (nonatomic, assign) UITextAutocorrectionType autocorrectionType;
20+
@property (nonatomic, assign) UITextSpellCheckingType spellCheckingType;
2021
@property (nonatomic, assign) BOOL blurOnSubmit;
2122
@property (nonatomic, assign) BOOL clearTextOnFocus;
2223
@property (nonatomic, assign) BOOL selectTextOnFocus;

Libraries/Text/RCTTextView.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,16 @@ - (UITextAutocorrectionType)autocorrectionType
530530
return _textView.autocorrectionType;
531531
}
532532

533+
- (void)setSpellCheckingType:(UITextSpellCheckingType)spellCheckingType
534+
{
535+
_textView.spellCheckingType = spellCheckingType;
536+
}
537+
538+
- (UITextSpellCheckingType)spellCheckingType
539+
{
540+
return _textView.spellCheckingType;
541+
}
542+
533543
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
534544
{
535545
if (_selectTextOnFocus) {

Libraries/Text/RCTTextViewManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ - (UIView *)view
2828

2929
RCT_REMAP_VIEW_PROPERTY(autoCapitalize, textView.autocapitalizationType, UITextAutocapitalizationType)
3030
RCT_REMAP_VIEW_PROPERTY(autoCorrect, autocorrectionType, UITextAutocorrectionType)
31+
RCT_REMAP_VIEW_PROPERTY(spellCheck, spellCheckingType, UITextSpellCheckingType)
3132
RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL)
3233
RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)
3334
RCT_REMAP_VIEW_PROPERTY(color, textView.textColor, UIColor)

0 commit comments

Comments
 (0)