Skip to content

Commit 8016d83

Browse files
Adam ComellaFacebook Github Bot
authored andcommitted
iOS: Fix autoCorrect doesn't revert to initial state
Summary: There's an inconsistency in autoCorrect's default state: - If you don't specify a value for autoCorrect, it defaults to on. - If you specify true/false for autoCorrect and later specify null, autoCorrect turns off. It should have reverted to its initial state of on. The reason for this discrepancy is that autoCorrect is exposed to JS as a boolean but it is actually an enum with three states in native: - UITextAutocorrectionTypeDefault (the default value) - UITextAutocorrectionTypeYes - UITextAutocorrectionTypeNo This is fixed by explicitly mapping JS null to UITextAutocorrectionTypeDefault. **Test plan (required)** Verified that switching `autoCorrect` between `true`, `false`, and `null` all work correctly in single line and multiline `TextInputs`. Adam Comella Microsoft Corp. Closes #11055 Differential Revision: D4226419 Pulled By: javache fbshipit-source-id: e3e5769a3aa537f00fb56ca4ae622ff4213481c5
1 parent b49e7af commit 8016d83

9 files changed

Lines changed: 55 additions & 18 deletions

File tree

Libraries/Text/RCTConvert+Text.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import "RCTConvert.h"
11+
12+
@interface RCTConvert (Text)
13+
14+
+ (UITextAutocorrectionType)UITextAutocorrectionType:(id)json;
15+
16+
@end

Libraries/Text/RCTConvert+Text.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import "RCTConvert+Text.h"
11+
12+
@implementation RCTConvert (Text)
13+
14+
+ (UITextAutocorrectionType)UITextAutocorrectionType:(id)json
15+
{
16+
return
17+
json == nil ? UITextAutocorrectionTypeDefault :
18+
[RCTConvert BOOL:json] ? UITextAutocorrectionTypeYes :
19+
UITextAutocorrectionTypeNo;
20+
}
21+
22+
@end

Libraries/Text/RCTText.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
58B511D01A9E6C5C00147676 /* RCTShadowText.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B511CB1A9E6C5C00147676 /* RCTShadowText.m */; };
2828
58B511D11A9E6C5C00147676 /* RCTTextManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B511CD1A9E6C5C00147676 /* RCTTextManager.m */; };
2929
58B512161A9E6EFF00147676 /* RCTText.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B512141A9E6EFF00147676 /* RCTText.m */; };
30+
AF3225F91DE5574F00D3E7E7 /* RCTConvert+Text.m in Sources */ = {isa = PBXBuildFile; fileRef = AF3225F81DE5574F00D3E7E7 /* RCTConvert+Text.m */; };
31+
AF3225FA1DE5574F00D3E7E7 /* RCTConvert+Text.m in Sources */ = {isa = PBXBuildFile; fileRef = AF3225F81DE5574F00D3E7E7 /* RCTConvert+Text.m */; };
3032
/* End PBXBuildFile section */
3133

3234
/* Begin PBXCopyFilesBuildPhase section */
@@ -73,6 +75,8 @@
7375
58B511CD1A9E6C5C00147676 /* RCTTextManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTextManager.m; sourceTree = "<group>"; };
7476
58B512141A9E6EFF00147676 /* RCTText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTText.m; sourceTree = "<group>"; };
7577
58B512151A9E6EFF00147676 /* RCTText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTText.h; sourceTree = "<group>"; };
78+
AF3225F71DE5574F00D3E7E7 /* RCTConvert+Text.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+Text.h"; sourceTree = "<group>"; };
79+
AF3225F81DE5574F00D3E7E7 /* RCTConvert+Text.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+Text.m"; sourceTree = "<group>"; };
7680
/* End PBXFileReference section */
7781

7882
/* Begin PBXFrameworksBuildPhase section */
@@ -96,6 +100,8 @@
96100
58B511921A9E6C1200147676 = {
97101
isa = PBXGroup;
98102
children = (
103+
AF3225F71DE5574F00D3E7E7 /* RCTConvert+Text.h */,
104+
AF3225F81DE5574F00D3E7E7 /* RCTConvert+Text.m */,
99105
19FC5C861D41A4220090108F /* RCTTextSelection.h */,
100106
19FC5C841D41A4120090108F /* RCTTextSelection.m */,
101107
58B511C61A9E6C5C00147676 /* RCTRawTextManager.h */,
@@ -216,6 +222,7 @@
216222
2D3B5F3B1D9B106F00451313 /* RCTTextView.m in Sources */,
217223
2D3B5F3A1D9B106F00451313 /* RCTTextFieldManager.m in Sources */,
218224
2D3B5F341D9B103100451313 /* RCTRawTextManager.m in Sources */,
225+
AF3225FA1DE5574F00D3E7E7 /* RCTConvert+Text.m in Sources */,
219226
2D3B5F3C1D9B106F00451313 /* RCTTextViewManager.m in Sources */,
220227
2D3B5F331D9B102D00451313 /* RCTTextSelection.m in Sources */,
221228
2D3B5F351D9B103300451313 /* RCTShadowRawText.m in Sources */,
@@ -233,6 +240,7 @@
233240
1362F1001B4D51F400E06D8C /* RCTTextField.m in Sources */,
234241
58B512161A9E6EFF00147676 /* RCTText.m in Sources */,
235242
1362F1011B4D51F400E06D8C /* RCTTextFieldManager.m in Sources */,
243+
AF3225F91DE5574F00D3E7E7 /* RCTConvert+Text.m in Sources */,
236244
131B6AC11AF0CD0600FFC3E0 /* RCTTextViewManager.m in Sources */,
237245
58B511CF1A9E6C5C00147676 /* RCTShadowRawText.m in Sources */,
238246
58B511D01A9E6C5C00147676 /* RCTShadowText.m in Sources */,

Libraries/Text/RCTTextField.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
@interface RCTTextField : UITextField
1717

1818
@property (nonatomic, assign) BOOL caretHidden;
19-
@property (nonatomic, assign) BOOL autoCorrect;
2019
@property (nonatomic, assign) BOOL selectTextOnFocus;
2120
@property (nonatomic, assign) BOOL blurOnSubmit;
2221
@property (nonatomic, assign) UIEdgeInsets contentInset;

Libraries/Text/RCTTextField.m

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,6 @@ - (CGRect)editingRectForBounds:(CGRect)bounds
149149
return [self textRectForBounds:bounds];
150150
}
151151

152-
- (void)setAutoCorrect:(BOOL)autoCorrect
153-
{
154-
self.autocorrectionType = (autoCorrect ? UITextAutocorrectionTypeYes : UITextAutocorrectionTypeNo);
155-
}
156-
157-
- (BOOL)autoCorrect
158-
{
159-
return self.autocorrectionType == UITextAutocorrectionTypeYes;
160-
}
161-
162152
- (void)textFieldDidChange
163153
{
164154
_nativeEventCount++;

Libraries/Text/RCTTextFieldManager.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#import "RCTShadowView.h"
1414
#import "RCTTextField.h"
1515
#import "RCTFont.h"
16+
#import "RCTConvert+Text.h"
1617

1718
@interface RCTTextFieldManager() <UITextFieldDelegate>
1819

@@ -75,7 +76,7 @@ - (BOOL)textFieldShouldEndEditing:(RCTTextField *)textField
7576
}
7677

7778
RCT_EXPORT_VIEW_PROPERTY(caretHidden, BOOL)
78-
RCT_EXPORT_VIEW_PROPERTY(autoCorrect, BOOL)
79+
RCT_REMAP_VIEW_PROPERTY(autoCorrect, autocorrectionType, UITextAutocorrectionType)
7980
RCT_REMAP_VIEW_PROPERTY(editable, enabled, BOOL)
8081
RCT_EXPORT_VIEW_PROPERTY(placeholder, NSString)
8182
RCT_EXPORT_VIEW_PROPERTY(placeholderTextColor, UIColor)

Libraries/Text/RCTTextView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
@interface RCTTextView : RCTView <UITextViewDelegate>
1818

19-
@property (nonatomic, assign) BOOL autoCorrect;
19+
@property (nonatomic, assign) UITextAutocorrectionType autocorrectionType;
2020
@property (nonatomic, assign) BOOL blurOnSubmit;
2121
@property (nonatomic, assign) BOOL clearTextOnFocus;
2222
@property (nonatomic, assign) BOOL selectTextOnFocus;

Libraries/Text/RCTTextView.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,14 +519,14 @@ - (void)updatePlaceholderVisibility
519519
}
520520
}
521521

522-
- (void)setAutoCorrect:(BOOL)autoCorrect
522+
- (void)setAutocorrectionType:(UITextAutocorrectionType)autocorrectionType
523523
{
524-
_textView.autocorrectionType = (autoCorrect ? UITextAutocorrectionTypeYes : UITextAutocorrectionTypeNo);
524+
_textView.autocorrectionType = autocorrectionType;
525525
}
526526

527-
- (BOOL)autoCorrect
527+
- (UITextAutocorrectionType)autocorrectionType
528528
{
529-
return _textView.autocorrectionType == UITextAutocorrectionTypeYes;
529+
return _textView.autocorrectionType;
530530
}
531531

532532
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView

Libraries/Text/RCTTextViewManager.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#import "RCTShadowView.h"
1515
#import "RCTTextView.h"
1616
#import "RCTFont.h"
17+
#import "RCTConvert+Text.h"
1718

1819
@implementation RCTTextViewManager
1920

@@ -25,7 +26,7 @@ - (UIView *)view
2526
}
2627

2728
RCT_REMAP_VIEW_PROPERTY(autoCapitalize, textView.autocapitalizationType, UITextAutocapitalizationType)
28-
RCT_EXPORT_VIEW_PROPERTY(autoCorrect, BOOL)
29+
RCT_REMAP_VIEW_PROPERTY(autoCorrect, autocorrectionType, UITextAutocorrectionType)
2930
RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL)
3031
RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)
3132
RCT_REMAP_VIEW_PROPERTY(color, textView.textColor, UIColor)

0 commit comments

Comments
 (0)