Skip to content

Commit 86695d8

Browse files
YevheniiKotyrlometa-codesync[bot]
authored andcommitted
Reset removed shadow, editable and persistentScrollbar props to their defaults (#59125)
Summary: A prop removed from a component reaches the C++ props as `null`, and `convertRawProp` then returns its fallback argument. For these props the fallback differs from the field's declared default, so a component that had the prop and lost it is left with a value that a component which never had it does not have: | Prop | Declared default | After removal | | --- | --- | --- | | `shadowRadius` | `3` | `0` | | `shadowOffset` | `{width: 0, height: -3}` | `{width: 0, height: 0}` | | `editable` (TextInput) | `true` | `false` | | `persistentScrollbar` (ScrollView) | `false` | `true` | | `sendMomentumEvents`, `nestedScrollEnabled` (Android ScrollView) | `false` | `true` | On iOS, `RCTViewComponentView` applies the shadow values to the layer, so a view that sets `shadowRadius` or `shadowOffset` conditionally (a raised card, a pressed state) gets `layer.shadowRadius = 0` and `layer.shadowOffset = {0, 0}` once they are removed, instead of the defaults it started with. On Android, the props diff of `enablePropsUpdateReconciliationAndroid` reads the same values, so a `TextInput` that drops `editable={false}` stays read-only and a `ScrollView` that drops `persistentScrollbar` keeps it. `ScrollView` always passes `sendMomentumEvents` and `nestedScrollEnabled`, so those two only reach a direct user of the native component. Each fallback is now the declared default, the value `setProp` (`enableCppPropsIteratorSetter`) already resets these props to. ## Changelog: [GENERAL] [FIXED] - Reset a removed `shadowRadius`, `shadowOffset`, `editable` or `persistentScrollbar` prop to its default Pull Request resolved: #59125 Test Plan: - `ViewPropsTest` and `BaseTextInputPropsTest` parse a prop, then its removal, and compare the result with a default-constructed props object. On `main` they fail with `removed.shadowRadius` 0 against 3, `removed.shadowOffset.height` 0 against -3, and `removed.editable` false against true. `BaseTextInputProps` had no tests, so `textinput/tests/` is new: the SwiftPM target excludes it as the other targets exclude theirs, and the internal BUCK file now defines and links a `:tests` target. The view test target also declares the direct dependencies used by the new regression tests. - A Fantom case in `ScrollView-itest.js` renders `persistentScrollbar={true}` and then no prop; on `main` the second render still carries `persistentScrollbar="true"`. - I ran these in the `reactnativecommunity/react-native-android` image, linking the gtests against the Fantom runner's ReactCommon build: the new tests fail on `main` and pass with this change, and the whole Fantom suite passes with it. clang-format 21.1.2, Prettier, ESLint and Flow pass. - RNTester release builds of `main` and of this change on an iPad (iOS 27.0.1): a view that loses `shadowRadius` and `shadowOffset` draws no shadow on `main` and the default one with this change ([before and after](#59125 (comment))). - Internal validation after the BUCK updates: `buck2 test -j 16 fbsource//xplat/js/react-native-github/packages/react-native/ReactCommon/react/renderer/components/textinput:tests fbsource//xplat/js/react-native-github/packages/react-native/ReactCommon/react/renderer/components/view:tests -- --timeout=300` passed all 96 tests, including the new editable and shadow prop-removal regressions ([test run](https://www.internalfb.com/intern/testinfra/testrun/30680772508413679)). `arc f` and `arc lint -a` passed. - Apple follow-up validation: reproduced both `testsApple` analysis failures with `buck2 build --flagfile fbsource//fbobjc/mode/buck2/ios-tests -c cxx.default_platform=iphonesimulator-arm64` before this update ([failure](https://www.internalfb.com/intern/sandcastle/instance/22518001181223006/)). The direct `core` dependencies caused Buck to import private core headers because the test target basename matches the core test registration. Removing those redundant dependencies avoids the basename `conversions.h` collisions while preserving access to the exported core headers through the component dependencies. Both Apple targets now build successfully ([build](https://www.internalfb.com/buck2/0e4dea76-a9d8-4bec-8fc9-9f74701bfd96)). Running the same two targets with `buck2 test` in the iOS-tests mode passes all 100 tests ([Apple test run](https://www.internalfb.com/intern/testinfra/testrun/11821949232723115)); the Linux targets on the updated base pass all 98 tests ([Linux test run](https://www.internalfb.com/intern/testinfra/testrun/3659175102648737)). `arc f` and focused `arc lint -a` on both BUCK files pass. - Current cross-platform BUCK validation: the Android linker failure in `textinput:testsAndroid` reproduces locally using the exact CI command, `buck2 build --flagfile fbsource//fbandroid/mode/integration-tests-allowed-abi-x86` ([before](https://www.internalfb.com/buck2/f06f5508-6e4c-477e-ab58-9ec31f031e47)). A `test-deps` library now exports the core, view and attributed-string dependencies, matching the existing core test-dependency pattern. This links the symbols used by inline/default props constructors on Android without giving the Apple test direct access to conflicting private headers. The exact Android build now passes ([after](https://www.internalfb.com/buck2/856b54eb-3183-40e9-8237-60eae8a49158)). Both textinput and view test packages build for x86/x86_64 and armeabi-v7a/arm64-v8a, including the 32-bit target variants ([ARM build](https://www.internalfb.com/buck2/95780495-d6f6-47e8-98bc-f90275fc524a)). On the same Linux checkout, the iOS-tests-mode Buck run passes 100/100 tests ([Apple](https://www.internalfb.com/intern/testinfra/testrun/1688850268234094)) and the Linux run passes 98/98 tests ([Linux](https://www.internalfb.com/intern/testinfra/testrun/27303072800788143)). Android `buck2 test` successfully built the packages but reported `NO TESTS RAN`, so no Android runtime test pass is claimed. `arc f` and focused `arc lint -a` pass. Reviewed By: christophpurrer Differential Revision: D125706127 Pulled By: javache fbshipit-source-id: c94b7a1d2e96cc59a958b34bc3242e2fc71d1fcd
1 parent 1423ef0 commit 86695d8

8 files changed

Lines changed: 136 additions & 7 deletions

File tree

‎packages/react-native/Libraries/Components/ScrollView/__tests__/ScrollView-itest.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,34 @@ describe('<ScrollView>', () => {
4141
</rn-scrollView>,
4242
);
4343
});
44+
45+
it('returns persistentScrollbar to its default once the prop is removed', () => {
46+
const root = Fantom.createRoot();
47+
48+
Fantom.runTask(() => {
49+
root.render(<ScrollView persistentScrollbar={true} />);
50+
});
51+
52+
expect(
53+
root.getRenderedOutput({props: ['persistentScrollbar']}).toJSX(),
54+
).toEqual(
55+
<rn-scrollView persistentScrollbar="true">
56+
<rn-view />
57+
</rn-scrollView>,
58+
);
59+
60+
Fantom.runTask(() => {
61+
root.render(<ScrollView />);
62+
});
63+
64+
expect(
65+
root.getRenderedOutput({props: ['persistentScrollbar']}).toJSX(),
66+
).toEqual(
67+
<rn-scrollView>
68+
<rn-view />
69+
</rn-scrollView>,
70+
);
71+
});
4472
});
4573

4674
describe('ref', () => {

‎packages/react-native/Package.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ let reactFabricText = RNTarget(
563563
let reactFabricTextInput = RNTarget(
564564
name: .reactFabricTextInput,
565565
path: "ReactCommon/react/renderer/components/textinput",
566-
excludedPaths: ["platform/android", "platform/macos"],
566+
excludedPaths: ["tests", "platform/android", "platform/macos"],
567567
dependencies: [.reactNativeDependencies, .reactCore, .reactJsiExecutor, .reactTurboModuleCore, .jsi, .logger, .reactDebug, .reactFeatureFlags, .reactUtils, .reactRuntimeScheduler, .reactCxxReact, .yoga, .reactRendererDebug, .reactGraphics, .reactFabric, .reactTurboModuleBridging, .reactFabricTextLayoutManager, .reactImageManagerApple],
568568
sources: [".", "platform/ios"]
569569
)

‎packages/react-native/ReactCommon/react/renderer/components/scrollview/BaseScrollViewProps.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ BaseScrollViewProps::BaseScrollViewProps(
164164
rawProps,
165165
"persistentScrollbar",
166166
sourceProps.persistentScrollbar,
167-
true)),
167+
false)),
168168
horizontal(convertRawProp(
169169
context,
170170
rawProps,

‎packages/react-native/ReactCommon/react/renderer/components/scrollview/platform/android/react/renderer/components/scrollview/HostPlatformScrollViewProps.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ HostPlatformScrollViewProps::HostPlatformScrollViewProps(
2525
rawProps,
2626
"sendMomentumEvents",
2727
sourceProps.sendMomentumEvents,
28-
true)),
28+
false)),
2929
nestedScrollEnabled(convertRawProp(
3030
context,
3131
rawProps,
3232
"nestedScrollEnabled",
3333
sourceProps.nestedScrollEnabled,
34-
true)),
34+
false)),
3535
fadingEdgeLength(convertRawProp(
3636
context,
3737
rawProps,

‎packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ BaseTextInputProps::BaseTextInputProps(
104104
rawProps,
105105
"editable",
106106
sourceProps.editable,
107-
{})),
107+
true)),
108108
readOnly(convertRawProp(
109109
context,
110110
rawProps,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
#include <gtest/gtest.h>
9+
10+
#include <react/renderer/components/textinput/BaseTextInputProps.h>
11+
#include <react/renderer/core/RawProps.h>
12+
#include <react/renderer/core/RawPropsParser.h>
13+
14+
namespace facebook::react {
15+
16+
namespace {
17+
18+
BaseTextInputProps parse(
19+
const folly::dynamic& rawPropsValue,
20+
const BaseTextInputProps& sourceProps = BaseTextInputProps()) {
21+
ContextContainer contextContainer{};
22+
PropsParserContext parserContext{-1, contextContainer};
23+
24+
auto raw = RawProps(rawPropsValue);
25+
auto parser = RawPropsParser();
26+
parser.prepare<BaseTextInputProps>();
27+
raw.parse(parser);
28+
29+
return {parserContext, sourceProps, raw};
30+
}
31+
32+
} // namespace
33+
34+
TEST(BaseTextInputPropsTest, removed_editable_returns_to_its_default) {
35+
auto readOnly = parse(folly::dynamic::object("editable", false));
36+
ASSERT_FALSE(readOnly.editable);
37+
38+
auto removed = parse(folly::dynamic::object("editable", nullptr), readOnly);
39+
40+
EXPECT_EQ(removed.editable, BaseTextInputProps().editable);
41+
}
42+
43+
} // namespace facebook::react

‎packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ BaseViewProps::BaseViewProps(
180180
rawProps,
181181
"shadowOffset",
182182
sourceProps.shadowOffset,
183-
{})),
183+
Size{0, -3})),
184184
shadowOpacity(convertRawProp(
185185
context,
186186
rawProps,
@@ -192,7 +192,7 @@ BaseViewProps::BaseViewProps(
192192
rawProps,
193193
"shadowRadius",
194194
sourceProps.shadowRadius,
195-
{})),
195+
(Float)3)),
196196
cursor(
197197
convertRawProp(context, rawProps, "cursor", sourceProps.cursor, {})),
198198
boxShadow(convertRawProp(
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
#include <gtest/gtest.h>
9+
10+
#include <react/renderer/components/view/ViewProps.h>
11+
#include <react/renderer/core/RawProps.h>
12+
#include <react/renderer/core/RawPropsParser.h>
13+
14+
namespace facebook::react {
15+
16+
namespace {
17+
18+
ViewProps parse(
19+
const folly::dynamic& rawPropsValue,
20+
const ViewProps& sourceProps = ViewProps()) {
21+
ContextContainer contextContainer{};
22+
PropsParserContext parserContext{-1, contextContainer};
23+
24+
auto raw = RawProps(rawPropsValue);
25+
auto parser = RawPropsParser();
26+
parser.prepare<ViewProps>();
27+
raw.parse(parser);
28+
29+
return {parserContext, sourceProps, raw};
30+
}
31+
32+
} // namespace
33+
34+
TEST(ViewPropsTest, removed_shadow_radius_returns_to_its_default) {
35+
auto withShadowRadius = parse(folly::dynamic::object("shadowRadius", 8));
36+
ASSERT_EQ(withShadowRadius.shadowRadius, 8);
37+
38+
auto removed =
39+
parse(folly::dynamic::object("shadowRadius", nullptr), withShadowRadius);
40+
41+
EXPECT_EQ(removed.shadowRadius, ViewProps().shadowRadius);
42+
}
43+
44+
TEST(ViewPropsTest, removed_shadow_offset_returns_to_its_default) {
45+
auto withShadowOffset = parse(
46+
folly::dynamic::object(
47+
"shadowOffset", folly::dynamic::object("width", 2)("height", 4)));
48+
ASSERT_EQ(withShadowOffset.shadowOffset, (Size{.width = 2, .height = 4}));
49+
50+
auto removed =
51+
parse(folly::dynamic::object("shadowOffset", nullptr), withShadowOffset);
52+
53+
const auto defaultShadowOffset = ViewProps().shadowOffset;
54+
EXPECT_EQ(removed.shadowOffset.width, defaultShadowOffset.width);
55+
EXPECT_EQ(removed.shadowOffset.height, defaultShadowOffset.height);
56+
}
57+
58+
} // namespace facebook::react

0 commit comments

Comments
 (0)