|
27 | 27 | namespace winrt::Microsoft::ReactNative::Composition::implementation { |
28 | 28 |
|
29 | 29 | constexpr float c_scrollerLineDelta = 16.0f; |
30 | | -constexpr auto c_maxSnapPoints = 1000; |
31 | 30 |
|
32 | 31 | enum class ScrollbarHitRegion : int { |
33 | 32 | Unknown = -1, |
@@ -741,15 +740,6 @@ void ScrollViewComponentView::updateBackgroundColor(const facebook::react::Share |
741 | 740 | } |
742 | 741 | } |
743 | 742 |
|
744 | | -winrt::Windows::Foundation::Collections::IVector<float> ScrollViewComponentView::CreateSnapToOffsets( |
745 | | - const std::vector<float> &offsets) { |
746 | | - auto snapToOffsets = winrt::single_threaded_vector<float>(); |
747 | | - for (const auto &offset : offsets) { |
748 | | - snapToOffsets.Append(offset); |
749 | | - } |
750 | | - return snapToOffsets; |
751 | | -} |
752 | | - |
753 | 743 | void ScrollViewComponentView::updateProps( |
754 | 744 | facebook::react::Props::Shared const &props, |
755 | 745 | facebook::react::Props::Shared const &oldProps) noexcept { |
@@ -818,13 +808,11 @@ void ScrollViewComponentView::updateProps( |
818 | 808 |
|
819 | 809 | if (oldViewProps.snapToStart != newViewProps.snapToStart || oldViewProps.snapToEnd != newViewProps.snapToEnd || |
820 | 810 | oldViewProps.snapToOffsets != newViewProps.snapToOffsets) { |
821 | | - if (oldViewProps.snapToInterval != newViewProps.snapToInterval) { |
822 | | - updateSnapPoints(); |
823 | | - } else { |
824 | | - const auto snapToOffsets = CreateSnapToOffsets(newViewProps.snapToOffsets); |
825 | | - m_scrollVisual.SetSnapPoints( |
826 | | - newViewProps.snapToStart, newViewProps.snapToEnd, snapToOffsets.GetView(), SnapAlignment::Center); |
| 811 | + const auto snapToOffsets = winrt::single_threaded_vector<float>(); |
| 812 | + for (const auto &offset : newViewProps.snapToOffsets) { |
| 813 | + snapToOffsets.Append(static_cast<float>(offset)); |
827 | 814 | } |
| 815 | + m_scrollVisual.SetSnapPoints(newViewProps.snapToStart, newViewProps.snapToEnd, snapToOffsets.GetView()); |
828 | 816 | } |
829 | 817 | } |
830 | 818 |
|
@@ -875,9 +863,6 @@ void ScrollViewComponentView::updateContentVisualSize() noexcept { |
875 | 863 | m_verticalScrollbarComponent->ContentSize(contentSize); |
876 | 864 | m_horizontalScrollbarComponent->ContentSize(contentSize); |
877 | 865 | m_scrollVisual.ContentSize(contentSize); |
878 | | - |
879 | | - // Update snap points if snapToInterval is being used, as content size affects the number of snap points |
880 | | - updateSnapPoints(); |
881 | 866 | } |
882 | 867 |
|
883 | 868 | void ScrollViewComponentView::prepareForRecycle() noexcept {} |
@@ -1476,50 +1461,4 @@ void ScrollViewComponentView::updateShowsVerticalScrollIndicator(bool value) noe |
1476 | 1461 | void ScrollViewComponentView::updateDecelerationRate(float value) noexcept { |
1477 | 1462 | m_scrollVisual.SetDecelerationRate({value, value, value}); |
1478 | 1463 | } |
1479 | | - |
1480 | | -SnapAlignment ScrollViewComponentView::convertSnapToAlignment( |
1481 | | - facebook::react::ScrollViewSnapToAlignment alignment) noexcept { |
1482 | | - switch (alignment) { |
1483 | | - case facebook::react::ScrollViewSnapToAlignment::Center: |
1484 | | - return SnapAlignment::Center; |
1485 | | - case facebook::react::ScrollViewSnapToAlignment::End: |
1486 | | - return SnapAlignment::End; |
1487 | | - case facebook::react::ScrollViewSnapToAlignment::Start: |
1488 | | - default: |
1489 | | - return SnapAlignment::Start; |
1490 | | - } |
1491 | | -} |
1492 | | - |
1493 | | -void ScrollViewComponentView::updateSnapPoints() noexcept { |
1494 | | - const auto &viewProps = *std::static_pointer_cast<const facebook::react::ScrollViewProps>(this->viewProps()); |
1495 | | - const auto snapToOffsets = CreateSnapToOffsets(viewProps.snapToOffsets); |
1496 | | - // Typically used in combination with snapToAlignment and decelerationRate="fast" |
1497 | | - auto snapAlignment = SnapAlignment::Center; |
1498 | | - auto decelerationRate = viewProps.decelerationRate; |
1499 | | - |
1500 | | - // snapToOffsets has priority over snapToInterval (matches React Native behavior) |
1501 | | - if (viewProps.snapToInterval > 0 && decelerationRate >= 0.99) { |
1502 | | - snapAlignment = convertSnapToAlignment(viewProps.snapToAlignment); |
1503 | | - // Generate snap points based on interval |
1504 | | - // Calculate the content size to determine how many intervals to create |
1505 | | - float contentLength = viewProps.horizontal |
1506 | | - ? std::max(m_contentSize.width, m_layoutMetrics.frame.size.width) * m_layoutMetrics.pointScaleFactor |
1507 | | - : std::max(m_contentSize.height, m_layoutMetrics.frame.size.height) * m_layoutMetrics.pointScaleFactor; |
1508 | | - |
1509 | | - float interval = static_cast<float>(viewProps.snapToInterval) * m_layoutMetrics.pointScaleFactor; |
1510 | | - |
1511 | | - // Ensure we have a reasonable minimum interval to avoid infinite loops or excessive memory usage |
1512 | | - if (interval >= 1.0f && contentLength > 0) { |
1513 | | - // Generate offsets at each interval, but limit the number of snap points to avoid excessive memory usage |
1514 | | - int snapPointCount = 0; |
1515 | | - |
1516 | | - for (float offset = 0; offset <= contentLength && snapPointCount < c_maxSnapPoints; offset += interval) { |
1517 | | - snapToOffsets.Append(offset); |
1518 | | - snapPointCount++; |
1519 | | - } |
1520 | | - } |
1521 | | - } |
1522 | | - |
1523 | | - m_scrollVisual.SetSnapPoints(viewProps.snapToStart, viewProps.snapToEnd, snapToOffsets.GetView(), snapAlignment); |
1524 | | -} |
1525 | 1464 | } // namespace winrt::Microsoft::ReactNative::Composition::implementation |
0 commit comments