diff --git a/Examples/UIExplorer/TextInputExample.ios.js b/Examples/UIExplorer/TextInputExample.ios.js index 471920a0b..826139048 100644 --- a/Examples/UIExplorer/TextInputExample.ios.js +++ b/Examples/UIExplorer/TextInputExample.ios.js @@ -301,50 +301,6 @@ exports.displayName = (undefined: ?string); exports.title = ''; exports.description = 'Single and multi-line text inputs.'; exports.examples = [ - { - title: 'Multiline', - render: function() { - return ( - - - - - - - - - ); - } - }, - { - title: 'Attributed text', - render: function() { - return ; - } - }, { title: 'Auto-focus', render: function() { @@ -592,4 +548,48 @@ exports.examples = [ title: 'Blur on submit', render: function(): ReactElement { return ; }, }, + { + title: 'Multiline', + render: function() { + return ( + + + + + + + + + ); + } + }, + { + title: 'Attributed text', + render: function() { + return ; + } + }, ]; diff --git a/Libraries/Text/RCTTextField.m b/Libraries/Text/RCTTextField.m index 222d280e1..de4fd867b 100644 --- a/Libraries/Text/RCTTextField.m +++ b/Libraries/Text/RCTTextField.m @@ -239,12 +239,19 @@ static void RCTUpdatePlaceholder(RCTTextField *self) } } -- (BOOL)becomeFirstResponder +- (void)reactWillMakeFirstResponder { _jsRequestingFirstResponder = YES; - BOOL result = [super becomeFirstResponder]; +} + +- (void)reactDidMakeFirstResponder +{ _jsRequestingFirstResponder = NO; - return result; +} + +- (BOOL)canBecomeFirstResponder +{ + return _jsRequestingFirstResponder; } - (BOOL)resignFirstResponder @@ -261,9 +268,4 @@ static void RCTUpdatePlaceholder(RCTTextField *self) return result; } -- (BOOL)canBecomeFirstResponder -{ - return _jsRequestingFirstResponder; -} - @end diff --git a/Libraries/Text/RCTTextView.m b/Libraries/Text/RCTTextView.m index f75a4c013..412dd47ac 100644 --- a/Libraries/Text/RCTTextView.m +++ b/Libraries/Text/RCTTextView.m @@ -22,6 +22,9 @@ @end @implementation RCTUITextView +{ + BOOL _jsRequestingFirstResponder; +} - (void)paste:(id)sender { @@ -29,12 +32,26 @@ [super paste:sender]; } +- (void)reactWillMakeFirstResponder +{ + _jsRequestingFirstResponder = YES; +} + +- (BOOL)canBecomeFirstResponder +{ + return _jsRequestingFirstResponder; +} + +- (void)reactDidMakeFirstResponder +{ + _jsRequestingFirstResponder = NO; +} + @end @implementation RCTTextView { RCTEventDispatcher *_eventDispatcher; - BOOL _jsRequestingFirstResponder; NSString *_placeholder; UITextView *_placeholderView; UITextView *_textView; @@ -360,7 +377,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) [_eventDispatcher sendTextEventWithType:RCTTextEventTypeFocus reactTag:self.reactTag - text:textView.text + text:nil key:nil eventCount:_nativeEventCount]; } @@ -385,28 +402,27 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) text:textView.text key:nil eventCount:_nativeEventCount]; + + [_eventDispatcher sendTextEventWithType:RCTTextEventTypeBlur + reactTag:self.reactTag + text:nil + key:nil + eventCount:_nativeEventCount]; +} + +- (void)reactWillMakeFirstResponder +{ + [_textView reactWillMakeFirstResponder]; } - (BOOL)becomeFirstResponder { - _jsRequestingFirstResponder = YES; - BOOL result = [_textView becomeFirstResponder]; - _jsRequestingFirstResponder = NO; - return result; + return [_textView becomeFirstResponder]; } -- (BOOL)resignFirstResponder +- (void)reactDidMakeFirstResponder { - [super resignFirstResponder]; - BOOL result = [_textView resignFirstResponder]; - if (result) { - [_eventDispatcher sendTextEventWithType:RCTTextEventTypeBlur - reactTag:self.reactTag - text:_textView.text - key:nil - eventCount:_nativeEventCount]; - } - return result; + [_textView reactDidMakeFirstResponder]; } - (void)layoutSubviews @@ -415,11 +431,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) [self updateFrames]; } -- (BOOL)canBecomeFirstResponder -{ - return _jsRequestingFirstResponder; -} - - (UIFont *)defaultPlaceholderFont { return [UIFont systemFontOfSize:17];