From 7fe3b2c9023642a57bbee9da7a8b94046b6950dc Mon Sep 17 00:00:00 2001 From: Nick Lefever Date: Sun, 27 Jul 2025 17:20:44 -0700 Subject: [PATCH] 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 --- .../text/HostPlatformParagraphProps.cpp | 26 +++++++++- .../text/HostPlatformParagraphProps.h | 2 + .../components/text/ParagraphState.cpp | 2 +- .../renderer/components/text/conversions.h | 52 +++++++++++++++++++ .../renderer/components/text/primitives.h | 20 +++++++ .../{conversions.h => stateConversions.h} | 0 6 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/conversions.h create mode 100644 packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/primitives.h rename packages/react-native/ReactCommon/react/renderer/components/text/{conversions.h => stateConversions.h} (100%) diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/HostPlatformParagraphProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/HostPlatformParagraphProps.cpp index 4f151bf069a..a1019158f66 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/HostPlatformParagraphProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/HostPlatformParagraphProps.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -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; } diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/HostPlatformParagraphProps.h b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/HostPlatformParagraphProps.h index cc25bfc83a5..1082b822b3b 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/HostPlatformParagraphProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/HostPlatformParagraphProps.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -41,6 +42,7 @@ class HostPlatformParagraphProps : public BaseParagraphProps { bool disabled{false}; std::optional selectionColor{}; + std::optional dataDetectorType{}; #pragma mark - DebugStringConvertible diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.cpp b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.cpp index 00def60e86b..2e6417f970b 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.cpp @@ -7,7 +7,7 @@ #include "ParagraphState.h" -#include +#include #include #include diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/conversions.h b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/conversions.h new file mode 100644 index 00000000000..af246ab2b47 --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/conversions.h @@ -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 +#include +#include +#include + +namespace facebook::react { + +inline void fromRawValue( + const PropsParserContext& /*context*/, + const RawValue& value, + DataDetectorType& result) { + auto string = static_cast(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 diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/primitives.h b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/primitives.h new file mode 100644 index 00000000000..30f9bd623f5 --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/primitives.h @@ -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 diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/conversions.h b/packages/react-native/ReactCommon/react/renderer/components/text/stateConversions.h similarity index 100% rename from packages/react-native/ReactCommon/react/renderer/components/text/conversions.h rename to packages/react-native/ReactCommon/react/renderer/components/text/stateConversions.h