Skip to content

Commit c491b22

Browse files
sherginfacebook-github-bot
authored andcommitted
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
1 parent 176a578 commit c491b22

7 files changed

+95
-88
lines changed

Libraries/Text/RCTText.xcodeproj/project.pbxproj

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
5989E14D20018A2200EA444A /* RCTBaseTextInputViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 5989E14C20018A2200EA444A /* RCTBaseTextInputViewManager.m */; };
11+
5989E14E20018A6600EA444A /* RCTBaseTextInputViewManager.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 5989E14B20018A2200EA444A /* RCTBaseTextInputViewManager.h */; };
12+
5989E14F20018A7800EA444A /* RCTBaseTextInputViewManager.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 5989E14B20018A2200EA444A /* RCTBaseTextInputViewManager.h */; };
1013
59E604521FE9CAF100BD90C5 /* RCTTextShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59E6042F1FE9CAF100BD90C5 /* RCTTextShadowView.m */; };
1114
59E604531FE9CAF100BD90C5 /* RCTTextShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59E6042F1FE9CAF100BD90C5 /* RCTTextShadowView.m */; };
1215
59E604541FE9CAF100BD90C5 /* RCTTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59E604311FE9CAF100BD90C5 /* RCTTextView.m */; };
@@ -94,6 +97,7 @@
9497
dstPath = include/RCTText;
9598
dstSubfolderSpec = 16;
9699
files = (
100+
5989E14E20018A6600EA444A /* RCTBaseTextInputViewManager.h in Copy Headers */,
97101
59E604871FE9CB4A00BD90C5 /* RCTConvert+Text.h in Copy Headers */,
98102
59E604881FE9CB4A00BD90C5 /* RCTFontAttributes.h in Copy Headers */,
99103
59E604891FE9CB4A00BD90C5 /* RCTFontAttributesDelegate.h in Copy Headers */,
@@ -125,6 +129,7 @@
125129
dstPath = include/RCTText;
126130
dstSubfolderSpec = 16;
127131
files = (
132+
5989E14F20018A7800EA444A /* RCTBaseTextInputViewManager.h in Copy Headers */,
128133
59E604721FE9CB3F00BD90C5 /* RCTConvert+Text.h in Copy Headers */,
129134
59E604731FE9CB3F00BD90C5 /* RCTFontAttributes.h in Copy Headers */,
130135
59E604741FE9CB3F00BD90C5 /* RCTFontAttributesDelegate.h in Copy Headers */,
@@ -155,6 +160,8 @@
155160
/* Begin PBXFileReference section */
156161
2D2A287B1D9B048500D4039D /* libRCTText-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libRCTText-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
157162
58B5119B1A9E6C1200147676 /* libRCTText.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTText.a; sourceTree = BUILT_PRODUCTS_DIR; };
163+
5989E14B20018A2200EA444A /* RCTBaseTextInputViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTBaseTextInputViewManager.h; sourceTree = "<group>"; };
164+
5989E14C20018A2200EA444A /* RCTBaseTextInputViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTBaseTextInputViewManager.m; sourceTree = "<group>"; };
158165
59E6042C1FE9CAF100BD90C5 /* RCTRawTextShadowView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTRawTextShadowView.h; sourceTree = "<group>"; };
159166
59E6042E1FE9CAF100BD90C5 /* RCTTextShadowView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTextShadowView.h; sourceTree = "<group>"; };
160167
59E6042F1FE9CAF100BD90C5 /* RCTTextShadowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTextShadowView.m; sourceTree = "<group>"; };
@@ -250,6 +257,8 @@
250257
59E604441FE9CAF100BD90C5 /* RCTBackedTextInputViewProtocol.h */,
251258
59E604451FE9CAF100BD90C5 /* RCTBaseTextInputView.h */,
252259
59E604461FE9CAF100BD90C5 /* RCTBaseTextInputView.m */,
260+
5989E14B20018A2200EA444A /* RCTBaseTextInputViewManager.h */,
261+
5989E14C20018A2200EA444A /* RCTBaseTextInputViewManager.m */,
253262
59E604471FE9CAF100BD90C5 /* RCTTextSelection.h */,
254263
59E604481FE9CAF100BD90C5 /* RCTTextSelection.m */,
255264
59E604491FE9CAF100BD90C5 /* Singleline */,
@@ -396,6 +405,7 @@
396405
59E6045C1FE9CAF100BD90C5 /* RCTMultilineTextInputShadowView.m in Sources */,
397406
59E604581FE9CAF100BD90C5 /* RCTRawTextShadowView.m in Sources */,
398407
59E604541FE9CAF100BD90C5 /* RCTTextView.m in Sources */,
408+
5989E14D20018A2200EA444A /* RCTBaseTextInputViewManager.m in Sources */,
399409
59E604681FE9CAF100BD90C5 /* RCTTextSelection.m in Sources */,
400410
59E6045E1FE9CAF100BD90C5 /* RCTMultilineTextInputView.m in Sources */,
401411
59E604601FE9CAF100BD90C5 /* RCTMultilineTextInputViewManager.m in Sources */,

Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10-
#import <React/RCTViewManager.h>
10+
#import "RCTBaseTextInputViewManager.h"
1111

12-
@interface RCTMultilineTextInputViewManager : RCTViewManager
12+
@interface RCTMultilineTextInputViewManager : RCTBaseTextInputViewManager
1313

1414
@end

Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.m

-42
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,6 @@ - (UIView *)view
3333
return [[RCTMultilineTextInputView alloc] initWithBridge:self.bridge];
3434
}
3535

36-
#pragma mark - Unified <TextInput> properties
37-
38-
RCT_REMAP_VIEW_PROPERTY(allowFontScaling, fontAttributes.allowFontScaling, BOOL)
39-
RCT_REMAP_VIEW_PROPERTY(autoCapitalize, backedTextInputView.autocapitalizationType, UITextAutocapitalizationType)
40-
RCT_REMAP_VIEW_PROPERTY(autoCorrect, backedTextInputView.autocorrectionType, UITextAutocorrectionType)
41-
RCT_REMAP_VIEW_PROPERTY(color, backedTextInputView.textColor, UIColor)
42-
RCT_REMAP_VIEW_PROPERTY(editable, backedTextInputView.editable, BOOL)
43-
RCT_REMAP_VIEW_PROPERTY(enablesReturnKeyAutomatically, backedTextInputView.enablesReturnKeyAutomatically, BOOL)
44-
RCT_REMAP_VIEW_PROPERTY(fontSize, fontAttributes.fontSize, NSNumber)
45-
RCT_REMAP_VIEW_PROPERTY(fontWeight, fontAttributes.fontWeight, NSString)
46-
RCT_REMAP_VIEW_PROPERTY(fontStyle, fontAttributes.fontStyle, NSString)
47-
RCT_REMAP_VIEW_PROPERTY(fontFamily, fontAttributes.fontFamily, NSString)
48-
RCT_REMAP_VIEW_PROPERTY(keyboardAppearance, backedTextInputView.keyboardAppearance, UIKeyboardAppearance)
49-
RCT_REMAP_VIEW_PROPERTY(keyboardType, backedTextInputView.keyboardType, UIKeyboardType)
50-
RCT_REMAP_VIEW_PROPERTY(placeholder, backedTextInputView.placeholder, NSString)
51-
RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, backedTextInputView.placeholderColor, UIColor)
52-
RCT_REMAP_VIEW_PROPERTY(returnKeyType, backedTextInputView.returnKeyType, UIReturnKeyType)
53-
RCT_REMAP_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BOOL)
54-
RCT_REMAP_VIEW_PROPERTY(selectionColor, backedTextInputView.tintColor, UIColor)
55-
RCT_REMAP_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingType, UITextSpellCheckingType)
56-
RCT_REMAP_VIEW_PROPERTY(textAlign, backedTextInputView.textAlignment, NSTextAlignment)
57-
RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL)
58-
RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)
59-
RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber)
60-
RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL)
61-
RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection)
62-
RCT_EXPORT_VIEW_PROPERTY(text, NSString)
63-
6436
#pragma mark - Multiline <TextInput> (aka TextView) specific properties
6537

6638
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
@@ -69,22 +41,8 @@ - (UIView *)view
6941
RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock)
7042
RCT_EXPORT_VIEW_PROPERTY(onTextInput, RCTDirectEventBlock)
7143

72-
RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger)
73-
7444
#if !TARGET_OS_TV
7545
RCT_REMAP_VIEW_PROPERTY(dataDetectorTypes, backedTextInputView.dataDetectorTypes, UIDataDetectorTypes)
7646
#endif
7747

78-
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(RCTShadowView *)shadowView
79-
{
80-
NSNumber *reactTag = shadowView.reactTag;
81-
UIEdgeInsets borderAsInsets = shadowView.borderAsInsets;
82-
UIEdgeInsets paddingAsInsets = shadowView.paddingAsInsets;
83-
return ^(RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTBaseTextInputView *> *viewRegistry) {
84-
RCTBaseTextInputView *view = viewRegistry[reactTag];
85-
view.reactBorderInsets = borderAsInsets;
86-
view.reactPaddingInsets = paddingAsInsets;
87-
};
88-
}
89-
9048
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 <React/RCTViewManager.h>
11+
12+
@interface RCTBaseTextInputViewManager : RCTViewManager
13+
14+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 "RCTBaseTextInputViewManager.h"
11+
12+
#import <React/RCTBridge.h>
13+
#import <React/RCTConvert.h>
14+
#import <React/RCTFont.h>
15+
#import <React/RCTShadowView+Layout.h>
16+
#import <React/RCTShadowView.h>
17+
18+
#import "RCTConvert+Text.h"
19+
#import "RCTBaseTextInputView.h"
20+
21+
@implementation RCTBaseTextInputViewManager
22+
23+
RCT_EXPORT_MODULE()
24+
25+
#pragma mark - Unified <TextInput> properties
26+
27+
RCT_REMAP_VIEW_PROPERTY(allowFontScaling, fontAttributes.allowFontScaling, BOOL)
28+
RCT_REMAP_VIEW_PROPERTY(autoCapitalize, backedTextInputView.autocapitalizationType, UITextAutocapitalizationType)
29+
RCT_REMAP_VIEW_PROPERTY(autoCorrect, backedTextInputView.autocorrectionType, UITextAutocorrectionType)
30+
RCT_REMAP_VIEW_PROPERTY(color, backedTextInputView.textColor, UIColor)
31+
RCT_REMAP_VIEW_PROPERTY(editable, backedTextInputView.editable, BOOL)
32+
RCT_REMAP_VIEW_PROPERTY(enablesReturnKeyAutomatically, backedTextInputView.enablesReturnKeyAutomatically, BOOL)
33+
RCT_REMAP_VIEW_PROPERTY(fontSize, fontAttributes.fontSize, NSNumber)
34+
RCT_REMAP_VIEW_PROPERTY(fontWeight, fontAttributes.fontWeight, NSString)
35+
RCT_REMAP_VIEW_PROPERTY(fontStyle, fontAttributes.fontStyle, NSString)
36+
RCT_REMAP_VIEW_PROPERTY(fontFamily, fontAttributes.fontFamily, NSString)
37+
RCT_REMAP_VIEW_PROPERTY(keyboardAppearance, backedTextInputView.keyboardAppearance, UIKeyboardAppearance)
38+
RCT_REMAP_VIEW_PROPERTY(keyboardType, backedTextInputView.keyboardType, UIKeyboardType)
39+
RCT_REMAP_VIEW_PROPERTY(placeholder, backedTextInputView.placeholder, NSString)
40+
RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, backedTextInputView.placeholderColor, UIColor)
41+
RCT_REMAP_VIEW_PROPERTY(returnKeyType, backedTextInputView.returnKeyType, UIReturnKeyType)
42+
RCT_REMAP_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BOOL)
43+
RCT_REMAP_VIEW_PROPERTY(selectionColor, backedTextInputView.tintColor, UIColor)
44+
RCT_REMAP_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingType, UITextSpellCheckingType)
45+
RCT_REMAP_VIEW_PROPERTY(textAlign, backedTextInputView.textAlignment, NSTextAlignment)
46+
RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL)
47+
RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)
48+
RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber)
49+
RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL)
50+
RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection)
51+
RCT_EXPORT_VIEW_PROPERTY(text, NSString)
52+
53+
RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger)
54+
55+
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(RCTShadowView *)shadowView
56+
{
57+
NSNumber *reactTag = shadowView.reactTag;
58+
UIEdgeInsets borderAsInsets = shadowView.borderAsInsets;
59+
UIEdgeInsets paddingAsInsets = shadowView.paddingAsInsets;
60+
return ^(RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTBaseTextInputView *> *viewRegistry) {
61+
RCTBaseTextInputView *view = viewRegistry[reactTag];
62+
view.reactBorderInsets = borderAsInsets;
63+
view.reactPaddingInsets = paddingAsInsets;
64+
};
65+
}
66+
67+
@end

Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputViewManager.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10-
#import <React/RCTViewManager.h>
10+
#import "RCTBaseTextInputViewManager.h"
1111

12-
@interface RCTSinglelineTextInputViewManager : RCTViewManager
12+
@interface RCTSinglelineTextInputViewManager : RCTBaseTextInputViewManager
1313

1414
@end

Libraries/Text/TextInput/Singleline/RCTSinglelineTextInputViewManager.m

-42
Original file line numberDiff line numberDiff line change
@@ -33,52 +33,10 @@ - (UIView *)view
3333
return [[RCTSinglelineTextInputView alloc] initWithBridge:self.bridge];
3434
}
3535

36-
#pragma mark - Unified <TextInput> properties
37-
38-
RCT_REMAP_VIEW_PROPERTY(allowFontScaling, fontAttributes.allowFontScaling, BOOL)
39-
RCT_REMAP_VIEW_PROPERTY(autoCapitalize, backedTextInputView.autocapitalizationType, UITextAutocapitalizationType)
40-
RCT_REMAP_VIEW_PROPERTY(autoCorrect, backedTextInputView.autocorrectionType, UITextAutocorrectionType)
41-
RCT_REMAP_VIEW_PROPERTY(color, backedTextInputView.textColor, UIColor)
42-
RCT_REMAP_VIEW_PROPERTY(editable, backedTextInputView.editable, BOOL)
43-
RCT_REMAP_VIEW_PROPERTY(enablesReturnKeyAutomatically, backedTextInputView.enablesReturnKeyAutomatically, BOOL)
44-
RCT_REMAP_VIEW_PROPERTY(fontSize, fontAttributes.fontSize, NSNumber)
45-
RCT_REMAP_VIEW_PROPERTY(fontWeight, fontAttributes.fontWeight, NSString)
46-
RCT_REMAP_VIEW_PROPERTY(fontStyle, fontAttributes.fontStyle, NSString)
47-
RCT_REMAP_VIEW_PROPERTY(fontFamily, fontAttributes.fontFamily, NSString)
48-
RCT_REMAP_VIEW_PROPERTY(keyboardAppearance, backedTextInputView.keyboardAppearance, UIKeyboardAppearance)
49-
RCT_REMAP_VIEW_PROPERTY(keyboardType, backedTextInputView.keyboardType, UIKeyboardType)
50-
RCT_REMAP_VIEW_PROPERTY(placeholder, backedTextInputView.placeholder, NSString)
51-
RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, backedTextInputView.placeholderColor, UIColor)
52-
RCT_REMAP_VIEW_PROPERTY(returnKeyType, backedTextInputView.returnKeyType, UIReturnKeyType)
53-
RCT_REMAP_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BOOL)
54-
RCT_REMAP_VIEW_PROPERTY(selectionColor, backedTextInputView.tintColor, UIColor)
55-
RCT_REMAP_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingType, UITextSpellCheckingType)
56-
RCT_REMAP_VIEW_PROPERTY(textAlign, backedTextInputView.textAlignment, NSTextAlignment)
57-
RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL)
58-
RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)
59-
RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber)
60-
RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL)
61-
RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection)
62-
RCT_EXPORT_VIEW_PROPERTY(text, NSString)
63-
6436
#pragma mark - Singleline <TextInput> (aka TextField) specific properties
6537

6638
RCT_REMAP_VIEW_PROPERTY(caretHidden, backedTextInputView.caretHidden, BOOL)
6739
RCT_REMAP_VIEW_PROPERTY(clearButtonMode, backedTextInputView.clearButtonMode, UITextFieldViewMode)
6840
RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock)
6941

70-
RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger)
71-
72-
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(RCTShadowView *)shadowView
73-
{
74-
NSNumber *reactTag = shadowView.reactTag;
75-
UIEdgeInsets borderAsInsets = shadowView.borderAsInsets;
76-
UIEdgeInsets paddingAsInsets = shadowView.paddingAsInsets;
77-
return ^(RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTBaseTextInputView *> *viewRegistry) {
78-
RCTBaseTextInputView *view = viewRegistry[reactTag];
79-
view.reactBorderInsets = borderAsInsets;
80-
view.reactPaddingInsets = paddingAsInsets;
81-
};
82-
}
83-
8442
@end

0 commit comments

Comments
 (0)