Files
react-native/ReactCommon/react/renderer/components/textinput/iostextinput/conversions.h
T
Tony Du 1e3cb91707 Allow multiline TextInputs be submittable without blurring (#33653)
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.

![multiline-momentary-blur](https://user-images.githubusercontent.com/22553678/163596940-aae779f5-4d2a-4425-8ed0-e4aa77b90699.gif)

## 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 |
| --- | -- |
| ![android-returnkeyaction-test](https://user-images.githubusercontent.com/22553678/163597864-2e306f98-7b6e-4ddf-8a35-625d397d3dce.gif) | ![ios-returnkeyaction-test](https://user-images.githubusercontent.com/22553678/163598407-9e059f74-3549-4b46-8e03-c19bfaa6dd3d.gif)  |

With the changes, the TODO list example from before now looks like this:

![multiline-no-momentary-blur](https://user-images.githubusercontent.com/22553678/163598810-f3a71d62-5514-486e-bf6a-79169fe86378.gif)

Reviewed By: yungsters

Differential Revision: D35735249

Pulled By: makovkastar

fbshipit-source-id: 1f2237a2a5e11dd141165d7568c91c9824bd6f25
2022-07-22 13:08:45 -07:00

243 lines
5.1 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 {
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
AutocapitalizationType &result) {
auto string = (std::string)value;
if (string == "none") {
result = AutocapitalizationType::None;
return;
}
if (string == "words") {
result = AutocapitalizationType::Words;
return;
}
if (string == "sentences") {
result = AutocapitalizationType::Sentences;
return;
}
if (string == "characters") {
result = AutocapitalizationType::Characters;
return;
}
abort();
}
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
KeyboardAppearance &result) {
auto string = (std::string)value;
if (string == "default") {
result = KeyboardAppearance::Default;
return;
}
if (string == "light") {
result = KeyboardAppearance::Light;
return;
}
if (string == "dark") {
result = KeyboardAppearance::Dark;
return;
}
abort();
}
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
ReturnKeyType &result) {
auto string = (std::string)value;
if (string == "default") {
result = ReturnKeyType::Default;
return;
}
if (string == "done") {
result = ReturnKeyType::Done;
return;
}
if (string == "go") {
result = ReturnKeyType::Go;
return;
}
if (string == "next") {
result = ReturnKeyType::Next;
return;
}
if (string == "search") {
result = ReturnKeyType::Search;
return;
}
if (string == "send") {
result = ReturnKeyType::Send;
return;
}
// Android-only
if (string == "none") {
result = ReturnKeyType::None;
return;
}
if (string == "previous") {
result = ReturnKeyType::Previous;
return;
}
// iOS-only
if (string == "emergency-call") {
result = ReturnKeyType::EmergencyCall;
return;
}
if (string == "google") {
result = ReturnKeyType::Google;
return;
}
if (string == "join") {
result = ReturnKeyType::Join;
return;
}
if (string == "route") {
result = ReturnKeyType::Route;
return;
}
if (string == "yahoo") {
result = ReturnKeyType::Yahoo;
return;
}
if (string == "continue") {
result = ReturnKeyType::Continue;
return;
}
abort();
}
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
SubmitBehavior &result) {
auto string = (std::string)value;
if (string == "newline") {
result = SubmitBehavior::Newline;
return;
}
if (string == "submit") {
result = SubmitBehavior::Submit;
return;
}
if (string == "blurAndSubmit") {
result = SubmitBehavior::BlurAndSubmit;
return;
}
abort();
}
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
TextInputAccessoryVisibilityMode &result) {
auto string = (std::string)value;
if (string == "never") {
result = TextInputAccessoryVisibilityMode::Never;
return;
}
if (string == "while-editing") {
result = TextInputAccessoryVisibilityMode::WhileEditing;
return;
}
if (string == "unless-editing") {
result = TextInputAccessoryVisibilityMode::UnlessEditing;
return;
}
if (string == "always") {
result = TextInputAccessoryVisibilityMode::Always;
return;
}
abort();
}
inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
KeyboardType &result) {
auto string = (std::string)value;
if (string == "default") {
result = KeyboardType::Default;
return;
}
if (string == "email-address") {
result = KeyboardType::EmailAddress;
return;
}
if (string == "numeric") {
result = KeyboardType::Numeric;
return;
}
if (string == "phone-pad") {
result = KeyboardType::PhonePad;
return;
}
if (string == "number-pad") {
result = KeyboardType::NumberPad;
return;
}
if (string == "url") {
result = KeyboardType::URL;
return;
}
if (string == "decimal-pad") {
result = KeyboardType::DecimalPad;
return;
}
// iOS-only
if (string == "ascii-capable") {
result = KeyboardType::ASCIICapable;
return;
}
if (string == "numbers-and-punctuation") {
result = KeyboardType::NumbersAndPunctuation;
return;
}
if (string == "name-phone-pad") {
result = KeyboardType::NamePhonePad;
return;
}
if (string == "twitter") {
result = KeyboardType::Twitter;
return;
}
if (string == "web-search") {
result = KeyboardType::WebSearch;
return;
}
if (string == "ascii-capable-number-pad") {
result = KeyboardType::ASCIICapableNumberPad;
return;
}
// Android-only
if (string == "visible-password") {
result = KeyboardType::VisiblePassword;
return;
}
abort();
}
} // namespace react
} // namespace facebook