diff --git a/Libraries/Text/RCTConvert+Text.h b/Libraries/Text/RCTConvert+Text.h new file mode 100644 index 00000000000000..a2ac1f7ba0a9e1 --- /dev/null +++ b/Libraries/Text/RCTConvert+Text.h @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import "RCTConvert.h" + +@interface RCTConvert (Text) + ++ (UITextAutocorrectionType)UITextAutocorrectionType:(id)json; + +@end diff --git a/Libraries/Text/RCTConvert+Text.m b/Libraries/Text/RCTConvert+Text.m new file mode 100644 index 00000000000000..201d7d96a3725d --- /dev/null +++ b/Libraries/Text/RCTConvert+Text.m @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import "RCTConvert+Text.h" + +@implementation RCTConvert (Text) + ++ (UITextAutocorrectionType)UITextAutocorrectionType:(id)json +{ + return + json == nil ? UITextAutocorrectionTypeDefault : + [RCTConvert BOOL:json] ? UITextAutocorrectionTypeYes : + UITextAutocorrectionTypeNo; +} + +@end diff --git a/Libraries/Text/RCTText.xcodeproj/project.pbxproj b/Libraries/Text/RCTText.xcodeproj/project.pbxproj index f7e44b9b3605cd..77b733a48e0937 100644 --- a/Libraries/Text/RCTText.xcodeproj/project.pbxproj +++ b/Libraries/Text/RCTText.xcodeproj/project.pbxproj @@ -27,6 +27,8 @@ 58B511D01A9E6C5C00147676 /* RCTShadowText.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B511CB1A9E6C5C00147676 /* RCTShadowText.m */; }; 58B511D11A9E6C5C00147676 /* RCTTextManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B511CD1A9E6C5C00147676 /* RCTTextManager.m */; }; 58B512161A9E6EFF00147676 /* RCTText.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B512141A9E6EFF00147676 /* RCTText.m */; }; + AF3225F91DE5574F00D3E7E7 /* RCTConvert+Text.m in Sources */ = {isa = PBXBuildFile; fileRef = AF3225F81DE5574F00D3E7E7 /* RCTConvert+Text.m */; }; + AF3225FA1DE5574F00D3E7E7 /* RCTConvert+Text.m in Sources */ = {isa = PBXBuildFile; fileRef = AF3225F81DE5574F00D3E7E7 /* RCTConvert+Text.m */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -73,6 +75,8 @@ 58B511CD1A9E6C5C00147676 /* RCTTextManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTextManager.m; sourceTree = ""; }; 58B512141A9E6EFF00147676 /* RCTText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTText.m; sourceTree = ""; }; 58B512151A9E6EFF00147676 /* RCTText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTText.h; sourceTree = ""; }; + AF3225F71DE5574F00D3E7E7 /* RCTConvert+Text.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+Text.h"; sourceTree = ""; }; + AF3225F81DE5574F00D3E7E7 /* RCTConvert+Text.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+Text.m"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -96,6 +100,8 @@ 58B511921A9E6C1200147676 = { isa = PBXGroup; children = ( + AF3225F71DE5574F00D3E7E7 /* RCTConvert+Text.h */, + AF3225F81DE5574F00D3E7E7 /* RCTConvert+Text.m */, 19FC5C861D41A4220090108F /* RCTTextSelection.h */, 19FC5C841D41A4120090108F /* RCTTextSelection.m */, 58B511C61A9E6C5C00147676 /* RCTRawTextManager.h */, @@ -216,6 +222,7 @@ 2D3B5F3B1D9B106F00451313 /* RCTTextView.m in Sources */, 2D3B5F3A1D9B106F00451313 /* RCTTextFieldManager.m in Sources */, 2D3B5F341D9B103100451313 /* RCTRawTextManager.m in Sources */, + AF3225FA1DE5574F00D3E7E7 /* RCTConvert+Text.m in Sources */, 2D3B5F3C1D9B106F00451313 /* RCTTextViewManager.m in Sources */, 2D3B5F331D9B102D00451313 /* RCTTextSelection.m in Sources */, 2D3B5F351D9B103300451313 /* RCTShadowRawText.m in Sources */, @@ -233,6 +240,7 @@ 1362F1001B4D51F400E06D8C /* RCTTextField.m in Sources */, 58B512161A9E6EFF00147676 /* RCTText.m in Sources */, 1362F1011B4D51F400E06D8C /* RCTTextFieldManager.m in Sources */, + AF3225F91DE5574F00D3E7E7 /* RCTConvert+Text.m in Sources */, 131B6AC11AF0CD0600FFC3E0 /* RCTTextViewManager.m in Sources */, 58B511CF1A9E6C5C00147676 /* RCTShadowRawText.m in Sources */, 58B511D01A9E6C5C00147676 /* RCTShadowText.m in Sources */, diff --git a/Libraries/Text/RCTTextField.h b/Libraries/Text/RCTTextField.h index 0448dcfca8ca8f..7017e71525adc3 100644 --- a/Libraries/Text/RCTTextField.h +++ b/Libraries/Text/RCTTextField.h @@ -16,7 +16,6 @@ @interface RCTTextField : UITextField @property (nonatomic, assign) BOOL caretHidden; -@property (nonatomic, assign) BOOL autoCorrect; @property (nonatomic, assign) BOOL selectTextOnFocus; @property (nonatomic, assign) BOOL blurOnSubmit; @property (nonatomic, assign) UIEdgeInsets contentInset; diff --git a/Libraries/Text/RCTTextField.m b/Libraries/Text/RCTTextField.m index 50b85241fdc27c..b72d4099adec2f 100644 --- a/Libraries/Text/RCTTextField.m +++ b/Libraries/Text/RCTTextField.m @@ -149,16 +149,6 @@ - (CGRect)editingRectForBounds:(CGRect)bounds return [self textRectForBounds:bounds]; } -- (void)setAutoCorrect:(BOOL)autoCorrect -{ - self.autocorrectionType = (autoCorrect ? UITextAutocorrectionTypeYes : UITextAutocorrectionTypeNo); -} - -- (BOOL)autoCorrect -{ - return self.autocorrectionType == UITextAutocorrectionTypeYes; -} - - (void)textFieldDidChange { _nativeEventCount++; diff --git a/Libraries/Text/RCTTextFieldManager.m b/Libraries/Text/RCTTextFieldManager.m index 3c125caa309033..af0577b2944df0 100644 --- a/Libraries/Text/RCTTextFieldManager.m +++ b/Libraries/Text/RCTTextFieldManager.m @@ -13,6 +13,7 @@ #import "RCTShadowView.h" #import "RCTTextField.h" #import "RCTFont.h" +#import "RCTConvert+Text.h" @interface RCTTextFieldManager() @@ -75,7 +76,7 @@ - (BOOL)textFieldShouldEndEditing:(RCTTextField *)textField } RCT_EXPORT_VIEW_PROPERTY(caretHidden, BOOL) -RCT_EXPORT_VIEW_PROPERTY(autoCorrect, BOOL) +RCT_REMAP_VIEW_PROPERTY(autoCorrect, autocorrectionType, UITextAutocorrectionType) RCT_REMAP_VIEW_PROPERTY(editable, enabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(placeholder, NSString) RCT_EXPORT_VIEW_PROPERTY(placeholderTextColor, UIColor) diff --git a/Libraries/Text/RCTTextView.h b/Libraries/Text/RCTTextView.h index 03a187216af559..1a737ad2aabb6b 100644 --- a/Libraries/Text/RCTTextView.h +++ b/Libraries/Text/RCTTextView.h @@ -16,7 +16,7 @@ @interface RCTTextView : RCTView -@property (nonatomic, assign) BOOL autoCorrect; +@property (nonatomic, assign) UITextAutocorrectionType autocorrectionType; @property (nonatomic, assign) BOOL blurOnSubmit; @property (nonatomic, assign) BOOL clearTextOnFocus; @property (nonatomic, assign) BOOL selectTextOnFocus; diff --git a/Libraries/Text/RCTTextView.m b/Libraries/Text/RCTTextView.m index 3cbd393dbb7aa5..058834636d228c 100644 --- a/Libraries/Text/RCTTextView.m +++ b/Libraries/Text/RCTTextView.m @@ -519,14 +519,14 @@ - (void)updatePlaceholderVisibility } } -- (void)setAutoCorrect:(BOOL)autoCorrect +- (void)setAutocorrectionType:(UITextAutocorrectionType)autocorrectionType { - _textView.autocorrectionType = (autoCorrect ? UITextAutocorrectionTypeYes : UITextAutocorrectionTypeNo); + _textView.autocorrectionType = autocorrectionType; } -- (BOOL)autoCorrect +- (UITextAutocorrectionType)autocorrectionType { - return _textView.autocorrectionType == UITextAutocorrectionTypeYes; + return _textView.autocorrectionType; } - (BOOL)textViewShouldBeginEditing:(UITextView *)textView diff --git a/Libraries/Text/RCTTextViewManager.m b/Libraries/Text/RCTTextViewManager.m index 050a93322dd021..7478f83435d085 100644 --- a/Libraries/Text/RCTTextViewManager.m +++ b/Libraries/Text/RCTTextViewManager.m @@ -14,6 +14,7 @@ #import "RCTShadowView.h" #import "RCTTextView.h" #import "RCTFont.h" +#import "RCTConvert+Text.h" @implementation RCTTextViewManager @@ -25,7 +26,7 @@ - (UIView *)view } RCT_REMAP_VIEW_PROPERTY(autoCapitalize, textView.autocapitalizationType, UITextAutocapitalizationType) -RCT_EXPORT_VIEW_PROPERTY(autoCorrect, BOOL) +RCT_REMAP_VIEW_PROPERTY(autoCorrect, autocorrectionType, UITextAutocorrectionType) RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL) RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL) RCT_REMAP_VIEW_PROPERTY(color, textView.textColor, UIColor)