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
45 lines
1.6 KiB
Objective-C
45 lines
1.6 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 <UIKit/UIKit.h>
|
|
|
|
@protocol RCTBackedTextInputViewProtocol;
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
@protocol RCTBackedTextInputDelegate <NSObject>
|
|
|
|
- (BOOL)textInputShouldBeginEditing; // Return `NO` to disallow editing.
|
|
- (void)textInputDidBeginEditing;
|
|
|
|
- (BOOL)textInputShouldEndEditing; // Return `YES` to allow editing to stop and to resign first responder status. `NO` to disallow the editing session to end.
|
|
- (void)textInputDidEndEditing; // May be called if forced even if `textInputShouldEndEditing` returns `NO` (e.g. view removed from window) or `[textInput endEditing:YES]` called.
|
|
|
|
- (BOOL)textInputShouldReturn; // May be called right before `textInputShouldEndEditing` if "Return" button was pressed. Dismisses keyboard if true
|
|
- (void)textInputDidReturn;
|
|
|
|
- (BOOL)textInputShouldSubmitOnReturn; // Checks whether to submit when return is pressed and emits an event if true.
|
|
|
|
/*
|
|
* Called before any change in the TextInput. The delegate has the opportunity to change the replacement string or reject the change completely.
|
|
* To change the replacement, return the changed version of the `text`.
|
|
* To accept the change, return `text` argument as-is.
|
|
* To reject the change, return `nil`.
|
|
*/
|
|
- (NSString *)textInputShouldChangeText:(NSString *)text inRange:(NSRange)range;
|
|
- (void)textInputDidChange;
|
|
|
|
- (void)textInputDidChangeSelection;
|
|
|
|
@optional
|
|
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|