Introducting RCTTextInput, base class for both text inputs

Summary: Some basic same to both classes functionality was moved to base class, and it is just a beginning.

Reviewed By: mmmulani

Differential Revision: D5144429

fbshipit-source-id: 56c6400d46f4cf3c0058fe936cba524dd5d490df
This commit is contained in:
Valentin Shergin 2017-06-27 16:05:05 -07:00 committed by Facebook Github Bot
parent 6ba8e29c89
commit 3364488af0
7 changed files with 116 additions and 76 deletions

View File

@ -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 = "<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>"; };
599DF2621F03076D0079B53E /* RCTTextInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTextInput.h; sourceTree = "<group>"; };
599DF2631F03076D0079B53E /* RCTTextInput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTextInput.m; 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>"; };
@ -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 */,

View File

@ -9,16 +9,13 @@
#import <UIKit/UIKit.h>
#import <RCTText/RCTBackedTextInputViewProtocol.h>
#import <RCTText/RCTTextInput.h>
#import <React/RCTComponent.h>
#import <React/RCTView.h>
@class RCTBridge;
@class RCTUITextField;
@interface RCTTextField : RCTView
@property (nonatomic, readonly) id<RCTBackedTextInputViewProtocol> 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

View File

@ -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 <TextInput multiline={false}> 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

View File

@ -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 <UIKit/UIKit.h>
#import <RCTText/RCTBackedTextInputViewProtocol.h>
#import <React/RCTView.h>
@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<RCTBackedTextInputViewProtocol> *backedTextInputView;
@end

View File

@ -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 <React/RCTBridge.h>
#import <React/RCTConvert.h>
#import <React/RCTEventDispatcher.h>
#import <React/RCTUtils.h>
#import <React/UIView+React.h>
@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<RCTBackedTextInputViewProtocol>)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

View File

@ -9,15 +9,13 @@
#import <UIKit/UIKit.h>
#import <RCTText/RCTBackedTextInputViewProtocol.h>
#import <RCTText/RCTTextInput.h>
#import <React/RCTView.h>
#import <React/UIView+React.h>
@class RCTBridge;
@interface RCTTextView : RCTView <UITextViewDelegate>
@property (nonatomic, readonly) id<RCTBackedTextInputViewProtocol> backedTextInputView;
@interface RCTTextView : RCTTextInput <UITextViewDelegate>
@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

View File

@ -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