Skip to content

Commit

Permalink
Introducting RCTTextInput, base class for both text inputs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shergin authored and facebook-github-bot committed Jun 27, 2017
1 parent 6ba8e29 commit 3364488
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 76 deletions.
12 changes: 12 additions & 0 deletions Libraries/Text/RCTText.xcodeproj/project.pbxproj
Expand Up @@ -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 */; };
Expand All @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -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>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand Down
12 changes: 2 additions & 10 deletions Libraries/Text/RCTTextField.h
Expand Up @@ -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;
Expand All @@ -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
31 changes: 1 addition & 30 deletions Libraries/Text/RCTTextField.m
Expand Up @@ -25,8 +25,6 @@ @interface RCTTextField () <UITextFieldDelegate>

@implementation RCTTextField
{
RCTBridge *_bridge;
RCTEventDispatcher *_eventDispatcher;
NSInteger _nativeEventCount;
BOOL _submitted;
UITextRange *_previousSelectionRange;
Expand All @@ -36,12 +34,9 @@ @implementation RCTTextField

- (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;

Expand Down Expand Up @@ -365,28 +360,4 @@ - (void)textFieldDidEndEditing:(UITextField *)textField
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
32 changes: 32 additions & 0 deletions 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 <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
66 changes: 66 additions & 0 deletions 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 <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
8 changes: 2 additions & 6 deletions Libraries/Text/RCTTextView.h
Expand Up @@ -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;
Expand All @@ -41,8 +39,6 @@
@property (nonatomic, copy) RCTDirectEventBlock onTextInput;
@property (nonatomic, copy) RCTDirectEventBlock onScroll;

- (instancetype)initWithBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;

- (void)performTextUpdate;

@end
31 changes: 1 addition & 30 deletions Libraries/Text/RCTTextView.m
Expand Up @@ -22,9 +22,6 @@

@implementation RCTTextView
{
RCTBridge *_bridge;
RCTEventDispatcher *_eventDispatcher;

RCTUITextView *_textView;
RCTText *_richTextView;
NSAttributedString *_pendingAttributedText;
Expand All @@ -43,9 +40,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
{
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];
Expand Down Expand Up @@ -514,30 +509,6 @@ - (void)textViewDidEndEditing:(UITextView *)textView
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
Expand Down

0 comments on commit 3364488

Please sign in to comment.