|
| 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/scrollview/ScrollViewProps.h> |
| 11 | +#include <react/test_utils/PropsPayloads.h> |
| 12 | + |
| 13 | +#ifdef RN_SERIALIZABLE_STATE |
| 14 | + |
| 15 | +namespace facebook::react { |
| 16 | + |
| 17 | +namespace { |
| 18 | + |
| 19 | +using folly::dynamic; |
| 20 | + |
| 21 | +void expectPayloads(const std::vector<PropsCommit>& commits) { |
| 22 | + expectPayloadsMatchRawProps<ScrollViewProps>(commits); |
| 23 | +} |
| 24 | + |
| 25 | +} // namespace |
| 26 | + |
| 27 | +// ReactScrollViewManager has a setter for it; with |
| 28 | +// enableExclusivePropsUpdateAndroid there is no rawProps fallback. |
| 29 | +TEST(ScrollViewPropsDiffTest, emitsScrollsChildToFocus) { |
| 30 | + expectPayloads({{dynamic::object("scrollsChildToFocus", false)}}); |
| 31 | +} |
| 32 | + |
| 33 | +// Android ScrollViews start with snapping alignment disabled, and |
| 34 | +// setSnapToAlignment disables it for null. |
| 35 | +TEST( |
| 36 | + ScrollViewPropsDiffTest, |
| 37 | + keepsAnExplicitSnapToAlignmentStartApartFromUnset) { |
| 38 | + expectPayloads({ |
| 39 | + {dynamic::object("snapToAlignment", "start")}, |
| 40 | + {dynamic::object("snapToAlignment", "center")}, |
| 41 | + {dynamic::object("snapToAlignment", nullptr)}, |
| 42 | + }); |
| 43 | +} |
| 44 | + |
| 45 | +// Android ScrollViews start decelerating at 0.985 (ReactScrollViewHelper). |
| 46 | +// A removed rate restores it; Props 1.5 sends null, which the setter reads as |
| 47 | +// 0. |
| 48 | +TEST(ScrollViewPropsDiffTest, emitsAnExplicitDecelerationRate) { |
| 49 | + expectPayloads({ |
| 50 | + {dynamic::object("decelerationRate", 0.998)}, |
| 51 | + {dynamic::object("decelerationRate", nullptr), |
| 52 | + dynamic::object("decelerationRate", 0.985)}, |
| 53 | + }); |
| 54 | +} |
| 55 | + |
| 56 | +// The ScrollView managers turn both off for null. |
| 57 | +TEST(ScrollViewPropsDiffTest, removingNestedScrollAndMomentumEventsEmitsFalse) { |
| 58 | + expectPayloads({ |
| 59 | + {dynamic::object("nestedScrollEnabled", true)( |
| 60 | + "sendMomentumEvents", true)}, |
| 61 | + {dynamic::object("nestedScrollEnabled", nullptr)( |
| 62 | + "sendMomentumEvents", nullptr), |
| 63 | + dynamic::object("nestedScrollEnabled", false)( |
| 64 | + "sendMomentumEvents", false)}, |
| 65 | + }); |
| 66 | +} |
| 67 | + |
| 68 | +} // namespace facebook::react |
| 69 | + |
| 70 | +#endif |
0 commit comments