2015-04-29 08:29:00 +00:00
|
|
|
/**
|
|
|
|
* 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 "RCTTextView.h"
|
|
|
|
|
|
|
|
#import "RCTConvert.h"
|
|
|
|
#import "RCTEventDispatcher.h"
|
2015-11-06 15:25:19 +00:00
|
|
|
#import "RCTText.h"
|
2015-04-29 08:29:00 +00:00
|
|
|
#import "RCTUtils.h"
|
|
|
|
#import "UIView+React.h"
|
|
|
|
|
2015-11-02 17:13:41 +00:00
|
|
|
@interface RCTUITextView : UITextView
|
|
|
|
|
|
|
|
@property (nonatomic, assign) BOOL textWasPasted;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RCTUITextView
|
2015-11-27 14:52:29 +00:00
|
|
|
{
|
|
|
|
BOOL _jsRequestingFirstResponder;
|
|
|
|
}
|
2015-11-02 17:13:41 +00:00
|
|
|
|
|
|
|
- (void)paste:(id)sender
|
|
|
|
{
|
|
|
|
_textWasPasted = YES;
|
|
|
|
[super paste:sender];
|
|
|
|
}
|
|
|
|
|
2015-11-27 14:52:29 +00:00
|
|
|
- (void)reactWillMakeFirstResponder
|
|
|
|
{
|
|
|
|
_jsRequestingFirstResponder = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)canBecomeFirstResponder
|
|
|
|
{
|
|
|
|
return _jsRequestingFirstResponder;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)reactDidMakeFirstResponder
|
|
|
|
{
|
|
|
|
_jsRequestingFirstResponder = NO;
|
|
|
|
}
|
|
|
|
|
2015-11-02 17:13:41 +00:00
|
|
|
@end
|
|
|
|
|
2015-04-29 08:29:00 +00:00
|
|
|
@implementation RCTTextView
|
|
|
|
{
|
|
|
|
RCTEventDispatcher *_eventDispatcher;
|
|
|
|
NSString *_placeholder;
|
|
|
|
UITextView *_placeholderView;
|
|
|
|
UITextView *_textView;
|
2015-07-21 19:37:24 +00:00
|
|
|
NSInteger _nativeEventCount;
|
2015-11-06 15:25:19 +00:00
|
|
|
RCTText *_richTextView;
|
|
|
|
NSAttributedString *_pendingAttributedText;
|
2015-11-14 18:25:00 +00:00
|
|
|
NSMutableArray<UIView *> *_subviews;
|
2015-11-06 15:25:19 +00:00
|
|
|
BOOL _blockTextShouldChange;
|
2015-11-14 17:41:59 +00:00
|
|
|
UITextRange *_previousSelectionRange;
|
2015-11-24 22:26:14 +00:00
|
|
|
UIScrollView *_scrollView;
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
|
|
|
|
{
|
2015-06-15 14:53:45 +00:00
|
|
|
RCTAssertParam(eventDispatcher);
|
|
|
|
|
2015-04-29 08:29:00 +00:00
|
|
|
if ((self = [super initWithFrame:CGRectZero])) {
|
|
|
|
_contentInset = UIEdgeInsetsZero;
|
|
|
|
_eventDispatcher = eventDispatcher;
|
|
|
|
_placeholderTextColor = [self defaultPlaceholderTextColor];
|
2015-12-02 15:11:20 +00:00
|
|
|
_blurOnSubmit = NO;
|
2015-04-29 08:29:00 +00:00
|
|
|
|
2015-11-24 22:26:14 +00:00
|
|
|
_textView = [[RCTUITextView alloc] initWithFrame:CGRectZero];
|
2015-04-29 08:29:00 +00:00
|
|
|
_textView.backgroundColor = [UIColor clearColor];
|
2015-09-01 10:23:29 +00:00
|
|
|
_textView.scrollsToTop = NO;
|
2015-11-24 22:26:14 +00:00
|
|
|
_textView.scrollEnabled = NO;
|
2015-04-29 08:29:00 +00:00
|
|
|
_textView.delegate = self;
|
2015-11-06 15:25:19 +00:00
|
|
|
|
2015-11-24 22:26:14 +00:00
|
|
|
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
|
2015-12-04 14:59:14 +00:00
|
|
|
_scrollView.scrollsToTop = NO;
|
2015-11-24 22:26:14 +00:00
|
|
|
[_scrollView addSubview:_textView];
|
|
|
|
|
2015-11-14 17:41:59 +00:00
|
|
|
_previousSelectionRange = _textView.selectedTextRange;
|
|
|
|
|
2015-11-06 15:25:19 +00:00
|
|
|
_subviews = [NSMutableArray new];
|
2015-11-24 22:26:14 +00:00
|
|
|
[self addSubview:_scrollView];
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-08-24 10:14:33 +00:00
|
|
|
RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
|
|
|
|
RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
2015-06-15 14:53:45 +00:00
|
|
|
|
2015-11-14 18:25:00 +00:00
|
|
|
- (NSArray<UIView *> *)reactSubviews
|
2015-11-06 15:25:19 +00:00
|
|
|
{
|
|
|
|
return _subviews;
|
|
|
|
}
|
|
|
|
|
2015-11-14 18:25:00 +00:00
|
|
|
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)index
|
2015-11-06 15:25:19 +00:00
|
|
|
{
|
|
|
|
if ([subview isKindOfClass:[RCTText class]]) {
|
|
|
|
if (_richTextView) {
|
|
|
|
RCTLogError(@"Tried to insert a second <Text> into <TextInput> - there can only be one.");
|
|
|
|
}
|
|
|
|
_richTextView = (RCTText *)subview;
|
|
|
|
[_subviews insertObject:_richTextView atIndex:index];
|
|
|
|
} else {
|
|
|
|
[_subviews insertObject:subview atIndex:index];
|
|
|
|
[self insertSubview:subview atIndex:index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-14 18:25:00 +00:00
|
|
|
- (void)removeReactSubview:(UIView *)subview
|
2015-11-06 15:25:19 +00:00
|
|
|
{
|
|
|
|
if (_richTextView == subview) {
|
|
|
|
[_subviews removeObject:_richTextView];
|
|
|
|
_richTextView = nil;
|
|
|
|
} else {
|
|
|
|
[_subviews removeObject:subview];
|
|
|
|
[subview removeFromSuperview];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setMostRecentEventCount:(NSInteger)mostRecentEventCount
|
|
|
|
{
|
|
|
|
_mostRecentEventCount = mostRecentEventCount;
|
|
|
|
|
|
|
|
// Props are set after uiBlockToAmendWithShadowViewRegistry, which means that
|
|
|
|
// at the time performTextUpdate is called, _mostRecentEventCount will be
|
|
|
|
// behind _eventCount, with the result that performPendingTextUpdate will do
|
|
|
|
// nothing. For that reason we call it again here after mostRecentEventCount
|
|
|
|
// has been set.
|
|
|
|
[self performPendingTextUpdate];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)performTextUpdate
|
|
|
|
{
|
|
|
|
if (_richTextView) {
|
|
|
|
_pendingAttributedText = _richTextView.textStorage;
|
|
|
|
[self performPendingTextUpdate];
|
|
|
|
} else if (!self.text) {
|
|
|
|
_textView.attributedText = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)performPendingTextUpdate
|
|
|
|
{
|
|
|
|
if (!_pendingAttributedText || _mostRecentEventCount < _nativeEventCount) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([_textView.attributedText isEqualToAttributedString:_pendingAttributedText]) {
|
|
|
|
_pendingAttributedText = nil; // Don't try again.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When we update the attributed text, there might be pending autocorrections
|
|
|
|
// that will get accepted by default. In order for this to not garble our text,
|
|
|
|
// we temporarily block all textShouldChange events so they are not applied.
|
|
|
|
_blockTextShouldChange = YES;
|
|
|
|
|
2015-12-17 18:22:56 +00:00
|
|
|
UITextRange *selection = _textView.selectedTextRange;
|
|
|
|
NSInteger oldTextLength = _textView.attributedText.length;
|
|
|
|
|
2015-11-06 15:25:19 +00:00
|
|
|
_textView.attributedText = _pendingAttributedText;
|
|
|
|
_pendingAttributedText = nil;
|
2015-12-17 18:22:56 +00:00
|
|
|
|
|
|
|
if (selection.empty) {
|
|
|
|
// maintain cursor position relative to the end of the old text
|
|
|
|
NSInteger start = [_textView offsetFromPosition:_textView.beginningOfDocument toPosition:selection.start];
|
|
|
|
NSInteger offsetFromEnd = oldTextLength - start;
|
|
|
|
NSInteger newOffset = _textView.attributedText.length - offsetFromEnd;
|
|
|
|
UITextPosition *position = [_textView positionFromPosition:_textView.beginningOfDocument offset:newOffset];
|
|
|
|
_textView.selectedTextRange = [_textView textRangeFromPosition:position toPosition:position];
|
|
|
|
}
|
|
|
|
|
2015-11-06 15:25:19 +00:00
|
|
|
[_textView layoutIfNeeded];
|
|
|
|
|
|
|
|
[self _setPlaceholderVisibility];
|
|
|
|
|
|
|
|
_blockTextShouldChange = NO;
|
|
|
|
}
|
|
|
|
|
2015-04-29 08:29:00 +00:00
|
|
|
- (void)updateFrames
|
|
|
|
{
|
|
|
|
// Adjust the insets so that they are as close as possible to single-line
|
2015-08-12 22:24:59 +00:00
|
|
|
// RCTTextField defaults, using the system defaults of font size 17 and a
|
|
|
|
// height of 31 points.
|
|
|
|
//
|
|
|
|
// We apply the left inset to the frame since a negative left text-container
|
|
|
|
// inset mysteriously causes the text to be hidden until the text view is
|
|
|
|
// first focused.
|
|
|
|
UIEdgeInsets adjustedFrameInset = UIEdgeInsetsZero;
|
|
|
|
adjustedFrameInset.left = _contentInset.left - 5;
|
2015-11-02 17:13:41 +00:00
|
|
|
|
2015-08-12 22:24:59 +00:00
|
|
|
UIEdgeInsets adjustedTextContainerInset = _contentInset;
|
|
|
|
adjustedTextContainerInset.top += 5;
|
|
|
|
adjustedTextContainerInset.left = 0;
|
2015-11-02 17:13:41 +00:00
|
|
|
|
2015-08-12 22:24:59 +00:00
|
|
|
CGRect frame = UIEdgeInsetsInsetRect(self.bounds, adjustedFrameInset);
|
|
|
|
_textView.frame = frame;
|
|
|
|
_placeholderView.frame = frame;
|
2015-11-24 22:26:14 +00:00
|
|
|
_scrollView.frame = frame;
|
|
|
|
[self updateContentSize];
|
2015-11-02 17:13:41 +00:00
|
|
|
|
2015-08-12 22:24:59 +00:00
|
|
|
_textView.textContainerInset = adjustedTextContainerInset;
|
|
|
|
_placeholderView.textContainerInset = adjustedTextContainerInset;
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 22:26:14 +00:00
|
|
|
- (void)updateContentSize
|
|
|
|
{
|
2015-12-02 17:33:50 +00:00
|
|
|
CGSize size = (CGSize){_scrollView.frame.size.width, INFINITY};
|
|
|
|
size.height = [_textView sizeThatFits:size].height;
|
|
|
|
_scrollView.contentSize = size;
|
|
|
|
_textView.frame = (CGRect){CGPointZero, size};
|
2015-11-24 22:26:14 +00:00
|
|
|
}
|
|
|
|
|
2015-04-29 08:29:00 +00:00
|
|
|
- (void)updatePlaceholder
|
|
|
|
{
|
|
|
|
[_placeholderView removeFromSuperview];
|
|
|
|
_placeholderView = nil;
|
|
|
|
|
|
|
|
if (_placeholder) {
|
|
|
|
_placeholderView = [[UITextView alloc] initWithFrame:self.bounds];
|
2015-11-24 22:26:14 +00:00
|
|
|
_placeholderView.editable = NO;
|
|
|
|
_placeholderView.userInteractionEnabled = NO;
|
2015-04-29 08:29:00 +00:00
|
|
|
_placeholderView.backgroundColor = [UIColor clearColor];
|
|
|
|
_placeholderView.scrollEnabled = false;
|
2015-10-02 17:14:41 +00:00
|
|
|
_placeholderView.scrollsToTop = NO;
|
2015-04-29 08:29:00 +00:00
|
|
|
_placeholderView.attributedText =
|
|
|
|
[[NSAttributedString alloc] initWithString:_placeholder attributes:@{
|
|
|
|
NSFontAttributeName : (_textView.font ? _textView.font : [self defaultPlaceholderFont]),
|
|
|
|
NSForegroundColorAttributeName : _placeholderTextColor
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self insertSubview:_placeholderView belowSubview:_textView];
|
|
|
|
[self _setPlaceholderVisibility];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-14 16:37:39 +00:00
|
|
|
- (UIFont *)font
|
|
|
|
{
|
|
|
|
return _textView.font;
|
|
|
|
}
|
|
|
|
|
2015-04-29 08:29:00 +00:00
|
|
|
- (void)setFont:(UIFont *)font
|
|
|
|
{
|
2015-05-14 16:37:39 +00:00
|
|
|
_textView.font = font;
|
2015-04-29 08:29:00 +00:00
|
|
|
[self updatePlaceholder];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setPlaceholder:(NSString *)placeholder
|
|
|
|
{
|
|
|
|
_placeholder = placeholder;
|
|
|
|
[self updatePlaceholder];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setPlaceholderTextColor:(UIColor *)placeholderTextColor
|
|
|
|
{
|
|
|
|
if (placeholderTextColor) {
|
|
|
|
_placeholderTextColor = placeholderTextColor;
|
|
|
|
} else {
|
|
|
|
_placeholderTextColor = [self defaultPlaceholderTextColor];
|
|
|
|
}
|
|
|
|
[self updatePlaceholder];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setContentInset:(UIEdgeInsets)contentInset
|
|
|
|
{
|
|
|
|
_contentInset = contentInset;
|
|
|
|
[self updateFrames];
|
|
|
|
}
|
|
|
|
|
2015-05-14 16:37:39 +00:00
|
|
|
- (NSString *)text
|
|
|
|
{
|
|
|
|
return _textView.text;
|
|
|
|
}
|
|
|
|
|
2015-11-02 17:13:41 +00:00
|
|
|
- (BOOL)textView:(RCTUITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
|
2015-07-21 19:37:24 +00:00
|
|
|
{
|
2015-11-06 15:25:19 +00:00
|
|
|
if (_blockTextShouldChange) {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2015-11-02 17:13:41 +00:00
|
|
|
if (textView.textWasPasted) {
|
|
|
|
textView.textWasPasted = NO;
|
|
|
|
} else {
|
2015-12-02 15:11:20 +00:00
|
|
|
|
2015-11-02 17:13:41 +00:00
|
|
|
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeKeyPress
|
|
|
|
reactTag:self.reactTag
|
|
|
|
text:nil
|
|
|
|
key:text
|
|
|
|
eventCount:_nativeEventCount];
|
2015-12-02 15:11:20 +00:00
|
|
|
|
|
|
|
if (_blurOnSubmit && [text isEqualToString:@"\n"]) {
|
|
|
|
|
|
|
|
// TODO: the purpose of blurOnSubmit on RCTextField is to decide if the
|
|
|
|
// field should lose focus when return is pressed or not. We're cheating a
|
|
|
|
// bit here by using it on RCTextView to decide if return character should
|
|
|
|
// submit the form, or be entered into the field.
|
|
|
|
//
|
|
|
|
// The reason this is cheating is because there's no way to specify that
|
|
|
|
// you want the return key to be swallowed *and* have the field retain
|
|
|
|
// focus (which was what blurOnSubmit was originally for). For the case
|
|
|
|
// where _blurOnSubmit = YES, this is still the correct and expected
|
|
|
|
// behavior though, so we'll leave the don't-blur-or-add-newline problem
|
|
|
|
// to be solved another day.
|
|
|
|
|
|
|
|
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeSubmit
|
|
|
|
reactTag:self.reactTag
|
|
|
|
text:self.text
|
|
|
|
key:nil
|
|
|
|
eventCount:_nativeEventCount];
|
|
|
|
[self resignFirstResponder];
|
|
|
|
return NO;
|
|
|
|
}
|
2015-11-02 17:13:41 +00:00
|
|
|
}
|
|
|
|
|
2015-07-21 19:37:24 +00:00
|
|
|
if (_maxLength == nil) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
NSUInteger allowedLength = _maxLength.integerValue - textView.text.length + range.length;
|
|
|
|
if (text.length > allowedLength) {
|
|
|
|
if (text.length > 1) {
|
|
|
|
// Truncate the input string so the result is exactly maxLength
|
|
|
|
NSString *limitedString = [text substringToIndex:allowedLength];
|
|
|
|
NSMutableString *newString = textView.text.mutableCopy;
|
|
|
|
[newString replaceCharactersInRange:range withString:limitedString];
|
|
|
|
textView.text = newString;
|
|
|
|
// Collapse selection at end of insert to match normal paste behavior
|
|
|
|
UITextPosition *insertEnd = [textView positionFromPosition:textView.beginningOfDocument
|
|
|
|
offset:(range.location + allowedLength)];
|
|
|
|
textView.selectedTextRange = [textView textRangeFromPosition:insertEnd toPosition:insertEnd];
|
|
|
|
[self textViewDidChange:textView];
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
} else {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-14 17:41:59 +00:00
|
|
|
- (void)textViewDidChangeSelection:(RCTUITextView *)textView
|
|
|
|
{
|
|
|
|
if (_onSelectionChange &&
|
|
|
|
textView.selectedTextRange != _previousSelectionRange &&
|
|
|
|
![textView.selectedTextRange isEqual:_previousSelectionRange]) {
|
|
|
|
|
|
|
|
_previousSelectionRange = textView.selectedTextRange;
|
|
|
|
|
|
|
|
UITextRange *selection = textView.selectedTextRange;
|
2015-12-17 18:22:56 +00:00
|
|
|
NSInteger start = [textView offsetFromPosition:textView.beginningOfDocument toPosition:selection.start];
|
|
|
|
NSInteger end = [textView offsetFromPosition:textView.beginningOfDocument toPosition:selection.end];
|
2015-11-14 17:41:59 +00:00
|
|
|
_onSelectionChange(@{
|
|
|
|
@"selection": @{
|
|
|
|
@"start": @(start),
|
|
|
|
@"end": @(end),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-29 08:29:00 +00:00
|
|
|
- (void)setText:(NSString *)text
|
|
|
|
{
|
2015-07-21 19:37:24 +00:00
|
|
|
NSInteger eventLag = _nativeEventCount - _mostRecentEventCount;
|
|
|
|
if (eventLag == 0 && ![text isEqualToString:_textView.text]) {
|
|
|
|
UITextRange *selection = _textView.selectedTextRange;
|
2015-12-17 18:22:56 +00:00
|
|
|
NSInteger oldTextLength = _textView.text.length;
|
|
|
|
|
2015-08-24 10:14:33 +00:00
|
|
|
_textView.text = text;
|
2015-12-17 18:22:56 +00:00
|
|
|
|
|
|
|
if (selection.empty) {
|
|
|
|
// maintain cursor position relative to the end of the old text
|
|
|
|
NSInteger start = [_textView offsetFromPosition:_textView.beginningOfDocument toPosition:selection.start];
|
|
|
|
NSInteger offsetFromEnd = oldTextLength - start;
|
|
|
|
NSInteger newOffset = text.length - offsetFromEnd;
|
|
|
|
UITextPosition *position = [_textView positionFromPosition:_textView.beginningOfDocument offset:newOffset];
|
|
|
|
_textView.selectedTextRange = [_textView textRangeFromPosition:position toPosition:position];
|
|
|
|
}
|
|
|
|
|
2015-04-29 08:29:00 +00:00
|
|
|
[self _setPlaceholderVisibility];
|
2016-01-11 11:32:28 +00:00
|
|
|
[self updateContentSize]; //keep the text wrapping when the length of
|
|
|
|
//the textline has been extended longer than the length of textinputView
|
2015-07-21 19:37:24 +00:00
|
|
|
} else if (eventLag > RCTTextUpdateLagWarningThreshold) {
|
2015-08-11 13:37:12 +00:00
|
|
|
RCTLogWarn(@"Native TextInput(%@) is %zd events ahead of JS - try to make your JS faster.", self.text, eventLag);
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)_setPlaceholderVisibility
|
|
|
|
{
|
|
|
|
if (_textView.text.length > 0) {
|
|
|
|
[_placeholderView setHidden:YES];
|
|
|
|
} else {
|
|
|
|
[_placeholderView setHidden:NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAutoCorrect:(BOOL)autoCorrect
|
|
|
|
{
|
|
|
|
_textView.autocorrectionType = (autoCorrect ? UITextAutocorrectionTypeYes : UITextAutocorrectionTypeNo);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)autoCorrect
|
|
|
|
{
|
|
|
|
return _textView.autocorrectionType == UITextAutocorrectionTypeYes;
|
|
|
|
}
|
|
|
|
|
2015-04-29 22:55:36 +00:00
|
|
|
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
|
|
|
|
{
|
|
|
|
if (_selectTextOnFocus) {
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[textView selectAll:nil];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2015-04-29 08:29:00 +00:00
|
|
|
- (void)textViewDidBeginEditing:(UITextView *)textView
|
|
|
|
{
|
2015-04-29 22:55:36 +00:00
|
|
|
if (_clearTextOnFocus) {
|
|
|
|
_textView.text = @"";
|
|
|
|
[self _setPlaceholderVisibility];
|
|
|
|
}
|
|
|
|
|
2015-04-29 08:29:00 +00:00
|
|
|
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeFocus
|
|
|
|
reactTag:self.reactTag
|
2015-11-27 14:52:29 +00:00
|
|
|
text:nil
|
2015-11-02 17:13:41 +00:00
|
|
|
key:nil
|
2015-07-21 19:37:24 +00:00
|
|
|
eventCount:_nativeEventCount];
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)textViewDidChange:(UITextView *)textView
|
|
|
|
{
|
2015-11-24 22:26:14 +00:00
|
|
|
[self updateContentSize];
|
2015-04-29 08:29:00 +00:00
|
|
|
[self _setPlaceholderVisibility];
|
2015-07-21 19:37:24 +00:00
|
|
|
_nativeEventCount++;
|
2015-04-29 08:29:00 +00:00
|
|
|
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeChange
|
|
|
|
reactTag:self.reactTag
|
2015-07-21 19:37:24 +00:00
|
|
|
text:textView.text
|
2015-11-02 17:13:41 +00:00
|
|
|
key:nil
|
2015-07-21 19:37:24 +00:00
|
|
|
eventCount:_nativeEventCount];
|
2015-04-29 08:29:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)textViewDidEndEditing:(UITextView *)textView
|
|
|
|
{
|
|
|
|
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeEnd
|
|
|
|
reactTag:self.reactTag
|
2015-07-21 19:37:24 +00:00
|
|
|
text:textView.text
|
2015-11-02 17:13:41 +00:00
|
|
|
key:nil
|
2015-07-21 19:37:24 +00:00
|
|
|
eventCount:_nativeEventCount];
|
2015-11-27 14:52:29 +00:00
|
|
|
|
|
|
|
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeBlur
|
|
|
|
reactTag:self.reactTag
|
|
|
|
text:nil
|
|
|
|
key:nil
|
|
|
|
eventCount:_nativeEventCount];
|
|
|
|
}
|
|
|
|
|
2015-12-02 15:08:29 +00:00
|
|
|
- (BOOL)isFirstResponder
|
|
|
|
{
|
|
|
|
return [_textView isFirstResponder];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)canBecomeFirstResponder
|
|
|
|
{
|
|
|
|
return [_textView canBecomeFirstResponder];
|
|
|
|
}
|
|
|
|
|
2015-11-27 14:52:29 +00:00
|
|
|
- (void)reactWillMakeFirstResponder
|
|
|
|
{
|
|
|
|
[_textView reactWillMakeFirstResponder];
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)becomeFirstResponder
|
|
|
|
{
|
2015-11-27 14:52:29 +00:00
|
|
|
return [_textView becomeFirstResponder];
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
|
|
|
|
2015-11-27 14:52:29 +00:00
|
|
|
- (void)reactDidMakeFirstResponder
|
2015-04-29 08:29:00 +00:00
|
|
|
{
|
2015-11-27 14:52:29 +00:00
|
|
|
[_textView reactDidMakeFirstResponder];
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
|
|
|
|
2015-11-30 21:37:37 +00:00
|
|
|
- (BOOL)resignFirstResponder
|
|
|
|
{
|
2015-12-02 17:33:50 +00:00
|
|
|
[super resignFirstResponder];
|
|
|
|
return [_textView resignFirstResponder];
|
2015-11-30 21:37:37 +00:00
|
|
|
}
|
|
|
|
|
2015-04-29 08:29:00 +00:00
|
|
|
- (void)layoutSubviews
|
|
|
|
{
|
|
|
|
[super layoutSubviews];
|
|
|
|
[self updateFrames];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIFont *)defaultPlaceholderFont
|
|
|
|
{
|
2015-07-09 23:45:48 +00:00
|
|
|
return [UIFont systemFontOfSize:17];
|
2015-04-29 08:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (UIColor *)defaultPlaceholderTextColor
|
|
|
|
{
|
|
|
|
return [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.098/255.0 alpha:0.22];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|