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
183 lines
5.0 KiB
C++
183 lines
5.0 KiB
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.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <react/renderer/components/iostextinput/primitives.h>
|
|
#include <react/renderer/core/PropsParserContext.h>
|
|
#include <react/renderer/core/propsConversions.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
static TextInputTraits convertRawProp(
|
|
const PropsParserContext &context,
|
|
RawProps const &rawProps,
|
|
TextInputTraits const &sourceTraits,
|
|
TextInputTraits const &defaultTraits) {
|
|
auto traits = TextInputTraits{};
|
|
|
|
traits.multiline = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"multiline",
|
|
sourceTraits.multiline,
|
|
defaultTraits.multiline);
|
|
traits.autocapitalizationType = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"autoCapitalize",
|
|
sourceTraits.autocapitalizationType,
|
|
defaultTraits.autocapitalizationType);
|
|
traits.autoCorrect = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"autoCorrect",
|
|
sourceTraits.autoCorrect,
|
|
defaultTraits.autoCorrect);
|
|
traits.contextMenuHidden = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"contextMenuHidden",
|
|
sourceTraits.contextMenuHidden,
|
|
defaultTraits.contextMenuHidden);
|
|
traits.editable = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"editable",
|
|
sourceTraits.editable,
|
|
defaultTraits.editable);
|
|
traits.enablesReturnKeyAutomatically = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"enablesReturnKeyAutomatically",
|
|
sourceTraits.enablesReturnKeyAutomatically,
|
|
defaultTraits.enablesReturnKeyAutomatically);
|
|
traits.keyboardAppearance = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"keyboardAppearance",
|
|
sourceTraits.keyboardAppearance,
|
|
defaultTraits.keyboardAppearance);
|
|
traits.spellCheck = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"spellCheck",
|
|
sourceTraits.spellCheck,
|
|
defaultTraits.spellCheck);
|
|
traits.caretHidden = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"caretHidden",
|
|
sourceTraits.caretHidden,
|
|
defaultTraits.caretHidden);
|
|
traits.clearButtonMode = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"clearButtonMode",
|
|
sourceTraits.clearButtonMode,
|
|
defaultTraits.clearButtonMode);
|
|
traits.scrollEnabled = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"scrollEnabled",
|
|
sourceTraits.scrollEnabled,
|
|
defaultTraits.scrollEnabled);
|
|
traits.secureTextEntry = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"secureTextEntry",
|
|
sourceTraits.secureTextEntry,
|
|
defaultTraits.secureTextEntry);
|
|
traits.submitBehavior = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"submitBehavior",
|
|
sourceTraits.submitBehavior,
|
|
defaultTraits.submitBehavior);
|
|
traits.clearTextOnFocus = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"clearTextOnFocus",
|
|
sourceTraits.clearTextOnFocus,
|
|
defaultTraits.clearTextOnFocus);
|
|
traits.keyboardType = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"keyboardType",
|
|
sourceTraits.keyboardType,
|
|
defaultTraits.keyboardType);
|
|
traits.showSoftInputOnFocus = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"showSoftInputOnFocus",
|
|
sourceTraits.showSoftInputOnFocus,
|
|
defaultTraits.showSoftInputOnFocus);
|
|
traits.returnKeyType = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"returnKeyType",
|
|
sourceTraits.returnKeyType,
|
|
defaultTraits.returnKeyType);
|
|
traits.selectTextOnFocus = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"selectTextOnFocus",
|
|
sourceTraits.selectTextOnFocus,
|
|
defaultTraits.selectTextOnFocus);
|
|
traits.textContentType = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"textContentType",
|
|
sourceTraits.textContentType,
|
|
defaultTraits.textContentType);
|
|
traits.passwordRules = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"passwordRules",
|
|
sourceTraits.passwordRules,
|
|
defaultTraits.passwordRules);
|
|
|
|
return traits;
|
|
}
|
|
|
|
inline void fromRawValue(
|
|
const PropsParserContext &context,
|
|
const RawValue &value,
|
|
Selection &result) {
|
|
if (value.hasType<butter::map<std::string, int>>()) {
|
|
auto map = (butter::map<std::string, int>)value;
|
|
for (const auto &pair : map) {
|
|
if (pair.first == "start") {
|
|
result.start = pair.second;
|
|
} else if (pair.first == "end") {
|
|
result.end = pair.second;
|
|
} else {
|
|
LOG(ERROR) << "Unsupported Selection map key: " << pair.first;
|
|
react_native_assert(false);
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
react_native_assert(value.hasType<std::vector<int>>());
|
|
if (value.hasType<std::vector<int>>()) {
|
|
auto array = (std::vector<int>)value;
|
|
react_native_assert(array.size() == 2);
|
|
if (array.size() >= 2) {
|
|
result = {array.at(0), array.at(1)};
|
|
} else {
|
|
result = {0, 0};
|
|
LOG(ERROR) << "Unsupported Selection vector size: " << array.size();
|
|
}
|
|
} else {
|
|
LOG(ERROR) << "Unsupported Selection type";
|
|
}
|
|
}
|
|
} // namespace react
|
|
} // namespace facebook
|