diff --git a/Libraries/Text/RCTText.xcodeproj/project.pbxproj b/Libraries/Text/RCTText.xcodeproj/project.pbxproj index 1d5534a1a..a77407e22 100644 --- a/Libraries/Text/RCTText.xcodeproj/project.pbxproj +++ b/Libraries/Text/RCTText.xcodeproj/project.pbxproj @@ -29,6 +29,10 @@ 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 */; }; + 599DF2641F03076D0079B53E /* RCTTextInput.m in Sources */ = {isa = PBXBuildFile; fileRef = 599DF2631F03076D0079B53E /* RCTTextInput.m */; }; + 599DF2651F03076D0079B53E /* RCTTextInput.m in Sources */ = {isa = PBXBuildFile; fileRef = 599DF2631F03076D0079B53E /* RCTTextInput.m */; }; + 599DF2661F0307D10079B53E /* RCTTextInput.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 599DF2621F03076D0079B53E /* RCTTextInput.h */; }; + 599DF2671F0307D90079B53E /* RCTTextInput.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 599DF2621F03076D0079B53E /* RCTTextInput.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 */; }; @@ -48,6 +52,7 @@ dstPath = include/RCTText; dstSubfolderSpec = 16; files = ( + 599DF2671F0307D90079B53E /* RCTTextInput.h in Copy Headers */, 599DF25F1F0306660079B53E /* RCTBackedTextInputViewProtocol.h in Copy Headers */, ); name = "Copy Headers"; @@ -59,6 +64,7 @@ dstPath = include/RCTText; dstSubfolderSpec = 16; files = ( + 599DF2661F0307D10079B53E /* RCTTextInput.h in Copy Headers */, 599DF2611F0306C30079B53E /* RCTBackedTextInputViewProtocol.h in Copy Headers */, ); name = "Copy Headers"; @@ -90,6 +96,8 @@ 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 = ""; }; + 599DF2621F03076D0079B53E /* RCTTextInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTextInput.h; sourceTree = ""; }; + 599DF2631F03076D0079B53E /* RCTTextInput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTextInput.m; 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 = ""; }; @@ -126,6 +134,8 @@ 1362F0FD1B4D51F400E06D8C /* RCTTextField.m */, 1362F0FE1B4D51F400E06D8C /* RCTTextFieldManager.h */, 1362F0FF1B4D51F400E06D8C /* RCTTextFieldManager.m */, + 599DF2621F03076D0079B53E /* RCTTextInput.h */, + 599DF2631F03076D0079B53E /* RCTTextInput.m */, 58B511CC1A9E6C5C00147676 /* RCTTextManager.h */, 58B511CD1A9E6C5C00147676 /* RCTTextManager.m */, 19FC5C861D41A4220090108F /* RCTTextSelection.h */, @@ -235,6 +245,7 @@ 2D3B5F3B1D9B106F00451313 /* RCTTextView.m in Sources */, 59AF89AB1EDCBCC700F004B1 /* RCTUITextField.m in Sources */, 2D3B5F3A1D9B106F00451313 /* RCTTextFieldManager.m in Sources */, + 599DF2651F03076D0079B53E /* RCTTextInput.m in Sources */, 2D3B5F341D9B103100451313 /* RCTRawTextManager.m in Sources */, 59F60E921E661BDD0081153B /* RCTShadowTextField.m in Sources */, AF3225FA1DE5574F00D3E7E7 /* RCTConvert+Text.m in Sources */, @@ -257,6 +268,7 @@ 1362F1001B4D51F400E06D8C /* RCTTextField.m in Sources */, 59AF89AA1EDCBCC700F004B1 /* RCTUITextField.m in Sources */, 58B512161A9E6EFF00147676 /* RCTText.m in Sources */, + 599DF2641F03076D0079B53E /* RCTTextInput.m in Sources */, 1362F1011B4D51F400E06D8C /* RCTTextFieldManager.m in Sources */, 59F60E911E661BDD0081153B /* RCTShadowTextField.m in Sources */, AF3225F91DE5574F00D3E7E7 /* RCTConvert+Text.m in Sources */, diff --git a/Libraries/Text/RCTTextField.h b/Libraries/Text/RCTTextField.h index 34e0c33cb..6430101da 100644 --- a/Libraries/Text/RCTTextField.h +++ b/Libraries/Text/RCTTextField.h @@ -9,16 +9,13 @@ #import -#import +#import #import #import -@class RCTBridge; @class RCTUITextField; -@interface RCTTextField : RCTView - -@property (nonatomic, readonly) id backedTextInputView; +@interface RCTTextField : RCTTextInput @property (nonatomic, assign) BOOL caretHidden; @property (nonatomic, assign) BOOL selectTextOnFocus; @@ -32,9 +29,4 @@ @property (nonatomic, strong) RCTUITextField *textField; -- (instancetype)initWithBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER; - -- (instancetype)init NS_UNAVAILABLE; -- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE; - @end diff --git a/Libraries/Text/RCTTextField.m b/Libraries/Text/RCTTextField.m index 7d02339b7..b6fd66b87 100644 --- a/Libraries/Text/RCTTextField.m +++ b/Libraries/Text/RCTTextField.m @@ -25,8 +25,6 @@ @implementation RCTTextField { - RCTBridge *_bridge; - RCTEventDispatcher *_eventDispatcher; NSInteger _nativeEventCount; BOOL _submitted; UITextRange *_previousSelectionRange; @@ -36,12 +34,9 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge { - if (self = [super initWithFrame:CGRectZero]) { + if (self = [super initWithBridge:bridge]) { RCTAssertParam(bridge); - _bridge = bridge; - _eventDispatcher = bridge.eventDispatcher; - // `blurOnSubmit` defaults to `true` for by design. _blurOnSubmit = YES; @@ -365,28 +360,4 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) eventCount:_nativeEventCount]; } -#pragma mark - Accessibility - -- (UIView *)reactAccessibilityElement -{ - return _textField; -} - -#pragma mark - Focus control deledation - -- (void)reactFocus -{ - [_textField reactFocus]; -} - -- (void)reactBlur -{ - [_textField reactBlur]; -} - -- (void)didMoveToWindow -{ - [_textField reactFocusIfNeeded]; -} - @end diff --git a/Libraries/Text/RCTTextInput.h b/Libraries/Text/RCTTextInput.h new file mode 100644 index 000000000..50c59f61c --- /dev/null +++ b/Libraries/Text/RCTTextInput.h @@ -0,0 +1,32 @@ +/** + * 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 + +#import +#import + +@class RCTBridge; +@class RCTEventDispatcher; + +@interface RCTTextInput : RCTView { +@protected + RCTBridge *_bridge; + RCTEventDispatcher *_eventDispatcher; +} + +- (instancetype)initWithBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER; + +- (instancetype)init NS_UNAVAILABLE; +- (instancetype)initWithCoder:(NSCoder *)decoder NS_UNAVAILABLE; +- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE; + +@property (nonatomic, readonly) UIView *backedTextInputView; + +@end diff --git a/Libraries/Text/RCTTextInput.m b/Libraries/Text/RCTTextInput.m new file mode 100644 index 000000000..8d8e1d706 --- /dev/null +++ b/Libraries/Text/RCTTextInput.m @@ -0,0 +1,66 @@ +/** + * 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 "RCTTextInput.h" + +#import +#import +#import +#import +#import + +@implementation RCTTextInput + +- (instancetype)initWithBridge:(RCTBridge *)bridge +{ + RCTAssertParam(bridge); + + if (self = [super initWithFrame:CGRectZero]) { + _bridge = bridge; + _eventDispatcher = bridge.eventDispatcher; + } + + return self; +} + +RCT_NOT_IMPLEMENTED(- (instancetype)init) +RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)decoder) +RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) + +- (id)backedTextInputView +{ + RCTAssert(NO, @"-[RCTTextInput backedTextInputView] must be implemented in subclass."); + return nil; +} + +#pragma mark - Accessibility + +- (UIView *)reactAccessibleView +{ + return self.backedTextInputView; +} + +#pragma mark - Focus Control + +- (void)reactFocus +{ + [self.backedTextInputView reactFocus]; +} + +- (void)reactBlur +{ + [self.backedTextInputView reactBlur]; +} + +- (void)didMoveToWindow +{ + [self.backedTextInputView reactFocusIfNeeded]; +} + +@end diff --git a/Libraries/Text/RCTTextView.h b/Libraries/Text/RCTTextView.h index f6e2739d4..eb0a97131 100644 --- a/Libraries/Text/RCTTextView.h +++ b/Libraries/Text/RCTTextView.h @@ -9,15 +9,13 @@ #import -#import +#import #import #import @class RCTBridge; -@interface RCTTextView : RCTView - -@property (nonatomic, readonly) id backedTextInputView; +@interface RCTTextView : RCTTextInput @property (nonatomic, assign) UITextAutocorrectionType autocorrectionType; @property (nonatomic, assign) UITextSpellCheckingType spellCheckingType; @@ -41,8 +39,6 @@ @property (nonatomic, copy) RCTDirectEventBlock onTextInput; @property (nonatomic, copy) RCTDirectEventBlock onScroll; -- (instancetype)initWithBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER; - - (void)performTextUpdate; @end diff --git a/Libraries/Text/RCTTextView.m b/Libraries/Text/RCTTextView.m index e75f5a939..286c40964 100644 --- a/Libraries/Text/RCTTextView.m +++ b/Libraries/Text/RCTTextView.m @@ -22,9 +22,6 @@ @implementation RCTTextView { - RCTBridge *_bridge; - RCTEventDispatcher *_eventDispatcher; - RCTUITextView *_textView; RCTText *_richTextView; NSAttributedString *_pendingAttributedText; @@ -43,9 +40,7 @@ { RCTAssertParam(bridge); - if (self = [super initWithFrame:CGRectZero]) { - _bridge = bridge; - _eventDispatcher = bridge.eventDispatcher; + if (self = [super initWithBridge:bridge]) { _blurOnSubmit = NO; _textView = [[RCTUITextView alloc] initWithFrame:self.bounds]; @@ -514,30 +509,6 @@ static BOOL findMismatch(NSString *first, NSString *second, NSRange *firstRange, eventCount:_nativeEventCount]; } -#pragma mark - Accessibility - -- (UIView *)reactAccessibilityElement -{ - return _textView; -} - -#pragma mark - Focus control deledation - -- (void)reactFocus -{ - [_textView reactFocus]; -} - -- (void)reactBlur -{ - [_textView reactBlur]; -} - -- (void)didMoveToWindow -{ - [_textView reactFocusIfNeeded]; -} - #pragma mark - Content Size (in Yoga terms, without any insets) - (CGSize)contentSize