Skip to content

Commit 5e80759

Browse files
Nick Lefeverfacebook-github-bot
authored andcommitted
Add disabled paragraph prop (facebook#52846)
Summary: Pull Request resolved: facebook#52846 Adding the Paragraph `disabled` property for RN Android. This diff also adds a new Text example to RNTester for disabled text. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D78990840 fbshipit-source-id: dd25b890597bc9f728f929b38c2f680631b7f476
1 parent d390f3b commit 5e80759

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@ HostPlatformParagraphProps::HostPlatformParagraphProps(
2121
const PropsParserContext& context,
2222
const HostPlatformParagraphProps& sourceProps,
2323
const RawProps& rawProps)
24-
: BaseParagraphProps(context, sourceProps, rawProps) {}
24+
: BaseParagraphProps(context, sourceProps, rawProps),
25+
disabled(
26+
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
27+
? sourceProps.disabled
28+
: convertRawProp(
29+
context,
30+
rawProps,
31+
"disabled",
32+
sourceProps.disabled,
33+
false)){};
2534

2635
void HostPlatformParagraphProps::setProp(
2736
const PropsParserContext& context,
@@ -32,14 +41,20 @@ void HostPlatformParagraphProps::setProp(
3241
// call all super::setProp methods, since multiple structs may
3342
// reuse the same values.
3443
BaseParagraphProps::setProp(context, hash, propName, value);
44+
45+
static auto defaults = HostPlatformParagraphProps{};
46+
47+
switch (hash) { RAW_SET_PROP_SWITCH_CASE_BASIC(disabled); }
3548
}
3649

3750
#pragma mark - DebugStringConvertible
3851

3952
#if RN_DEBUG_STRING_CONVERTIBLE
4053
SharedDebugStringConvertibleList HostPlatformParagraphProps::getDebugProps()
4154
const {
42-
return BaseParagraphProps::getDebugProps();
55+
return BaseParagraphProps::getDebugProps() +
56+
SharedDebugStringConvertibleList{
57+
debugStringConvertibleItem("disabled", disabled)};
4358
}
4459
#endif
4560

@@ -128,6 +143,10 @@ folly::dynamic HostPlatformParagraphProps::getDiffProps(
128143
result["onTextLayout"] = onTextLayout;
129144
}
130145

146+
if (disabled != oldProps->disabled) {
147+
result["disabled"] = disabled;
148+
}
149+
131150
return result;
132151
}
133152

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class HostPlatformParagraphProps : public BaseParagraphProps {
3535
const char* propName,
3636
const RawValue& value);
3737

38+
#pragma mark - Props
39+
40+
bool disabled{false};
41+
3842
#pragma mark - DebugStringConvertible
3943

4044
#if RN_DEBUG_STRING_CONVERTIBLE

packages/rn-tester/js/examples/Text/TextExample.android.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,20 @@ const examples = [
17191719
);
17201720
},
17211721
},
1722+
{
1723+
title: 'Disabled',
1724+
name: 'disabled',
1725+
render: function (): React.Node {
1726+
return (
1727+
<View>
1728+
<RNTesterText testID="text-disabled" disabled={true}>
1729+
This text has its corresponding text view in the disabled state for
1730+
testing purposes.
1731+
</RNTesterText>
1732+
</View>
1733+
);
1734+
},
1735+
},
17221736
...TextSharedExamples,
17231737
];
17241738

0 commit comments

Comments
 (0)