Skip to content

Commit 7fe3b2c

Browse files
Nick Lefeverfacebook-github-bot
authored andcommitted
Add dataDetectorType paragraph prop (facebook#52848)
Summary: Pull Request resolved: facebook#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
1 parent 94d2e0a commit 7fe3b2c

File tree

6 files changed

+99
-3
lines changed

6 files changed

+99
-3
lines changed

packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/HostPlatformParagraphProps.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <react/featureflags/ReactNativeFeatureFlags.h>
1111
#include <react/renderer/attributedstring/conversions.h>
1212
#include <react/renderer/attributedstring/primitives.h>
13+
#include <react/renderer/components/text/conversions.h>
1314
#include <react/renderer/core/graphicsConversions.h>
1415
#include <react/renderer/core/propsConversions.h>
1516
#include <react/renderer/debug/debugStringConvertibleUtils.h>
@@ -40,7 +41,18 @@ HostPlatformParagraphProps::HostPlatformParagraphProps(
4041
rawProps,
4142
"selectionColor",
4243
sourceProps.selectionColor,
43-
{})){};
44+
{})),
45+
dataDetectorType(
46+
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
47+
? sourceProps.dataDetectorType
48+
: convertRawProp(
49+
context,
50+
rawProps,
51+
"dataDetectorType",
52+
sourceProps.dataDetectorType,
53+
{}))
54+
55+
{};
4456

4557
void HostPlatformParagraphProps::setProp(
4658
const PropsParserContext& context,
@@ -57,6 +69,7 @@ void HostPlatformParagraphProps::setProp(
5769
switch (hash) {
5870
RAW_SET_PROP_SWITCH_CASE_BASIC(disabled);
5971
RAW_SET_PROP_SWITCH_CASE_BASIC(selectionColor);
72+
RAW_SET_PROP_SWITCH_CASE_BASIC(dataDetectorType);
6073
}
6174
}
6275

@@ -68,7 +81,8 @@ SharedDebugStringConvertibleList HostPlatformParagraphProps::getDebugProps()
6881
return BaseParagraphProps::getDebugProps() +
6982
SharedDebugStringConvertibleList{
7083
debugStringConvertibleItem("disabled", disabled),
71-
debugStringConvertibleItem("selectionColor", selectionColor)};
84+
debugStringConvertibleItem("selectionColor", selectionColor),
85+
debugStringConvertibleItem("dataDetectorType", dataDetectorType)};
7286
}
7387
#endif
7488

@@ -169,6 +183,14 @@ folly::dynamic HostPlatformParagraphProps::getDiffProps(
169183
}
170184
}
171185

186+
if (dataDetectorType != oldProps->dataDetectorType) {
187+
if (dataDetectorType.has_value()) {
188+
result["dataDetectorType"] = toString(dataDetectorType.value());
189+
} else {
190+
result["dataDetectorType"] = folly::dynamic(nullptr);
191+
}
192+
}
193+
172194
return result;
173195
}
174196

packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/HostPlatformParagraphProps.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <optional>
1313

1414
#include <react/renderer/components/text/BaseParagraphProps.h>
15+
#include <react/renderer/components/text/primitives.h>
1516
#include <react/renderer/core/Props.h>
1617
#include <react/renderer/core/PropsParserContext.h>
1718
#include <react/renderer/graphics/Color.h>
@@ -41,6 +42,7 @@ class HostPlatformParagraphProps : public BaseParagraphProps {
4142

4243
bool disabled{false};
4344
std::optional<SharedColor> selectionColor{};
45+
std::optional<DataDetectorType> dataDetectorType{};
4446

4547
#pragma mark - DebugStringConvertible
4648

packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "ParagraphState.h"
99

10-
#include <react/renderer/components/text/conversions.h>
10+
#include <react/renderer/components/text/stateConversions.h>
1111
#include <react/renderer/core/ConcreteState.h>
1212
#include <react/renderer/debug/debugStringConvertibleUtils.h>
1313

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <react/renderer/components/text/primitives.h>
11+
#include <react/renderer/core/PropsParserContext.h>
12+
#include <react/renderer/core/RawValue.h>
13+
#include <string>
14+
15+
namespace facebook::react {
16+
17+
inline void fromRawValue(
18+
const PropsParserContext& /*context*/,
19+
const RawValue& value,
20+
DataDetectorType& result) {
21+
auto string = static_cast<std::string>(value);
22+
if (string == "all") {
23+
result = DataDetectorType::All;
24+
} else if (string == "email") {
25+
result = DataDetectorType::Email;
26+
} else if (string == "link") {
27+
result = DataDetectorType::Link;
28+
} else if (string == "none") {
29+
result = DataDetectorType::None;
30+
} else if (string == "phoneNumber") {
31+
result = DataDetectorType::PhoneNumber;
32+
} else {
33+
abort();
34+
}
35+
}
36+
37+
inline std::string toString(const DataDetectorType& value) {
38+
switch (value) {
39+
case DataDetectorType::All:
40+
return "all";
41+
case DataDetectorType::Email:
42+
return "email";
43+
case DataDetectorType::Link:
44+
return "link";
45+
case DataDetectorType::None:
46+
return "none";
47+
case DataDetectorType::PhoneNumber:
48+
return "phoneNumber";
49+
}
50+
}
51+
52+
} // namespace facebook::react
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
namespace facebook::react {
11+
12+
enum class DataDetectorType {
13+
All,
14+
Email,
15+
Link,
16+
None,
17+
PhoneNumber,
18+
};
19+
20+
} // namespace facebook::react

0 commit comments

Comments
 (0)