From c491b2223313676bd4900de7a8c70a10051fa9f0 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sun, 7 Jan 2018 18:21:48 -0800 Subject: [PATCH] RCTBaseTextInputViewManager: new base class for TextInput view managers Summary: Bunch or identical code was moved to superclass. Reviewed By: mmmulani Differential Revision: D6663772 fbshipit-source-id: 82321f56bbab0e9d17c0227c97dd86904cf5ab30 --- .../Text/RCTText.xcodeproj/project.pbxproj | 10 +++ .../RCTMultilineTextInputViewManager.h | 4 +- .../RCTMultilineTextInputViewManager.m | 42 ------------ .../TextInput/RCTBaseTextInputViewManager.h | 14 ++++ .../TextInput/RCTBaseTextInputViewManager.m | 67 +++++++++++++++++++ .../RCTSinglelineTextInputViewManager.h | 4 +- .../RCTSinglelineTextInputViewManager.m | 42 ------------ 7 files changed, 95 insertions(+), 88 deletions(-) create mode 100644 Libraries/Text/TextInput/RCTBaseTextInputViewManager.h create mode 100644 Libraries/Text/TextInput/RCTBaseTextInputViewManager.m diff --git a/Libraries/Text/RCTText.xcodeproj/project.pbxproj b/Libraries/Text/RCTText.xcodeproj/project.pbxproj index 226a81d4f2e235..fd6625ac95e63f 100644 --- a/Libraries/Text/RCTText.xcodeproj/project.pbxproj +++ b/Libraries/Text/RCTText.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 5989E14D20018A2200EA444A /* RCTBaseTextInputViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 5989E14C20018A2200EA444A /* RCTBaseTextInputViewManager.m */; }; + 5989E14E20018A6600EA444A /* RCTBaseTextInputViewManager.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 5989E14B20018A2200EA444A /* RCTBaseTextInputViewManager.h */; }; + 5989E14F20018A7800EA444A /* RCTBaseTextInputViewManager.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 5989E14B20018A2200EA444A /* RCTBaseTextInputViewManager.h */; }; 59E604521FE9CAF100BD90C5 /* RCTTextShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59E6042F1FE9CAF100BD90C5 /* RCTTextShadowView.m */; }; 59E604531FE9CAF100BD90C5 /* RCTTextShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59E6042F1FE9CAF100BD90C5 /* RCTTextShadowView.m */; }; 59E604541FE9CAF100BD90C5 /* RCTTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59E604311FE9CAF100BD90C5 /* RCTTextView.m */; }; @@ -94,6 +97,7 @@ dstPath = include/RCTText; dstSubfolderSpec = 16; files = ( + 5989E14E20018A6600EA444A /* RCTBaseTextInputViewManager.h in Copy Headers */, 59E604871FE9CB4A00BD90C5 /* RCTConvert+Text.h in Copy Headers */, 59E604881FE9CB4A00BD90C5 /* RCTFontAttributes.h in Copy Headers */, 59E604891FE9CB4A00BD90C5 /* RCTFontAttributesDelegate.h in Copy Headers */, @@ -125,6 +129,7 @@ dstPath = include/RCTText; dstSubfolderSpec = 16; files = ( + 5989E14F20018A7800EA444A /* RCTBaseTextInputViewManager.h in Copy Headers */, 59E604721FE9CB3F00BD90C5 /* RCTConvert+Text.h in Copy Headers */, 59E604731FE9CB3F00BD90C5 /* RCTFontAttributes.h in Copy Headers */, 59E604741FE9CB3F00BD90C5 /* RCTFontAttributesDelegate.h in Copy Headers */, @@ -155,6 +160,8 @@ /* Begin PBXFileReference section */ 2D2A287B1D9B048500D4039D /* libRCTText-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libRCTText-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 58B5119B1A9E6C1200147676 /* libRCTText.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTText.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 5989E14B20018A2200EA444A /* RCTBaseTextInputViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTBaseTextInputViewManager.h; sourceTree = ""; }; + 5989E14C20018A2200EA444A /* RCTBaseTextInputViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTBaseTextInputViewManager.m; sourceTree = ""; }; 59E6042C1FE9CAF100BD90C5 /* RCTRawTextShadowView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTRawTextShadowView.h; sourceTree = ""; }; 59E6042E1FE9CAF100BD90C5 /* RCTTextShadowView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTextShadowView.h; sourceTree = ""; }; 59E6042F1FE9CAF100BD90C5 /* RCTTextShadowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTextShadowView.m; sourceTree = ""; }; @@ -250,6 +257,8 @@ 59E604441FE9CAF100BD90C5 /* RCTBackedTextInputViewProtocol.h */, 59E604451FE9CAF100BD90C5 /* RCTBaseTextInputView.h */, 59E604461FE9CAF100BD90C5 /* RCTBaseTextInputView.m */, + 5989E14B20018A2200EA444A /* RCTBaseTextInputViewManager.h */, + 5989E14C20018A2200EA444A /* RCTBaseTextInputViewManager.m */, 59E604471FE9CAF100BD90C5 /* RCTTextSelection.h */, 59E604481FE9CAF100BD90C5 /* RCTTextSelection.m */, 59E604491FE9CAF100BD90C5 /* Singleline */, @@ -396,6 +405,7 @@ 59E6045C1FE9CAF100BD90C5 /* RCTMultilineTextInputShadowView.m in Sources */, 59E604581FE9CAF100BD90C5 /* RCTRawTextShadowView.m in Sources */, 59E604541FE9CAF100BD90C5 /* RCTTextView.m in Sources */, + 5989E14D20018A2200EA444A /* RCTBaseTextInputViewManager.m in Sources */, 59E604681FE9CAF100BD90C5 /* RCTTextSelection.m in Sources */, 59E6045E1FE9CAF100BD90C5 /* RCTMultilineTextInputView.m in Sources */, 59E604601FE9CAF100BD90C5 /* RCTMultilineTextInputViewManager.m in Sources */, diff --git a/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.h b/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.h index df3617d537f753..322cfa16790175 100644 --- a/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.h +++ b/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.h @@ -7,8 +7,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -#import +#import "RCTBaseTextInputViewManager.h" -@interface RCTMultilineTextInputViewManager : RCTViewManager +@interface RCTMultilineTextInputViewManager : RCTBaseTextInputViewManager @end diff --git a/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.m b/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.m index 328b2e77ead4b4..9676a63f24d99c 100644 --- a/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.m +++ b/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.m @@ -33,34 +33,6 @@ - (UIView *)view return [[RCTMultilineTextInputView alloc] initWithBridge:self.bridge]; } -#pragma mark - Unified properties - -RCT_REMAP_VIEW_PROPERTY(allowFontScaling, fontAttributes.allowFontScaling, BOOL) -RCT_REMAP_VIEW_PROPERTY(autoCapitalize, backedTextInputView.autocapitalizationType, UITextAutocapitalizationType) -RCT_REMAP_VIEW_PROPERTY(autoCorrect, backedTextInputView.autocorrectionType, UITextAutocorrectionType) -RCT_REMAP_VIEW_PROPERTY(color, backedTextInputView.textColor, UIColor) -RCT_REMAP_VIEW_PROPERTY(editable, backedTextInputView.editable, BOOL) -RCT_REMAP_VIEW_PROPERTY(enablesReturnKeyAutomatically, backedTextInputView.enablesReturnKeyAutomatically, BOOL) -RCT_REMAP_VIEW_PROPERTY(fontSize, fontAttributes.fontSize, NSNumber) -RCT_REMAP_VIEW_PROPERTY(fontWeight, fontAttributes.fontWeight, NSString) -RCT_REMAP_VIEW_PROPERTY(fontStyle, fontAttributes.fontStyle, NSString) -RCT_REMAP_VIEW_PROPERTY(fontFamily, fontAttributes.fontFamily, NSString) -RCT_REMAP_VIEW_PROPERTY(keyboardAppearance, backedTextInputView.keyboardAppearance, UIKeyboardAppearance) -RCT_REMAP_VIEW_PROPERTY(keyboardType, backedTextInputView.keyboardType, UIKeyboardType) -RCT_REMAP_VIEW_PROPERTY(placeholder, backedTextInputView.placeholder, NSString) -RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, backedTextInputView.placeholderColor, UIColor) -RCT_REMAP_VIEW_PROPERTY(returnKeyType, backedTextInputView.returnKeyType, UIReturnKeyType) -RCT_REMAP_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BOOL) -RCT_REMAP_VIEW_PROPERTY(selectionColor, backedTextInputView.tintColor, UIColor) -RCT_REMAP_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingType, UITextSpellCheckingType) -RCT_REMAP_VIEW_PROPERTY(textAlign, backedTextInputView.textAlignment, NSTextAlignment) -RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL) -RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL) -RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber) -RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL) -RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection) -RCT_EXPORT_VIEW_PROPERTY(text, NSString) - #pragma mark - Multiline (aka TextView) specific properties RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock) @@ -69,22 +41,8 @@ - (UIView *)view RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock) RCT_EXPORT_VIEW_PROPERTY(onTextInput, RCTDirectEventBlock) -RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger) - #if !TARGET_OS_TV RCT_REMAP_VIEW_PROPERTY(dataDetectorTypes, backedTextInputView.dataDetectorTypes, UIDataDetectorTypes) #endif -- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(RCTShadowView *)shadowView -{ - NSNumber *reactTag = shadowView.reactTag; - UIEdgeInsets borderAsInsets = shadowView.borderAsInsets; - UIEdgeInsets paddingAsInsets = shadowView.paddingAsInsets; - return ^(RCTUIManager *uiManager, NSDictionary *viewRegistry) { - RCTBaseTextInputView *view = viewRegistry[reactTag]; - view.reactBorderInsets = borderAsInsets; - view.reactPaddingInsets = paddingAsInsets; - }; -} - @end diff --git a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.h b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.h new file mode 100644 index 00000000000000..0d5b669c92102f --- /dev/null +++ b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.h @@ -0,0 +1,14 @@ +/** + * 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 + +@interface RCTBaseTextInputViewManager : RCTViewManager + +@end diff --git a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m new file mode 100644 index 00000000000000..c2ffffe21598fd --- /dev/null +++ b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m @@ -0,0 +1,67 @@ +/** + * 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 "RCTBaseTextInputViewManager.h" + +#import +#import +#import +#import +#import + +#import "RCTConvert+Text.h" +#import "RCTBaseTextInputView.h" + +@implementation RCTBaseTextInputViewManager + +RCT_EXPORT_MODULE() + +#pragma mark - Unified properties + +RCT_REMAP_VIEW_PROPERTY(allowFontScaling, fontAttributes.allowFontScaling, BOOL) +RCT_REMAP_VIEW_PROPERTY(autoCapitalize, backedTextInputView.autocapitalizationType, UITextAutocapitalizationType) +RCT_REMAP_VIEW_PROPERTY(autoCorrect, backedTextInputView.autocorrectionType, UITextAutocorrectionType) +RCT_REMAP_VIEW_PROPERTY(color, backedTextInputView.textColor, UIColor) +RCT_REMAP_VIEW_PROPERTY(editable, backedTextInputView.editable, BOOL) +RCT_REMAP_VIEW_PROPERTY(enablesReturnKeyAutomatically, backedTextInputView.enablesReturnKeyAutomatically, BOOL) +RCT_REMAP_VIEW_PROPERTY(fontSize, fontAttributes.fontSize, NSNumber) +RCT_REMAP_VIEW_PROPERTY(fontWeight, fontAttributes.fontWeight, NSString) +RCT_REMAP_VIEW_PROPERTY(fontStyle, fontAttributes.fontStyle, NSString) +RCT_REMAP_VIEW_PROPERTY(fontFamily, fontAttributes.fontFamily, NSString) +RCT_REMAP_VIEW_PROPERTY(keyboardAppearance, backedTextInputView.keyboardAppearance, UIKeyboardAppearance) +RCT_REMAP_VIEW_PROPERTY(keyboardType, backedTextInputView.keyboardType, UIKeyboardType) +RCT_REMAP_VIEW_PROPERTY(placeholder, backedTextInputView.placeholder, NSString) +RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, backedTextInputView.placeholderColor, UIColor) +RCT_REMAP_VIEW_PROPERTY(returnKeyType, backedTextInputView.returnKeyType, UIReturnKeyType) +RCT_REMAP_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BOOL) +RCT_REMAP_VIEW_PROPERTY(selectionColor, backedTextInputView.tintColor, UIColor) +RCT_REMAP_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingType, UITextSpellCheckingType) +RCT_REMAP_VIEW_PROPERTY(textAlign, backedTextInputView.textAlignment, NSTextAlignment) +RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL) +RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL) +RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber) +RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL) +RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection) +RCT_EXPORT_VIEW_PROPERTY(text, NSString) + +RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger) + +- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(RCTShadowView *)shadowView +{ + NSNumber *reactTag = shadowView.reactTag; + UIEdgeInsets borderAsInsets = shadowView.borderAsInsets; + UIEdgeInsets paddingAsInsets = shadowView.paddingAsInsets; + return ^(RCTUIManager *uiManager, NSDictionary *viewRegistry) { + RCTBaseTextInputView *view = viewRegistry[reactTag]; + view.reactBorderInsets = borderAsInsets; + view.reactPaddingInsets = paddingAsInsets; + }; +} + +@end diff --git a/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputViewManager.h b/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputViewManager.h index 3cd86bab289fbf..90f5fbda244249 100644 --- a/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputViewManager.h +++ b/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputViewManager.h @@ -7,8 +7,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -#import +#import "RCTBaseTextInputViewManager.h" -@interface RCTSinglelineTextInputViewManager : RCTViewManager +@interface RCTSinglelineTextInputViewManager : RCTBaseTextInputViewManager @end diff --git a/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputViewManager.m b/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputViewManager.m index ff7511884a4970..5b96501aa19a31 100644 --- a/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputViewManager.m +++ b/Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputViewManager.m @@ -33,52 +33,10 @@ - (UIView *)view return [[RCTSinglelineTextInputView alloc] initWithBridge:self.bridge]; } -#pragma mark - Unified properties - -RCT_REMAP_VIEW_PROPERTY(allowFontScaling, fontAttributes.allowFontScaling, BOOL) -RCT_REMAP_VIEW_PROPERTY(autoCapitalize, backedTextInputView.autocapitalizationType, UITextAutocapitalizationType) -RCT_REMAP_VIEW_PROPERTY(autoCorrect, backedTextInputView.autocorrectionType, UITextAutocorrectionType) -RCT_REMAP_VIEW_PROPERTY(color, backedTextInputView.textColor, UIColor) -RCT_REMAP_VIEW_PROPERTY(editable, backedTextInputView.editable, BOOL) -RCT_REMAP_VIEW_PROPERTY(enablesReturnKeyAutomatically, backedTextInputView.enablesReturnKeyAutomatically, BOOL) -RCT_REMAP_VIEW_PROPERTY(fontSize, fontAttributes.fontSize, NSNumber) -RCT_REMAP_VIEW_PROPERTY(fontWeight, fontAttributes.fontWeight, NSString) -RCT_REMAP_VIEW_PROPERTY(fontStyle, fontAttributes.fontStyle, NSString) -RCT_REMAP_VIEW_PROPERTY(fontFamily, fontAttributes.fontFamily, NSString) -RCT_REMAP_VIEW_PROPERTY(keyboardAppearance, backedTextInputView.keyboardAppearance, UIKeyboardAppearance) -RCT_REMAP_VIEW_PROPERTY(keyboardType, backedTextInputView.keyboardType, UIKeyboardType) -RCT_REMAP_VIEW_PROPERTY(placeholder, backedTextInputView.placeholder, NSString) -RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, backedTextInputView.placeholderColor, UIColor) -RCT_REMAP_VIEW_PROPERTY(returnKeyType, backedTextInputView.returnKeyType, UIReturnKeyType) -RCT_REMAP_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BOOL) -RCT_REMAP_VIEW_PROPERTY(selectionColor, backedTextInputView.tintColor, UIColor) -RCT_REMAP_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingType, UITextSpellCheckingType) -RCT_REMAP_VIEW_PROPERTY(textAlign, backedTextInputView.textAlignment, NSTextAlignment) -RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL) -RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL) -RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber) -RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL) -RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection) -RCT_EXPORT_VIEW_PROPERTY(text, NSString) - #pragma mark - Singleline (aka TextField) specific properties RCT_REMAP_VIEW_PROPERTY(caretHidden, backedTextInputView.caretHidden, BOOL) RCT_REMAP_VIEW_PROPERTY(clearButtonMode, backedTextInputView.clearButtonMode, UITextFieldViewMode) RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock) -RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger) - -- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(RCTShadowView *)shadowView -{ - NSNumber *reactTag = shadowView.reactTag; - UIEdgeInsets borderAsInsets = shadowView.borderAsInsets; - UIEdgeInsets paddingAsInsets = shadowView.paddingAsInsets; - return ^(RCTUIManager *uiManager, NSDictionary *viewRegistry) { - RCTBaseTextInputView *view = viewRegistry[reactTag]; - view.reactBorderInsets = borderAsInsets; - view.reactPaddingInsets = paddingAsInsets; - }; -} - @end