mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Make textInputProps.submitBehavior on android an enum type (#47206)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47206 Share definition of `SubmitBehavior` enum on ios, and use it on android Changelog: [Internal] Reviewed By: rshest Differential Revision: D64718150 fbshipit-source-id: a078c9be44c625cc5e9001e4ae25d32eaaf5d8e4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8b9535f101
commit
db835e28d8
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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/textinput/basePrimitives.h>
|
||||
#include <react/renderer/core/PropsParserContext.h>
|
||||
#include <react/renderer/core/RawValue.h>
|
||||
#include <string>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
inline void fromRawValue(
|
||||
const PropsParserContext& /*context*/,
|
||||
const RawValue& value,
|
||||
SubmitBehavior& result) {
|
||||
auto string = static_cast<std::string>(value);
|
||||
if (string == "newline") {
|
||||
result = SubmitBehavior::Newline;
|
||||
} else if (string == "submit") {
|
||||
result = SubmitBehavior::Submit;
|
||||
} else if (string == "blurAndSubmit") {
|
||||
result = SubmitBehavior::BlurAndSubmit;
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
inline folly::dynamic toDynamic(const SubmitBehavior& value) {
|
||||
switch (value) {
|
||||
case SubmitBehavior::Newline:
|
||||
return "newline";
|
||||
case SubmitBehavior::Submit:
|
||||
return "submit";
|
||||
case SubmitBehavior::BlurAndSubmit:
|
||||
return "blurAndSubmit";
|
||||
case SubmitBehavior::Default:
|
||||
return {nullptr};
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
enum class SubmitBehavior {
|
||||
Default,
|
||||
Submit,
|
||||
BlurAndSubmit,
|
||||
Newline,
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
+2
-1
@@ -8,6 +8,7 @@
|
||||
#include "AndroidTextInputProps.h"
|
||||
#include <react/featureflags/ReactNativeFeatureFlags.h>
|
||||
#include <react/renderer/components/image/conversions.h>
|
||||
#include <react/renderer/components/textinput/baseConversions.h>
|
||||
#include <react/renderer/core/graphicsConversions.h>
|
||||
#include <react/renderer/core/propsConversions.h>
|
||||
|
||||
@@ -322,7 +323,7 @@ folly::dynamic AndroidTextInputProps::getDynamic() const {
|
||||
props["value"] = value;
|
||||
props["defaultValue"] = defaultValue;
|
||||
props["selectTextOnFocus"] = selectTextOnFocus;
|
||||
props["submitBehavior"] = submitBehavior;
|
||||
props["submitBehavior"] = toDynamic(submitBehavior);
|
||||
props["caretHidden"] = caretHidden;
|
||||
props["contextMenuHidden"] = contextMenuHidden;
|
||||
props["textShadowColor"] = toAndroidRepr(textShadowColor);
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@
|
||||
#include <react/renderer/attributedstring/TextAttributes.h>
|
||||
#include <react/renderer/attributedstring/conversions.h>
|
||||
#include <react/renderer/components/textinput/BaseTextInputProps.h>
|
||||
#include <react/renderer/components/textinput/basePrimitives.h>
|
||||
#include <react/renderer/core/PropsParserContext.h>
|
||||
#include <react/renderer/core/propsConversions.h>
|
||||
#include <react/renderer/graphics/Color.h>
|
||||
@@ -93,7 +94,7 @@ class AndroidTextInputProps final : public BaseTextInputProps {
|
||||
bool secureTextEntry{false};
|
||||
std::string value{};
|
||||
bool selectTextOnFocus{false};
|
||||
std::string submitBehavior{};
|
||||
SubmitBehavior submitBehavior{};
|
||||
bool caretHidden{false};
|
||||
bool contextMenuHidden{false};
|
||||
SharedColor textShadowColor{};
|
||||
|
||||
+1
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <react/renderer/attributedstring/conversions.h>
|
||||
#include <react/renderer/components/iostextinput/propsConversions.h>
|
||||
#include <react/renderer/components/textinput/baseConversions.h>
|
||||
#include <react/renderer/core/graphicsConversions.h>
|
||||
#include <react/renderer/core/propsConversions.h>
|
||||
|
||||
|
||||
-20
@@ -125,26 +125,6 @@ inline void fromRawValue(
|
||||
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,
|
||||
|
||||
+1
-8
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/renderer/components/textinput/basePrimitives.h>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
@@ -47,14 +48,6 @@ enum class ReturnKeyType {
|
||||
Continue,
|
||||
};
|
||||
|
||||
// iOS & Android.
|
||||
enum class SubmitBehavior {
|
||||
Default,
|
||||
Submit,
|
||||
BlurAndSubmit,
|
||||
Newline,
|
||||
};
|
||||
|
||||
// iOS-only
|
||||
enum class TextInputAccessoryVisibilityMode {
|
||||
Never,
|
||||
|
||||
Reference in New Issue
Block a user