mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
1e3cb91707
Summary: For multiline TextInputs, it's possible to send the submit event when pressing the return key only with `blurOnSubmit`. However, there's currently no way to do so without blurring the input and dismissing the keyboard. This problem is apparent when we want to use a TextInput to span multiple lines but still have it be submittable (but not blurrable), like one might want for a TODO list.  ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [General] [Added] - Add `returnKeyAction` prop to `TextInput` component [General] [Deprecated] - Remove usages of `blurOnSubmit` in native code and convert `blurOnSubmit` to `returnKeyAction` in the JavaScript conversion layer Pull Request resolved: https://github.com/facebook/react-native/pull/33653 Test Plan: Verified old usages of combinations of `blurOnSubmit` and `multiline` matched previous behavior and that the new `returnKeyAction` prop behaves as expected. | Android | iOS | | --- | -- | |  |  | With the changes, the TODO list example from before now looks like this:  Reviewed By: yungsters Differential Revision: D35735249 Pulled By: makovkastar fbshipit-source-id: 1f2237a2a5e11dd141165d7568c91c9824bd6f25
41 lines
1.0 KiB
Objective-C
41 lines
1.0 KiB
Objective-C
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import <React/RCTSinglelineTextInputView.h>
|
|
|
|
#import <React/RCTBridge.h>
|
|
|
|
#import <React/RCTUITextField.h>
|
|
|
|
@implementation RCTSinglelineTextInputView
|
|
{
|
|
RCTUITextField *_backedTextInputView;
|
|
}
|
|
|
|
- (instancetype)initWithBridge:(RCTBridge *)bridge
|
|
{
|
|
if (self = [super initWithBridge:bridge]) {
|
|
// `submitBehavior` defaults to `"blurAndSubmit"` for <TextInput multiline={false}> by design.
|
|
self.submitBehavior = @"blurAndSubmit";
|
|
|
|
_backedTextInputView = [[RCTUITextField alloc] initWithFrame:self.bounds];
|
|
_backedTextInputView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
_backedTextInputView.textInputDelegate = self;
|
|
|
|
[self addSubview:_backedTextInputView];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (id<RCTBackedTextInputViewProtocol>)backedTextInputView
|
|
{
|
|
return _backedTextInputView;
|
|
}
|
|
|
|
@end
|