Move Android ScrollView props to HostPlatformScrollViewProps (#51517)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51517

The Props 2.0 implementation for ScrollView added two missing props which were Android specific.

This diff moves these to a separate HostPlatformScrollViewProps class so that other platforms wouldn't include them

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D75183132

fbshipit-source-id: 44d0e0aa974e69f8584ad6bd681fad100c3493d8
This commit is contained in:
Nick Lefever
2025-05-26 10:54:35 -07:00
committed by Facebook GitHub Bot
parent 1da4abd273
commit a314e34d6e
10 changed files with 518 additions and 390 deletions
@@ -66,11 +66,13 @@ Pod::Spec.new do |s|
add_dependency(s, "React-FabricImage")
add_dependency(s, "React-Fabric", :additional_framework_paths => [
"react/renderer/components/scrollview/platform/cxx",
"react/renderer/components/view/platform/cxx",
"react/renderer/imagemanager/platform/ios",
])
add_dependency(s, "React-FabricComponents", :additional_framework_paths => [
"react/renderer/textlayoutmanager/platform/ios",
"react/renderer/components/scrollview/platform/cxx",
"react/renderer/components/text/platform/cxx",
"react/renderer/components/textinput/platform/ios",
]);
@@ -77,6 +77,7 @@ Pod::Spec.new do |s|
if ENV['USE_FRAMEWORKS']
header_search_path = header_search_path + [
"\"$(PODS_TARGET_SRCROOT)/react/renderer/textlayoutmanager/platform/ios\"",
"\"$(PODS_TARGET_SRCROOT)/react/renderer/components/scrollview/platform/cxx\"",
"\"$(PODS_TARGET_SRCROOT)/react/renderer/components/text/platform/cxx\"",
"\"$(PODS_TARGET_SRCROOT)/react/renderer/components/textinput/platform/ios\"",
"\"$(PODS_TARGET_SRCROOT)/react/renderer/components/view/platform/cxx\"",
@@ -118,9 +119,9 @@ Pod::Spec.new do |s|
end
ss.subspec "scrollview" do |sss|
sss.source_files = "react/renderer/components/scrollview/*.{m,mm,cpp,h}"
sss.source_files = "react/renderer/components/scrollview/**/*.{m,mm,cpp,h}"
sss.header_dir = "react/renderer/components/scrollview"
ss.exclude_files = "react/renderer/components/scrollview/tests"
sss.exclude_files = "react/renderer/components/scrollview/tests", "react/renderer/components/scrollview/platform/android"
end
ss.subspec "legacyviewmanagerinterop" do |sss|
@@ -29,6 +29,7 @@ Pod::Spec.new do |s|
if ENV['USE_FRAMEWORKS']
header_search_path = header_search_path + [
"\"$(PODS_TARGET_SRCROOT)/react/renderer/textlayoutmanager/platform/ios\"",
"\"$(PODS_TARGET_SRCROOT)/react/renderer/components/scrollview/platform/cxx\"",
"\"$(PODS_TARGET_SRCROOT)/react/renderer/components/textinput/platform/ios\"",
"\"$(PODS_TARGET_SRCROOT)/react/renderer/components/text/platform/cxx\"",
"\"$(PODS_TARGET_SRCROOT)/react/renderer/components/view/platform/cxx\"",
@@ -72,6 +73,7 @@ Pod::Spec.new do |s|
add_dependency(s, "React-rendererdebug")
add_dependency(s, "React-graphics", :additional_framework_paths => ["react/renderer/graphics/platform/ios"])
add_dependency(s, "React-Fabric", :additional_framework_paths => [
"react/renderer/components/scrollview/platform/cxx",
"react/renderer/components/view/platform/cxx",
"react/renderer/imagemanager/platform/ios"
])
@@ -105,7 +107,9 @@ Pod::Spec.new do |s|
end
ss.subspec "scrollview" do |sss|
sss.source_files = "react/renderer/components/scrollview/*.{m,mm,cpp,h}"
sss.source_files = "react/renderer/components/scrollview/*.{m,mm,cpp,h}",
"react/renderer/components/scrollview/platform/cxx/**/*.{m,mm,cpp,h}"
sss.exclude_files = "react/renderer/components/scrollview/tests"
sss.header_dir = "react/renderer/components/scrollview"
end
@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
#include "ScrollViewProps.h"
#include "BaseScrollViewProps.h"
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/renderer/components/scrollview/conversions.h>
@@ -16,9 +16,10 @@
namespace facebook::react {
ScrollViewProps::ScrollViewProps(
// TODO (T28334063): Consider for codegen.
BaseScrollViewProps::BaseScrollViewProps(
const PropsParserContext& context,
const ScrollViewProps& sourceProps,
const BaseScrollViewProps& sourceProps,
const RawProps& rawProps)
: ViewProps(context, sourceProps, rawProps),
alwaysBounceHorizontal(
@@ -371,29 +372,9 @@ ScrollViewProps::ScrollViewProps(
rawProps,
"isInvertedVirtualizedList",
sourceProps.isInvertedVirtualizedList,
{})),
sendMomentumEvents(
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
? sourceProps.sendMomentumEvents
: convertRawProp(
context,
rawProps,
"sendMomentumEvents",
sourceProps.sendMomentumEvents,
true)),
nestedScrollEnabled(
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
? sourceProps.nestedScrollEnabled
: convertRawProp(
context,
rawProps,
"nestedScrollEnabled",
sourceProps.nestedScrollEnabled,
true))
{})) {}
{}
void ScrollViewProps::setProp(
void BaseScrollViewProps::setProp(
const PropsParserContext& context,
RawPropsPropNameHash hash,
const char* propName,
@@ -403,7 +384,7 @@ void ScrollViewProps::setProp(
// reuse the same values.
ViewProps::setProp(context, hash, propName, value);
static auto defaults = ScrollViewProps{};
static auto defaults = BaseScrollViewProps{};
switch (hash) {
RAW_SET_PROP_SWITCH_CASE_BASIC(alwaysBounceHorizontal);
@@ -444,16 +425,14 @@ void ScrollViewProps::setProp(
RAW_SET_PROP_SWITCH_CASE_BASIC(contentInsetAdjustmentBehavior);
RAW_SET_PROP_SWITCH_CASE_BASIC(scrollToOverflowEnabled);
RAW_SET_PROP_SWITCH_CASE_BASIC(isInvertedVirtualizedList);
RAW_SET_PROP_SWITCH_CASE_BASIC(sendMomentumEvents);
RAW_SET_PROP_SWITCH_CASE_BASIC(nestedScrollEnabled);
}
}
#pragma mark - DebugStringConvertible
#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList ScrollViewProps::getDebugProps() const {
auto defaultScrollViewProps = ScrollViewProps{};
SharedDebugStringConvertibleList BaseScrollViewProps::getDebugProps() const {
auto defaultScrollViewProps = BaseScrollViewProps{};
return ViewProps::getDebugProps() +
SharedDebugStringConvertibleList{
@@ -580,285 +559,8 @@ SharedDebugStringConvertibleList ScrollViewProps::getDebugProps() const {
debugStringConvertibleItem(
"isInvertedVirtualizedList",
snapToEnd,
defaultScrollViewProps.isInvertedVirtualizedList),
debugStringConvertibleItem(
"sendMomentumEvents",
sendMomentumEvents,
defaultScrollViewProps.sendMomentumEvents),
debugStringConvertibleItem(
"nestedScrollEnabled",
nestedScrollEnabled,
defaultScrollViewProps.nestedScrollEnabled)};
defaultScrollViewProps.isInvertedVirtualizedList)};
}
#endif
#ifdef RN_SERIALIZABLE_STATE
static folly::dynamic convertScrollViewMaintainVisibleContentPosition(
const ScrollViewMaintainVisibleContentPosition& value) {
folly::dynamic result = folly::dynamic::object();
result["minIndexForVisible"] = value.minIndexForVisible;
if (value.autoscrollToTopThreshold.has_value()) {
result["autoscrollToTopThreshold"] = value.autoscrollToTopThreshold.value();
}
return result;
}
static folly::dynamic convertEdgeInsets(const EdgeInsets& edgeInsets) {
folly::dynamic edgeInsetsResult = folly::dynamic::object();
edgeInsetsResult["left"] = edgeInsets.left;
edgeInsetsResult["top"] = edgeInsets.top;
edgeInsetsResult["right"] = edgeInsets.right;
edgeInsetsResult["bottom"] = edgeInsets.bottom;
return edgeInsetsResult;
}
static folly::dynamic convertPoint(const Point& point) {
folly::dynamic pointResult = folly::dynamic::object();
pointResult["y"] = point.y;
pointResult["x"] = point.x;
return pointResult;
}
folly::dynamic ScrollViewProps::getDiffProps(const Props* prevProps) const {
static const auto defaultProps = ScrollViewProps();
const ScrollViewProps* oldProps = prevProps == nullptr
? &defaultProps
: static_cast<const ScrollViewProps*>(prevProps);
folly::dynamic result = ViewProps::getDiffProps(oldProps);
if (alwaysBounceHorizontal != oldProps->alwaysBounceHorizontal) {
result["alwaysBounceHorizontal"] = alwaysBounceHorizontal;
}
if (alwaysBounceVertical != oldProps->alwaysBounceVertical) {
result["alwaysBounceVertical"] = alwaysBounceVertical;
}
if (bounces != oldProps->bounces) {
result["bounces"] = bounces;
}
if (bouncesZoom != oldProps->bouncesZoom) {
result["bouncesZoom"] = bouncesZoom;
}
if (canCancelContentTouches != oldProps->canCancelContentTouches) {
result["canCancelContentTouches"] = canCancelContentTouches;
}
if (centerContent != oldProps->centerContent) {
result["centerContent"] = centerContent;
}
if (automaticallyAdjustContentInsets !=
oldProps->automaticallyAdjustContentInsets) {
result["automaticallyAdjustContentInsets"] =
automaticallyAdjustContentInsets;
}
if (automaticallyAdjustsScrollIndicatorInsets !=
oldProps->automaticallyAdjustsScrollIndicatorInsets) {
result["automaticallyAdjustsScrollIndicatorInsets"] =
automaticallyAdjustsScrollIndicatorInsets;
}
if (automaticallyAdjustKeyboardInsets !=
oldProps->automaticallyAdjustKeyboardInsets) {
result["automaticallyAdjustKeyboardInsets"] =
automaticallyAdjustKeyboardInsets;
}
if (decelerationRate != oldProps->decelerationRate) {
result["decelerationRate"] = decelerationRate;
}
if (endDraggingSensitivityMultiplier !=
oldProps->endDraggingSensitivityMultiplier) {
result["endDraggingSensitivityMultiplier"] =
endDraggingSensitivityMultiplier;
}
if (directionalLockEnabled != oldProps->directionalLockEnabled) {
result["directionalLockEnabled"] = directionalLockEnabled;
}
if (indicatorStyle != oldProps->indicatorStyle) {
switch (indicatorStyle) {
case ScrollViewIndicatorStyle::Default:
result["indicatorStyle"] = "default";
break;
case ScrollViewIndicatorStyle::Black:
result["indicatorStyle"] = "black";
break;
case ScrollViewIndicatorStyle::White:
result["indicatorStyle"] = "white";
break;
}
}
if (keyboardDismissMode != oldProps->keyboardDismissMode) {
switch (keyboardDismissMode) {
case ScrollViewKeyboardDismissMode::None:
result["keyboardDismissMode"] = "none";
break;
case ScrollViewKeyboardDismissMode::OnDrag:
result["keyboardDismissMode"] = "on-drag";
break;
case ScrollViewKeyboardDismissMode::Interactive:
result["keyboardDismissMode"] = "interactive";
break;
}
}
if (maintainVisibleContentPosition !=
oldProps->maintainVisibleContentPosition) {
if (maintainVisibleContentPosition.has_value()) {
result["maintainVisibleContentPosition"] =
convertScrollViewMaintainVisibleContentPosition(
maintainVisibleContentPosition.value());
} else {
result["maintainVisibleContentPosition"] = folly::dynamic(nullptr);
}
}
if (maximumZoomScale != oldProps->maximumZoomScale) {
result["maximumZoomScale"] = maximumZoomScale;
}
if (minimumZoomScale != oldProps->minimumZoomScale) {
result["minimumZoomScale"] = minimumZoomScale;
}
if (scrollEnabled != oldProps->scrollEnabled) {
result["scrollEnabled"] = scrollEnabled;
}
if (pagingEnabled != oldProps->pagingEnabled) {
result["pagingEnabled"] = pagingEnabled;
}
if (pinchGestureEnabled != oldProps->pinchGestureEnabled) {
result["pinchGestureEnabled"] = pinchGestureEnabled;
}
if (scrollsToTop != oldProps->scrollsToTop) {
result["scrollsToTop"] = scrollsToTop;
}
if (showsHorizontalScrollIndicator !=
oldProps->showsHorizontalScrollIndicator) {
result["showsHorizontalScrollIndicator"] = showsHorizontalScrollIndicator;
}
if (showsVerticalScrollIndicator != oldProps->showsVerticalScrollIndicator) {
result["showsVerticalScrollIndicator"] = showsVerticalScrollIndicator;
}
if (persistentScrollbar != oldProps->persistentScrollbar) {
result["persistentScrollbar"] = persistentScrollbar;
}
if (horizontal != oldProps->horizontal) {
result["horizontal"] = horizontal;
}
if (scrollEventThrottle != oldProps->scrollEventThrottle) {
result["scrollEventThrottle"] = scrollEventThrottle;
}
if (zoomScale != oldProps->zoomScale) {
result["zoomScale"] = zoomScale;
}
if (contentInset != oldProps->contentInset) {
result["contentInset"] = convertEdgeInsets(contentInset);
}
if (contentOffset != oldProps->contentOffset) {
result["contentOffset"] = convertPoint(contentOffset);
}
if (scrollIndicatorInsets != oldProps->scrollIndicatorInsets) {
result["scrollIndicatorInsets"] = convertEdgeInsets(scrollIndicatorInsets);
}
if (snapToInterval != oldProps->snapToInterval) {
result["snapToInterval"] = snapToInterval;
}
if (snapToAlignment != oldProps->snapToAlignment) {
switch (snapToAlignment) {
case ScrollViewSnapToAlignment::Start:
result["snapToAlignment"] = "start";
break;
case ScrollViewSnapToAlignment::Center:
result["snapToAlignment"] = "center";
break;
case ScrollViewSnapToAlignment::End:
result["snapToAlignment"] = "end";
break;
}
}
if (disableIntervalMomentum != oldProps->disableIntervalMomentum) {
result["disableIntervalMomentum"] = disableIntervalMomentum;
}
if (snapToOffsets != oldProps->snapToOffsets) {
auto snapToOffsetsArray = folly::dynamic::array();
for (const auto& snapToOffset : snapToOffsets) {
snapToOffsetsArray.push_back(snapToOffset);
}
result["snapToOffsets"] = snapToOffsetsArray;
}
if (snapToStart != oldProps->snapToStart) {
result["snapToStart"] = snapToStart;
}
if (snapToEnd != oldProps->snapToEnd) {
result["snapToEnd"] = snapToEnd;
}
if (contentInsetAdjustmentBehavior !=
oldProps->contentInsetAdjustmentBehavior) {
switch (contentInsetAdjustmentBehavior) {
case ContentInsetAdjustmentBehavior::Never:
result["contentInsetAdjustmentBehavior"] = "never";
break;
case ContentInsetAdjustmentBehavior::Automatic:
result["contentInsetAdjustmentBehavior"] = "automatic";
break;
case ContentInsetAdjustmentBehavior::ScrollableAxes:
result["contentInsetAdjustmentBehavior"] = "scrollableAxes";
break;
case ContentInsetAdjustmentBehavior::Always:
result["contentInsetAdjustmentBehavior"] = "always";
break;
}
}
if (scrollToOverflowEnabled != oldProps->scrollToOverflowEnabled) {
result["scrollToOverflowEnabled"] = scrollToOverflowEnabled;
}
if (isInvertedVirtualizedList != oldProps->isInvertedVirtualizedList) {
result["isInvertedVirtualizedList"] = isInvertedVirtualizedList;
}
if (sendMomentumEvents != oldProps->sendMomentumEvents) {
result["sendMomentumEvents"] = sendMomentumEvents;
}
if (nestedScrollEnabled != oldProps->nestedScrollEnabled) {
result["nestedScrollEnabled"] = nestedScrollEnabled;
}
return result;
}
#endif
} // namespace facebook::react
@@ -0,0 +1,84 @@
/*
* 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 <react/renderer/components/scrollview/primitives.h>
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/PropsParserContext.h>
#include <optional>
namespace facebook::react {
// TODO (T28334063): Consider for codegen.
class BaseScrollViewProps : public ViewProps {
public:
BaseScrollViewProps() = default;
BaseScrollViewProps(
const PropsParserContext& context,
const BaseScrollViewProps& sourceProps,
const RawProps& rawProps);
void setProp(
const PropsParserContext& context,
RawPropsPropNameHash hash,
const char* propName,
const RawValue& value);
#pragma mark - Props
bool alwaysBounceHorizontal{};
bool alwaysBounceVertical{};
bool bounces{true};
bool bouncesZoom{true};
bool canCancelContentTouches{true};
bool centerContent{};
bool automaticallyAdjustContentInsets{};
bool automaticallyAdjustsScrollIndicatorInsets{true};
bool automaticallyAdjustKeyboardInsets{false};
Float decelerationRate{0.998f};
Float endDraggingSensitivityMultiplier{1};
bool directionalLockEnabled{};
ScrollViewIndicatorStyle indicatorStyle{};
ScrollViewKeyboardDismissMode keyboardDismissMode{};
std::optional<ScrollViewMaintainVisibleContentPosition>
maintainVisibleContentPosition{};
Float maximumZoomScale{1.0f};
Float minimumZoomScale{1.0f};
bool scrollEnabled{true};
bool pagingEnabled{};
bool pinchGestureEnabled{true};
bool scrollsToTop{true};
bool showsHorizontalScrollIndicator{true};
bool showsVerticalScrollIndicator{true};
bool persistentScrollbar{false};
bool horizontal{false};
Float scrollEventThrottle{};
Float zoomScale{1.0f};
EdgeInsets contentInset{};
Point contentOffset{};
EdgeInsets scrollIndicatorInsets{};
Float snapToInterval{};
ScrollViewSnapToAlignment snapToAlignment{};
bool disableIntervalMomentum{false};
std::vector<Float> snapToOffsets{};
bool snapToStart{true};
bool snapToEnd{true};
ContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior{
ContentInsetAdjustmentBehavior::Never};
bool scrollToOverflowEnabled{false};
bool isInvertedVirtualizedList{false};
#pragma mark - DebugStringConvertible
#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList getDebugProps() const override;
#endif
};
} // namespace facebook::react
@@ -13,6 +13,9 @@ add_library(rrc_scrollview STATIC ${rrc_scrollview_SRC})
target_include_directories(rrc_scrollview PUBLIC ${REACT_COMMON_DIR} . ${CMAKE_CURRENT_SOURCE_DIR}/platform/android/)
target_include_directories(rrc_scrollview PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/platform/android/react/renderer/components/scrollview/)
target_link_libraries(rrc_scrollview
glog
folly_runtime
@@ -7,85 +7,9 @@
#pragma once
#include <react/renderer/components/scrollview/primitives.h>
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/PropsParserContext.h>
#include <optional>
#include <react/renderer/components/scrollview/HostPlatformScrollViewProps.h>
namespace facebook::react {
// TODO (T28334063): Consider for codegen.
class ScrollViewProps final : public ViewProps {
public:
ScrollViewProps() = default;
ScrollViewProps(
const PropsParserContext& context,
const ScrollViewProps& sourceProps,
const RawProps& rawProps);
void setProp(
const PropsParserContext& context,
RawPropsPropNameHash hash,
const char* propName,
const RawValue& value);
#pragma mark - Props
bool alwaysBounceHorizontal{};
bool alwaysBounceVertical{};
bool bounces{true};
bool bouncesZoom{true};
bool canCancelContentTouches{true};
bool centerContent{};
bool automaticallyAdjustContentInsets{};
bool automaticallyAdjustsScrollIndicatorInsets{true};
bool automaticallyAdjustKeyboardInsets{false};
Float decelerationRate{0.998f};
Float endDraggingSensitivityMultiplier{1};
bool directionalLockEnabled{};
ScrollViewIndicatorStyle indicatorStyle{};
ScrollViewKeyboardDismissMode keyboardDismissMode{};
std::optional<ScrollViewMaintainVisibleContentPosition>
maintainVisibleContentPosition{};
Float maximumZoomScale{1.0f};
Float minimumZoomScale{1.0f};
bool scrollEnabled{true};
bool pagingEnabled{};
bool pinchGestureEnabled{true};
bool scrollsToTop{true};
bool showsHorizontalScrollIndicator{true};
bool showsVerticalScrollIndicator{true};
bool persistentScrollbar{false};
bool horizontal{false};
Float scrollEventThrottle{};
Float zoomScale{1.0f};
EdgeInsets contentInset{};
Point contentOffset{};
EdgeInsets scrollIndicatorInsets{};
Float snapToInterval{};
ScrollViewSnapToAlignment snapToAlignment{};
bool disableIntervalMomentum{false};
std::vector<Float> snapToOffsets{};
bool snapToStart{true};
bool snapToEnd{true};
ContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior{
ContentInsetAdjustmentBehavior::Never};
bool scrollToOverflowEnabled{false};
bool isInvertedVirtualizedList{false};
bool sendMomentumEvents{};
bool nestedScrollEnabled{};
#pragma mark - DebugStringConvertible
#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList getDebugProps() const override;
#endif
#ifdef RN_SERIALIZABLE_STATE
folly::dynamic getDiffProps(const Props* prevProps) const override;
#endif
};
using ScrollViewProps = HostPlatformScrollViewProps;
using SharedScrollViewProps = std::shared_ptr<const ScrollViewProps>;
} // namespace facebook::react
@@ -0,0 +1,349 @@
/*
* 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.
*/
#include "HostPlatformScrollViewProps.h"
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/renderer/components/scrollview/conversions.h>
#include <react/renderer/core/graphicsConversions.h>
#include <react/renderer/debug/debugStringConvertibleUtils.h>
#include <react/renderer/core/propsConversions.h>
namespace facebook::react {
HostPlatformScrollViewProps::HostPlatformScrollViewProps(
const PropsParserContext& context,
const HostPlatformScrollViewProps& sourceProps,
const RawProps& rawProps)
: BaseScrollViewProps(context, sourceProps, rawProps),
sendMomentumEvents(
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
? sourceProps.sendMomentumEvents
: convertRawProp(
context,
rawProps,
"sendMomentumEvents",
sourceProps.sendMomentumEvents,
true)),
nestedScrollEnabled(
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
? sourceProps.nestedScrollEnabled
: convertRawProp(
context,
rawProps,
"nestedScrollEnabled",
sourceProps.nestedScrollEnabled,
true))
{}
void HostPlatformScrollViewProps::setProp(
const PropsParserContext& context,
RawPropsPropNameHash hash,
const char* propName,
const RawValue& value) {
// All Props structs setProp methods must always, unconditionally,
// call all super::setProp methods, since multiple structs may
// reuse the same values.
BaseScrollViewProps::setProp(context, hash, propName, value);
static auto defaults = HostPlatformScrollViewProps{};
switch (hash) {
RAW_SET_PROP_SWITCH_CASE_BASIC(sendMomentumEvents);
RAW_SET_PROP_SWITCH_CASE_BASIC(nestedScrollEnabled);
}
}
#pragma mark - DebugStringConvertible
#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList HostPlatformScrollViewProps::getDebugProps()
const {
auto defaultScrollViewProps = HostPlatformScrollViewProps{};
return BaseScrollViewProps::getDebugProps() +
SharedDebugStringConvertibleList{
debugStringConvertibleItem(
"sendMomentumEvents",
sendMomentumEvents,
defaultScrollViewProps.sendMomentumEvents),
debugStringConvertibleItem(
"nestedScrollEnabled",
nestedScrollEnabled,
defaultScrollViewProps.nestedScrollEnabled)};
}
#endif
static folly::dynamic convertScrollViewMaintainVisibleContentPosition(
const ScrollViewMaintainVisibleContentPosition& value) {
folly::dynamic result = folly::dynamic::object();
result["minIndexForVisible"] = value.minIndexForVisible;
if (value.autoscrollToTopThreshold.has_value()) {
result["autoscrollToTopThreshold"] = value.autoscrollToTopThreshold.value();
}
return result;
}
static folly::dynamic convertEdgeInsets(const EdgeInsets& edgeInsets) {
folly::dynamic edgeInsetsResult = folly::dynamic::object();
edgeInsetsResult["left"] = edgeInsets.left;
edgeInsetsResult["top"] = edgeInsets.top;
edgeInsetsResult["right"] = edgeInsets.right;
edgeInsetsResult["bottom"] = edgeInsets.bottom;
return edgeInsetsResult;
}
static folly::dynamic convertPoint(const Point& point) {
folly::dynamic pointResult = folly::dynamic::object();
pointResult["y"] = point.y;
pointResult["x"] = point.x;
return pointResult;
}
folly::dynamic HostPlatformScrollViewProps::getDiffProps(
const Props* prevProps) const {
static const auto defaultProps = HostPlatformScrollViewProps();
const HostPlatformScrollViewProps* oldProps = prevProps == nullptr
? &defaultProps
: static_cast<const HostPlatformScrollViewProps*>(prevProps);
folly::dynamic result = ViewProps::getDiffProps(oldProps);
if (alwaysBounceHorizontal != oldProps->alwaysBounceHorizontal) {
result["alwaysBounceHorizontal"] = alwaysBounceHorizontal;
}
if (alwaysBounceVertical != oldProps->alwaysBounceVertical) {
result["alwaysBounceVertical"] = alwaysBounceVertical;
}
if (bounces != oldProps->bounces) {
result["bounces"] = bounces;
}
if (bouncesZoom != oldProps->bouncesZoom) {
result["bouncesZoom"] = bouncesZoom;
}
if (canCancelContentTouches != oldProps->canCancelContentTouches) {
result["canCancelContentTouches"] = canCancelContentTouches;
}
if (centerContent != oldProps->centerContent) {
result["centerContent"] = centerContent;
}
if (automaticallyAdjustContentInsets !=
oldProps->automaticallyAdjustContentInsets) {
result["automaticallyAdjustContentInsets"] =
automaticallyAdjustContentInsets;
}
if (automaticallyAdjustsScrollIndicatorInsets !=
oldProps->automaticallyAdjustsScrollIndicatorInsets) {
result["automaticallyAdjustsScrollIndicatorInsets"] =
automaticallyAdjustsScrollIndicatorInsets;
}
if (automaticallyAdjustKeyboardInsets !=
oldProps->automaticallyAdjustKeyboardInsets) {
result["automaticallyAdjustKeyboardInsets"] =
automaticallyAdjustKeyboardInsets;
}
if (decelerationRate != oldProps->decelerationRate) {
result["decelerationRate"] = decelerationRate;
}
if (endDraggingSensitivityMultiplier !=
oldProps->endDraggingSensitivityMultiplier) {
result["endDraggingSensitivityMultiplier"] =
endDraggingSensitivityMultiplier;
}
if (directionalLockEnabled != oldProps->directionalLockEnabled) {
result["directionalLockEnabled"] = directionalLockEnabled;
}
if (indicatorStyle != oldProps->indicatorStyle) {
switch (indicatorStyle) {
case ScrollViewIndicatorStyle::Default:
result["indicatorStyle"] = "default";
break;
case ScrollViewIndicatorStyle::Black:
result["indicatorStyle"] = "black";
break;
case ScrollViewIndicatorStyle::White:
result["indicatorStyle"] = "white";
break;
}
}
if (keyboardDismissMode != oldProps->keyboardDismissMode) {
switch (keyboardDismissMode) {
case ScrollViewKeyboardDismissMode::None:
result["keyboardDismissMode"] = "none";
break;
case ScrollViewKeyboardDismissMode::OnDrag:
result["keyboardDismissMode"] = "on-drag";
break;
case ScrollViewKeyboardDismissMode::Interactive:
result["keyboardDismissMode"] = "interactive";
break;
}
}
if (maintainVisibleContentPosition !=
oldProps->maintainVisibleContentPosition) {
if (maintainVisibleContentPosition.has_value()) {
result["maintainVisibleContentPosition"] =
convertScrollViewMaintainVisibleContentPosition(
maintainVisibleContentPosition.value());
} else {
result["maintainVisibleContentPosition"] = folly::dynamic(nullptr);
}
}
if (maximumZoomScale != oldProps->maximumZoomScale) {
result["maximumZoomScale"] = maximumZoomScale;
}
if (minimumZoomScale != oldProps->minimumZoomScale) {
result["minimumZoomScale"] = minimumZoomScale;
}
if (scrollEnabled != oldProps->scrollEnabled) {
result["scrollEnabled"] = scrollEnabled;
}
if (pagingEnabled != oldProps->pagingEnabled) {
result["pagingEnabled"] = pagingEnabled;
}
if (pinchGestureEnabled != oldProps->pinchGestureEnabled) {
result["pinchGestureEnabled"] = pinchGestureEnabled;
}
if (scrollsToTop != oldProps->scrollsToTop) {
result["scrollsToTop"] = scrollsToTop;
}
if (showsHorizontalScrollIndicator !=
oldProps->showsHorizontalScrollIndicator) {
result["showsHorizontalScrollIndicator"] = showsHorizontalScrollIndicator;
}
if (showsVerticalScrollIndicator != oldProps->showsVerticalScrollIndicator) {
result["showsVerticalScrollIndicator"] = showsVerticalScrollIndicator;
}
if (persistentScrollbar != oldProps->persistentScrollbar) {
result["persistentScrollbar"] = persistentScrollbar;
}
if (horizontal != oldProps->horizontal) {
result["horizontal"] = horizontal;
}
if (scrollEventThrottle != oldProps->scrollEventThrottle) {
result["scrollEventThrottle"] = scrollEventThrottle;
}
if (zoomScale != oldProps->zoomScale) {
result["zoomScale"] = zoomScale;
}
if (contentInset != oldProps->contentInset) {
result["contentInset"] = convertEdgeInsets(contentInset);
}
if (contentOffset != oldProps->contentOffset) {
result["contentOffset"] = convertPoint(contentOffset);
}
if (scrollIndicatorInsets != oldProps->scrollIndicatorInsets) {
result["scrollIndicatorInsets"] = convertEdgeInsets(scrollIndicatorInsets);
}
if (snapToInterval != oldProps->snapToInterval) {
result["snapToInterval"] = snapToInterval;
}
if (snapToAlignment != oldProps->snapToAlignment) {
switch (snapToAlignment) {
case ScrollViewSnapToAlignment::Start:
result["snapToAlignment"] = "start";
break;
case ScrollViewSnapToAlignment::Center:
result["snapToAlignment"] = "center";
break;
case ScrollViewSnapToAlignment::End:
result["snapToAlignment"] = "end";
break;
}
}
if (disableIntervalMomentum != oldProps->disableIntervalMomentum) {
result["disableIntervalMomentum"] = disableIntervalMomentum;
}
if (snapToOffsets != oldProps->snapToOffsets) {
auto snapToOffsetsArray = folly::dynamic::array();
for (const auto& snapToOffset : snapToOffsets) {
snapToOffsetsArray.push_back(snapToOffset);
}
result["snapToOffsets"] = snapToOffsetsArray;
}
if (snapToStart != oldProps->snapToStart) {
result["snapToStart"] = snapToStart;
}
if (snapToEnd != oldProps->snapToEnd) {
result["snapToEnd"] = snapToEnd;
}
if (contentInsetAdjustmentBehavior !=
oldProps->contentInsetAdjustmentBehavior) {
switch (contentInsetAdjustmentBehavior) {
case ContentInsetAdjustmentBehavior::Never:
result["contentInsetAdjustmentBehavior"] = "never";
break;
case ContentInsetAdjustmentBehavior::Automatic:
result["contentInsetAdjustmentBehavior"] = "automatic";
break;
case ContentInsetAdjustmentBehavior::ScrollableAxes:
result["contentInsetAdjustmentBehavior"] = "scrollableAxes";
break;
case ContentInsetAdjustmentBehavior::Always:
result["contentInsetAdjustmentBehavior"] = "always";
break;
}
}
if (scrollToOverflowEnabled != oldProps->scrollToOverflowEnabled) {
result["scrollToOverflowEnabled"] = scrollToOverflowEnabled;
}
if (isInvertedVirtualizedList != oldProps->isInvertedVirtualizedList) {
result["isInvertedVirtualizedList"] = isInvertedVirtualizedList;
}
if (sendMomentumEvents != oldProps->sendMomentumEvents) {
result["sendMomentumEvents"] = sendMomentumEvents;
}
if (nestedScrollEnabled != oldProps->nestedScrollEnabled) {
result["nestedScrollEnabled"] = nestedScrollEnabled;
}
return result;
}
} // namespace facebook::react
@@ -0,0 +1,45 @@
/*
* 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 <react/renderer/components/scrollview/BaseScrollViewProps.h>
#include <react/renderer/components/scrollview/primitives.h>
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/PropsParserContext.h>
namespace facebook::react {
class HostPlatformScrollViewProps final : public BaseScrollViewProps {
public:
HostPlatformScrollViewProps() = default;
HostPlatformScrollViewProps(
const PropsParserContext& context,
const HostPlatformScrollViewProps& sourceProps,
const RawProps& rawProps);
void setProp(
const PropsParserContext& context,
RawPropsPropNameHash hash,
const char* propName,
const RawValue& value);
#pragma mark - Props
bool sendMomentumEvents{};
bool nestedScrollEnabled{};
#pragma mark - DebugStringConvertible
#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList getDebugProps() const override;
#endif
folly::dynamic getDiffProps(const Props* prevProps) const override;
};
} // namespace facebook::react
@@ -0,0 +1,14 @@
/*
* 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 <react/renderer/components/scrollview/BaseScrollViewProps.h>
namespace facebook::react {
using HostPlatformScrollViewProps = BaseScrollViewProps;
} // namespace facebook::react