diff --git a/Libraries/Text/RCTBackedTextInputViewProtocol.h b/Libraries/Text/RCTBackedTextInputViewProtocol.h new file mode 100644 index 000000000..074686120 --- /dev/null +++ b/Libraries/Text/RCTBackedTextInputViewProtocol.h @@ -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 + +@protocol RCTBackedTextInputViewProtocol + +@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 diff --git a/Libraries/Text/RCTText.xcodeproj/project.pbxproj b/Libraries/Text/RCTText.xcodeproj/project.pbxproj index 926488983..1d5534a1a 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 */; }; + 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 = ""; }; 131B6ABD1AF0CD0600FFC3E0 /* RCTTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTextView.m; sourceTree = ""; }; @@ -62,6 +89,7 @@ 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 = ""; }; + 599DF25D1F0304B30079B53E /* RCTBackedTextInputViewProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTBackedTextInputViewProtocol.h; sourceTree = ""; }; 59AF89A81EDCBCC700F004B1 /* RCTUITextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTUITextField.h; sourceTree = ""; }; 59AF89A91EDCBCC700F004B1 /* RCTUITextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTUITextField.m; sourceTree = ""; }; 59B125C71E6E4E15004E2A67 /* RCTUITextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTUITextView.h; sourceTree = ""; }; @@ -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 = ( diff --git a/Libraries/Text/RCTTextField.h b/Libraries/Text/RCTTextField.h index 27fd5cf2c..34e0c33cb 100644 --- a/Libraries/Text/RCTTextField.h +++ b/Libraries/Text/RCTTextField.h @@ -9,6 +9,7 @@ #import +#import #import #import @@ -17,6 +18,8 @@ @interface RCTTextField : RCTView +@property (nonatomic, readonly) id backedTextInputView; + @property (nonatomic, assign) BOOL caretHidden; @property (nonatomic, assign) BOOL selectTextOnFocus; @property (nonatomic, assign) BOOL blurOnSubmit; diff --git a/Libraries/Text/RCTTextField.m b/Libraries/Text/RCTTextField.m index 0fde9f4da..7d02339b7 100644 --- a/Libraries/Text/RCTTextField.m +++ b/Libraries/Text/RCTTextField.m @@ -76,6 +76,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) [_textField removeObserver:self forKeyPath:@"selectedTextRange"]; } +- (id)backedTextInputView +{ + return _textField; +} + - (void)sendKeyValueForString:(NSString *)string { [_eventDispatcher sendTextEventWithType:RCTTextEventTypeKeyPress diff --git a/Libraries/Text/RCTTextFieldManager.m b/Libraries/Text/RCTTextFieldManager.m index 104882c57..88019f125 100644 --- a/Libraries/Text/RCTTextFieldManager.m +++ b/Libraries/Text/RCTTextFieldManager.m @@ -33,12 +33,17 @@ RCT_EXPORT_MODULE() return [[RCTTextField alloc] initWithBridge:self.bridge]; } +#pragma mark - Unified properties + +RCT_REMAP_VIEW_PROPERTY(placeholder, backedTextInputView.placeholder, NSString) +RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, backedTextInputView.placeholderColor, UIColor) + +#pragma mark - Singleline (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) diff --git a/Libraries/Text/RCTTextView.h b/Libraries/Text/RCTTextView.h index 75767f501..f6e2739d4 100644 --- a/Libraries/Text/RCTTextView.h +++ b/Libraries/Text/RCTTextView.h @@ -9,6 +9,7 @@ #import +#import #import #import @@ -16,6 +17,8 @@ @interface RCTTextView : RCTView +@property (nonatomic, readonly) id backedTextInputView; + @property (nonatomic, assign) UITextAutocorrectionType autocorrectionType; @property (nonatomic, assign) UITextSpellCheckingType spellCheckingType; @property (nonatomic, assign) BOOL blurOnSubmit; diff --git a/Libraries/Text/RCTTextView.m b/Libraries/Text/RCTTextView.m index d53125e87..e75f5a939 100644 --- a/Libraries/Text/RCTTextView.m +++ b/Libraries/Text/RCTTextView.m @@ -68,6 +68,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) +- (id)backedTextInputView +{ + return _textView; +} + #pragma mark - RCTComponent - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)index @@ -271,27 +276,6 @@ static NSAttributedString *removeReactTagFromString(NSAttributedString *string) } } -- (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; diff --git a/Libraries/Text/RCTTextViewManager.m b/Libraries/Text/RCTTextViewManager.m index 0dec7c5a4..f781a6e2b 100644 --- a/Libraries/Text/RCTTextViewManager.m +++ b/Libraries/Text/RCTTextViewManager.m @@ -33,6 +33,13 @@ RCT_EXPORT_MODULE() return [[RCTTextView alloc] initWithBridge:self.bridge]; } +#pragma mark - Unified properties + +RCT_REMAP_VIEW_PROPERTY(placeholder, backedTextInputView.placeholder, NSString) +RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, backedTextInputView.placeholderColor, UIColor) + +#pragma mark - Multiline (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 @@ RCT_EXPORT_VIEW_PROPERTY(onContentSizeChange, RCTBubblingEventBlock) 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) diff --git a/Libraries/Text/RCTUITextField.h b/Libraries/Text/RCTUITextField.h index f4f5b2ceb..9dfbd39fc 100644 --- a/Libraries/Text/RCTUITextField.h +++ b/Libraries/Text/RCTUITextField.h @@ -9,12 +9,14 @@ #import +#import + NS_ASSUME_NONNULL_BEGIN /* * Just regular UITextField... but much better! */ -@interface RCTUITextField : UITextField +@interface RCTUITextField : UITextField - (instancetype)initWithCoder:(NSCoder *)decoder NS_UNAVAILABLE; diff --git a/Libraries/Text/RCTUITextView.h b/Libraries/Text/RCTUITextView.h index b8388df26..dc15a8ef3 100644 --- a/Libraries/Text/RCTUITextView.h +++ b/Libraries/Text/RCTUITextView.h @@ -9,12 +9,14 @@ #import +#import + NS_ASSUME_NONNULL_BEGIN /* * Just regular UITextView... but much better! */ -@interface RCTUITextView : UITextView +@interface RCTUITextView : UITextView - (instancetype)initWithFrame:(CGRect)frame textContainer:(nullable NSTextContainer *)textContainer NS_UNAVAILABLE; - (instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE;