Permalink
Browse files

Introducing `RCTBackedTextInputViewProtocol`

Summary: RCTBackedTextInputViewProtocol is supposed to unify interface of backed text inputs which will make them accessible from managers and wrapper views.

Reviewed By: mmmulani

Differential Revision: D5144428

fbshipit-source-id: 473e7364d4af2edcd87c5555200e1325c38a8214
  • Loading branch information...
shergin authored and facebook-github-bot committed Jun 27, 2017
1 parent 2bf4167 commit 6ba8e29c89aca349c9e71d3c86b2044f216e3f30
@@ -0,0 +1,21 @@
/**
* 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 <UIKit/UIKit.h>
@protocol RCTBackedTextInputViewProtocol <UITextInput>
@property (nonatomic, copy, nullable) NSString *text;
@property (nonatomic, strong, nullable) UIColor *textColor;
@property (nonatomic, copy, nullable) NSString *placeholder;
@property (nonatomic, strong, nullable) UIColor *placeholderColor;
@property (nonatomic, assign, readonly) BOOL textWasPasted;
@property (nonatomic, strong, nullable) UIFont *font;
@end
@@ -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 */; };
599DF25F1F0306660079B53E /* RCTBackedTextInputViewProtocol.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 599DF25D1F0304B30079B53E /* RCTBackedTextInputViewProtocol.h */; };
599DF2611F0306C30079B53E /* RCTBackedTextInputViewProtocol.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 599DF25D1F0304B30079B53E /* RCTBackedTextInputViewProtocol.h */; };
59AF89AA1EDCBCC700F004B1 /* RCTUITextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 59AF89A91EDCBCC700F004B1 /* RCTUITextField.m */; };
59AF89AB1EDCBCC700F004B1 /* RCTUITextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 59AF89A91EDCBCC700F004B1 /* RCTUITextField.m */; };
59B125C91E6E4E15004E2A67 /* RCTUITextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59B125C81E6E4E15004E2A67 /* RCTUITextView.m */; };
@@ -39,6 +41,31 @@
AF3225FA1DE5574F00D3E7E7 /* RCTConvert+Text.m in Sources */ = {isa = PBXBuildFile; fileRef = AF3225F81DE5574F00D3E7E7 /* RCTConvert+Text.m */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
599DF25E1F0306540079B53E /* Copy Headers */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = include/RCTText;
dstSubfolderSpec = 16;
files = (
599DF25F1F0306660079B53E /* RCTBackedTextInputViewProtocol.h in Copy Headers */,
);
name = "Copy Headers";
runOnlyForDeploymentPostprocessing = 0;
};
599DF2601F0306AD0079B53E /* Copy Headers */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = include/RCTText;
dstSubfolderSpec = 16;
files = (
599DF2611F0306C30079B53E /* RCTBackedTextInputViewProtocol.h in Copy Headers */,
);
name = "Copy Headers";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
131B6ABC1AF0CD0600FFC3E0 /* RCTTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTextView.h; sourceTree = "<group>"; };
131B6ABD1AF0CD0600FFC3E0 /* RCTTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTextView.m; sourceTree = "<group>"; };
@@ -62,6 +89,7 @@
58B511CD1A9E6C5C00147676 /* RCTTextManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTextManager.m; sourceTree = "<group>"; };
58B512141A9E6EFF00147676 /* RCTText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTText.m; sourceTree = "<group>"; };
58B512151A9E6EFF00147676 /* RCTText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTText.h; sourceTree = "<group>"; };
599DF25D1F0304B30079B53E /* RCTBackedTextInputViewProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTBackedTextInputViewProtocol.h; sourceTree = "<group>"; };
59AF89A81EDCBCC700F004B1 /* RCTUITextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTUITextField.h; sourceTree = "<group>"; };
59AF89A91EDCBCC700F004B1 /* RCTUITextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTUITextField.m; sourceTree = "<group>"; };
59B125C71E6E4E15004E2A67 /* RCTUITextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTUITextView.h; sourceTree = "<group>"; };
@@ -79,6 +107,7 @@
isa = PBXGroup;
children = (
58B5119C1A9E6C1200147676 /* Products */,
599DF25D1F0304B30079B53E /* RCTBackedTextInputViewProtocol.h */,
AF3225F71DE5574F00D3E7E7 /* RCTConvert+Text.h */,
AF3225F81DE5574F00D3E7E7 /* RCTConvert+Text.m */,
58B511C61A9E6C5C00147676 /* RCTRawTextManager.h */,
@@ -130,6 +159,7 @@
isa = PBXNativeTarget;
buildConfigurationList = 2D2A28831D9B048500D4039D /* Build configuration list for PBXNativeTarget "RCTText-tvOS" */;
buildPhases = (
599DF2601F0306AD0079B53E /* Copy Headers */,
2D2A28771D9B048500D4039D /* Sources */,
);
buildRules = (
@@ -145,6 +175,7 @@
isa = PBXNativeTarget;
buildConfigurationList = 58B511AF1A9E6C1300147676 /* Build configuration list for PBXNativeTarget "RCTText" */;
buildPhases = (
599DF25E1F0306540079B53E /* Copy Headers */,
58B511971A9E6C1200147676 /* Sources */,
);
buildRules = (
@@ -9,6 +9,7 @@
#import <UIKit/UIKit.h>
#import <RCTText/RCTBackedTextInputViewProtocol.h>
#import <React/RCTComponent.h>
#import <React/RCTView.h>
@@ -17,6 +18,8 @@
@interface RCTTextField : RCTView
@property (nonatomic, readonly) id<RCTBackedTextInputViewProtocol> backedTextInputView;
@property (nonatomic, assign) BOOL caretHidden;
@property (nonatomic, assign) BOOL selectTextOnFocus;
@property (nonatomic, assign) BOOL blurOnSubmit;
@@ -76,6 +76,11 @@ - (void)dealloc
[_textField removeObserver:self forKeyPath:@"selectedTextRange"];
}
- (id<RCTBackedTextInputViewProtocol>)backedTextInputView
{
return _textField;
}
- (void)sendKeyValueForString:(NSString *)string
{
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeKeyPress
@@ -33,12 +33,17 @@ - (UIView *)view
return [[RCTTextField alloc] initWithBridge:self.bridge];
}
#pragma mark - Unified <TextInput> properties
RCT_REMAP_VIEW_PROPERTY(placeholder, backedTextInputView.placeholder, NSString)
RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, backedTextInputView.placeholderColor, UIColor)
#pragma mark - Singleline <TextInput> (aka TextField) specific properties
RCT_REMAP_VIEW_PROPERTY(caretHidden, textField.caretHidden, BOOL)
RCT_REMAP_VIEW_PROPERTY(autoCorrect, textField.autocorrectionType, UITextAutocorrectionType)
RCT_REMAP_VIEW_PROPERTY(spellCheck, textField.spellCheckingType, UITextSpellCheckingType)
RCT_REMAP_VIEW_PROPERTY(editable, textField.enabled, BOOL)
RCT_REMAP_VIEW_PROPERTY(placeholder, textField.placeholder, NSString)
RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, textField.placeholderColor, UIColor)
RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection)
RCT_EXPORT_VIEW_PROPERTY(text, NSString)
RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber)
@@ -9,13 +9,16 @@
#import <UIKit/UIKit.h>
#import <RCTText/RCTBackedTextInputViewProtocol.h>
#import <React/RCTView.h>
#import <React/UIView+React.h>
@class RCTBridge;
@interface RCTTextView : RCTView <UITextViewDelegate>
@property (nonatomic, readonly) id<RCTBackedTextInputViewProtocol> backedTextInputView;
@property (nonatomic, assign) UITextAutocorrectionType autocorrectionType;
@property (nonatomic, assign) UITextSpellCheckingType spellCheckingType;
@property (nonatomic, assign) BOOL blurOnSubmit;
@@ -68,6 +68,11 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
- (id<RCTBackedTextInputViewProtocol>)backedTextInputView
{
return _textView;
}
#pragma mark - RCTComponent
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)index
@@ -271,27 +276,6 @@ - (void)setText:(NSString *)text
}
}
- (NSString *)placeholder
{
return _textView.placeholder;
}
- (void)setPlaceholder:(NSString *)placeholder
{
_textView.placeholder = placeholder;
[self setNeedsLayout];
}
- (UIColor *)placeholderColor
{
return _textView.placeholderColor;
}
- (void)setPlaceholderColor:(UIColor *)placeholderColor
{
_textView.placeholderColor = placeholderColor;
}
- (void)setAutocorrectionType:(UITextAutocorrectionType)autocorrectionType
{
_textView.autocorrectionType = autocorrectionType;
@@ -33,6 +33,13 @@ - (UIView *)view
return [[RCTTextView alloc] initWithBridge:self.bridge];
}
#pragma mark - Unified <TextInput> properties
RCT_REMAP_VIEW_PROPERTY(placeholder, backedTextInputView.placeholder, NSString)
RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, backedTextInputView.placeholderColor, UIColor)
#pragma mark - Multiline <TextInput> (aka TextView) specific properties
RCT_REMAP_VIEW_PROPERTY(autoCapitalize, textView.autocapitalizationType, UITextAutocapitalizationType)
RCT_REMAP_VIEW_PROPERTY(autoCorrect, autocorrectionType, UITextAutocorrectionType)
RCT_REMAP_VIEW_PROPERTY(spellCheck, spellCheckingType, UITextSpellCheckingType)
@@ -50,8 +57,6 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onTextInput, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(placeholder, NSString)
RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, placeholderColor, UIColor)
RCT_REMAP_VIEW_PROPERTY(returnKeyType, textView.returnKeyType, UIReturnKeyType)
RCT_REMAP_VIEW_PROPERTY(secureTextEntry, textView.secureTextEntry, BOOL)
RCT_REMAP_VIEW_PROPERTY(selectionColor, tintColor, UIColor)
@@ -9,12 +9,14 @@
#import <UIKit/UIKit.h>
#import <RCTText/RCTBackedTextInputViewProtocol.h>
NS_ASSUME_NONNULL_BEGIN
/*
* Just regular UITextField... but much better!
*/
@interface RCTUITextField : UITextField
@interface RCTUITextField : UITextField <RCTBackedTextInputViewProtocol>
- (instancetype)initWithCoder:(NSCoder *)decoder NS_UNAVAILABLE;
@@ -9,12 +9,14 @@
#import <UIKit/UIKit.h>
#import <RCTText/RCTBackedTextInputViewProtocol.h>
NS_ASSUME_NONNULL_BEGIN
/*
* Just regular UITextView... but much better!
*/
@interface RCTUITextView : UITextView
@interface RCTUITextView : UITextView <RCTBackedTextInputViewProtocol>
- (instancetype)initWithFrame:(CGRect)frame textContainer:(nullable NSTextContainer *)textContainer NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE;

0 comments on commit 6ba8e29

Please sign in to comment.