mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Add dataDetectorType paragraph prop (#52848)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52848 This diff declares the `DataDetectorType` enum and defined the `dataDetectorType` property on the Android Paragraph props. The conversions.h file holding the state conversion to MapBuffer was renamed to stateConversions.h so that it wouldn't clash with the Android conversions.h file. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D79025294 fbshipit-source-id: 52dc519ea51191f28745d91fe31e36eaba29a731
This commit is contained in:
1 parent
94d2e0a39b
commit
7fe3b2c902
6 files changed
+99
-3
No files matched your search
+24
-2
@@ -10,6 +10,7 @@
|
||||
#include <react/featureflags/ReactNativeFeatureFlags.h>
|
||||
#include <react/renderer/attributedstring/conversions.h>
|
||||
#include <react/renderer/attributedstring/primitives.h>
|
||||
#include <react/renderer/components/text/conversions.h>
|
||||
#include <react/renderer/core/graphicsConversions.h>
|
||||
#include <react/renderer/core/propsConversions.h>
|
||||
#include <react/renderer/debug/debugStringConvertibleUtils.h>
|
||||
@@ -40,7 +41,18 @@ HostPlatformParagraphProps::HostPlatformParagraphProps(
|
||||
rawProps,
|
||||
"selectionColor",
|
||||
sourceProps.selectionColor,
|
||||
{})){};
|
||||
{})),
|
||||
dataDetectorType(
|
||||
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
|
||||
? sourceProps.dataDetectorType
|
||||
: convertRawProp(
|
||||
context,
|
||||
rawProps,
|
||||
"dataDetectorType",
|
||||
sourceProps.dataDetectorType,
|
||||
{}))
|
||||
|
||||
{};
|
||||
|
||||
void HostPlatformParagraphProps::setProp(
|
||||
const PropsParserContext& context,
|
||||
@@ -57,6 +69,7 @@ void HostPlatformParagraphProps::setProp(
|
||||
switch (hash) {
|
||||
RAW_SET_PROP_SWITCH_CASE_BASIC(disabled);
|
||||
RAW_SET_PROP_SWITCH_CASE_BASIC(selectionColor);
|
||||
RAW_SET_PROP_SWITCH_CASE_BASIC(dataDetectorType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +81,8 @@ SharedDebugStringConvertibleList HostPlatformParagraphProps::getDebugProps()
|
||||
return BaseParagraphProps::getDebugProps() +
|
||||
SharedDebugStringConvertibleList{
|
||||
debugStringConvertibleItem("disabled", disabled),
|
||||
debugStringConvertibleItem("selectionColor", selectionColor)};
|
||||
debugStringConvertibleItem("selectionColor", selectionColor),
|
||||
debugStringConvertibleItem("dataDetectorType", dataDetectorType)};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -169,6 +183,14 @@ folly::dynamic HostPlatformParagraphProps::getDiffProps(
|
||||
}
|
||||
}
|
||||
|
||||
if (dataDetectorType != oldProps->dataDetectorType) {
|
||||
if (dataDetectorType.has_value()) {
|
||||
result["dataDetectorType"] = toString(dataDetectorType.value());
|
||||
} else {
|
||||
result["dataDetectorType"] = folly::dynamic(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -12,6 +12,7 @@
|
||||
#include <optional>
|
||||
|
||||
#include <react/renderer/components/text/BaseParagraphProps.h>
|
||||
#include <react/renderer/components/text/primitives.h>
|
||||
#include <react/renderer/core/Props.h>
|
||||
#include <react/renderer/core/PropsParserContext.h>
|
||||
#include <react/renderer/graphics/Color.h>
|
||||
@@ -41,6 +42,7 @@ class HostPlatformParagraphProps : public BaseParagraphProps {
|
||||
|
||||
bool disabled{false};
|
||||
std::optional<SharedColor> selectionColor{};
|
||||
std::optional<DataDetectorType> dataDetectorType{};
|
||||
|
||||
#pragma mark - DebugStringConvertible
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "ParagraphState.h"
|
||||
|
||||
#include <react/renderer/components/text/conversions.h>
|
||||
#include <react/renderer/components/text/stateConversions.h>
|
||||
#include <react/renderer/core/ConcreteState.h>
|
||||
#include <react/renderer/debug/debugStringConvertibleUtils.h>
|
||||
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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/text/primitives.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,
|
||||
DataDetectorType& result) {
|
||||
auto string = static_cast<std::string>(value);
|
||||
if (string == "all") {
|
||||
result = DataDetectorType::All;
|
||||
} else if (string == "email") {
|
||||
result = DataDetectorType::Email;
|
||||
} else if (string == "link") {
|
||||
result = DataDetectorType::Link;
|
||||
} else if (string == "none") {
|
||||
result = DataDetectorType::None;
|
||||
} else if (string == "phoneNumber") {
|
||||
result = DataDetectorType::PhoneNumber;
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string toString(const DataDetectorType& value) {
|
||||
switch (value) {
|
||||
case DataDetectorType::All:
|
||||
return "all";
|
||||
case DataDetectorType::Email:
|
||||
return "email";
|
||||
case DataDetectorType::Link:
|
||||
return "link";
|
||||
case DataDetectorType::None:
|
||||
return "none";
|
||||
case DataDetectorType::PhoneNumber:
|
||||
return "phoneNumber";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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 DataDetectorType {
|
||||
All,
|
||||
Email,
|
||||
Link,
|
||||
None,
|
||||
PhoneNumber,
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
Reference in new issue
Block a user