diff --git a/packages/react-native/React/React-RCTFabric.podspec b/packages/react-native/React/React-RCTFabric.podspec index 9fe3dfc3a89..0cd588c605e 100644 --- a/packages/react-native/React/React-RCTFabric.podspec +++ b/packages/react-native/React/React-RCTFabric.podspec @@ -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", ]); diff --git a/packages/react-native/ReactCommon/React-Fabric.podspec b/packages/react-native/ReactCommon/React-Fabric.podspec index b8b27980caf..7a9f67c74ae 100644 --- a/packages/react-native/ReactCommon/React-Fabric.podspec +++ b/packages/react-native/ReactCommon/React-Fabric.podspec @@ -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| diff --git a/packages/react-native/ReactCommon/React-FabricComponents.podspec b/packages/react-native/ReactCommon/React-FabricComponents.podspec index 2fec9d25ccb..f83631b2491 100644 --- a/packages/react-native/ReactCommon/React-FabricComponents.podspec +++ b/packages/react-native/ReactCommon/React-FabricComponents.podspec @@ -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 diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/scrollview/BaseScrollViewProps.cpp similarity index 69% rename from packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp rename to packages/react-native/ReactCommon/react/renderer/components/scrollview/BaseScrollViewProps.cpp index ecb5898c91b..a62c9f1bc99 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/BaseScrollViewProps.cpp @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -#include "ScrollViewProps.h" +#include "BaseScrollViewProps.h" #include #include @@ -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(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 diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/BaseScrollViewProps.h b/packages/react-native/ReactCommon/react/renderer/components/scrollview/BaseScrollViewProps.h new file mode 100644 index 00000000000..0ea853b9b36 --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/BaseScrollViewProps.h @@ -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 +#include +#include + +#include + +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 + 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 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 diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/CMakeLists.txt b/packages/react-native/ReactCommon/react/renderer/components/scrollview/CMakeLists.txt index 74e601543f4..88188e50c2b 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/scrollview/CMakeLists.txt +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/CMakeLists.txt @@ -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 diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.h b/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.h index 79fff61345a..4d551b5ea44 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.h @@ -7,85 +7,9 @@ #pragma once -#include -#include -#include - -#include +#include 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 - 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 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; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/platform/android/react/renderer/components/scrollview/HostPlatformScrollViewProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/scrollview/platform/android/react/renderer/components/scrollview/HostPlatformScrollViewProps.cpp new file mode 100644 index 00000000000..71dec44b64e --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/platform/android/react/renderer/components/scrollview/HostPlatformScrollViewProps.cpp @@ -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 +#include +#include +#include + +#include + +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(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 diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/platform/android/react/renderer/components/scrollview/HostPlatformScrollViewProps.h b/packages/react-native/ReactCommon/react/renderer/components/scrollview/platform/android/react/renderer/components/scrollview/HostPlatformScrollViewProps.h new file mode 100644 index 00000000000..d62179a62b8 --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/platform/android/react/renderer/components/scrollview/HostPlatformScrollViewProps.h @@ -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 +#include +#include +#include + +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 diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/platform/cxx/react/renderer/components/scrollview/HostPlatformScrollViewProps.h b/packages/react-native/ReactCommon/react/renderer/components/scrollview/platform/cxx/react/renderer/components/scrollview/HostPlatformScrollViewProps.h new file mode 100644 index 00000000000..6eaa3d29d9f --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/platform/cxx/react/renderer/components/scrollview/HostPlatformScrollViewProps.h @@ -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 + +namespace facebook::react { +using HostPlatformScrollViewProps = BaseScrollViewProps; +} // namespace facebook::react