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
74 lines
1.8 KiB
Objective-C
74 lines
1.8 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/RCTMultilineTextInputView.h>
|
|
|
|
#import <React/RCTUtils.h>
|
|
|
|
#import <React/RCTUITextView.h>
|
|
|
|
@implementation RCTMultilineTextInputView
|
|
{
|
|
RCTUITextView *_backedTextInputView;
|
|
}
|
|
|
|
- (instancetype)initWithBridge:(RCTBridge *)bridge
|
|
{
|
|
if (self = [super initWithBridge:bridge]) {
|
|
_backedTextInputView = [[RCTUITextView alloc] initWithFrame:self.bounds];
|
|
_backedTextInputView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
_backedTextInputView.textInputDelegate = self;
|
|
|
|
[self addSubview:_backedTextInputView];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (id<RCTBackedTextInputViewProtocol>)backedTextInputView
|
|
{
|
|
return _backedTextInputView;
|
|
}
|
|
|
|
#pragma mark - UIScrollViewDelegate
|
|
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
|
{
|
|
RCTDirectEventBlock onScroll = self.onScroll;
|
|
|
|
if (onScroll) {
|
|
CGPoint contentOffset = scrollView.contentOffset;
|
|
CGSize contentSize = scrollView.contentSize;
|
|
CGSize size = scrollView.bounds.size;
|
|
UIEdgeInsets contentInset = scrollView.contentInset;
|
|
|
|
onScroll(@{
|
|
@"contentOffset": @{
|
|
@"x": @(contentOffset.x),
|
|
@"y": @(contentOffset.y)
|
|
},
|
|
@"contentInset": @{
|
|
@"top": @(contentInset.top),
|
|
@"left": @(contentInset.left),
|
|
@"bottom": @(contentInset.bottom),
|
|
@"right": @(contentInset.right)
|
|
},
|
|
@"contentSize": @{
|
|
@"width": @(contentSize.width),
|
|
@"height": @(contentSize.height)
|
|
},
|
|
@"layoutMeasurement": @{
|
|
@"width": @(size.width),
|
|
@"height": @(size.height)
|
|
},
|
|
@"zoomScale": @(scrollView.zoomScale ?: 1),
|
|
});
|
|
}
|
|
}
|
|
|
|
@end
|