Skip to content

Commit 07869fd

Browse files
committed
Revert "[Fabric] Implement snapToInterval property for ScrollView (microsoft#14847)"
This reverts commit 2cde3f1.
1 parent 72ebc77 commit 07869fd

File tree

2 files changed

+5
-54
lines changed

2 files changed

+5
-54
lines changed

vnext/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
namespace winrt::Microsoft::ReactNative::Composition::implementation {
2828

2929
constexpr float c_scrollerLineDelta = 16.0f;
30-
constexpr auto c_maxSnapPoints = 1000;
3130

3231
enum class ScrollbarHitRegion : int {
3332
Unknown = -1,
@@ -741,15 +740,6 @@ void ScrollViewComponentView::updateBackgroundColor(const facebook::react::Share
741740
}
742741
}
743742

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-
753743
void ScrollViewComponentView::updateProps(
754744
facebook::react::Props::Shared const &props,
755745
facebook::react::Props::Shared const &oldProps) noexcept {
@@ -817,17 +807,12 @@ void ScrollViewComponentView::updateProps(
817807
}
818808

819809
if (oldViewProps.snapToStart != newViewProps.snapToStart || oldViewProps.snapToEnd != newViewProps.snapToEnd ||
820-
oldViewProps.snapToOffsets != newViewProps.snapToOffsets ||
821-
oldViewProps.snapToInterval != newViewProps.snapToInterval) {
822-
if ((newViewProps.snapToInterval > 0 || oldViewProps.snapToInterval != newViewProps.snapToInterval) &&
823-
(newViewProps.decelerationRate >= 0.99)) {
824-
// Use the comprehensive updateSnapPoints method when snapToInterval is involved
825-
// Typically used in combination with snapToAlignment and decelerationRate="fast".
826-
updateSnapPoints();
827-
} else {
828-
auto snapToOffsets = CreateSnapToOffsets(newViewProps.snapToOffsets);
829-
m_scrollVisual.SetSnapPoints(newViewProps.snapToStart, newViewProps.snapToEnd, snapToOffsets.GetView());
810+
oldViewProps.snapToOffsets != newViewProps.snapToOffsets) {
811+
const auto snapToOffsets = winrt::single_threaded_vector<float>();
812+
for (const auto &offset : newViewProps.snapToOffsets) {
813+
snapToOffsets.Append(static_cast<float>(offset));
830814
}
815+
m_scrollVisual.SetSnapPoints(newViewProps.snapToStart, newViewProps.snapToEnd, snapToOffsets.GetView());
831816
}
832817
}
833818

@@ -878,9 +863,6 @@ void ScrollViewComponentView::updateContentVisualSize() noexcept {
878863
m_verticalScrollbarComponent->ContentSize(contentSize);
879864
m_horizontalScrollbarComponent->ContentSize(contentSize);
880865
m_scrollVisual.ContentSize(contentSize);
881-
882-
// Update snap points if snapToInterval is being used, as content size affects the number of snap points
883-
updateSnapPoints();
884866
}
885867

886868
void ScrollViewComponentView::prepareForRecycle() noexcept {}
@@ -1453,33 +1435,4 @@ void ScrollViewComponentView::updateShowsVerticalScrollIndicator(bool value) noe
14531435
void ScrollViewComponentView::updateDecelerationRate(float value) noexcept {
14541436
m_scrollVisual.SetDecelerationRate({value, value, value});
14551437
}
1456-
1457-
void ScrollViewComponentView::updateSnapPoints() noexcept {
1458-
const auto &viewProps = *std::static_pointer_cast<const facebook::react::ScrollViewProps>(this->viewProps());
1459-
const auto snapToOffsets = CreateSnapToOffsets(viewProps.snapToOffsets);
1460-
1461-
// snapToOffsets has priority over snapToInterval (matches React Native behavior)
1462-
if (viewProps.snapToInterval > 0) {
1463-
// Generate snap points based on interval
1464-
// Calculate the content size to determine how many intervals to create
1465-
float contentLength = viewProps.horizontal
1466-
? std::max(m_contentSize.width, m_layoutMetrics.frame.size.width) * m_layoutMetrics.pointScaleFactor
1467-
: std::max(m_contentSize.height, m_layoutMetrics.frame.size.height) * m_layoutMetrics.pointScaleFactor;
1468-
1469-
float interval = static_cast<float>(viewProps.snapToInterval) * m_layoutMetrics.pointScaleFactor;
1470-
1471-
// Ensure we have a reasonable minimum interval to avoid infinite loops or excessive memory usage
1472-
if (interval >= 1.0f && contentLength > 0) {
1473-
// Generate offsets at each interval, but limit the number of snap points to avoid excessive memory usage
1474-
int snapPointCount = 0;
1475-
1476-
for (float offset = 0; offset <= contentLength && snapPointCount < c_maxSnapPoints; offset += interval) {
1477-
snapToOffsets.Append(offset);
1478-
snapPointCount++;
1479-
}
1480-
}
1481-
}
1482-
1483-
m_scrollVisual.SetSnapPoints(viewProps.snapToStart, viewProps.snapToEnd, snapToOffsets.GetView());
1484-
}
14851438
} // namespace winrt::Microsoft::ReactNative::Composition::implementation

vnext/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
121121
private:
122122
void updateDecelerationRate(float value) noexcept;
123123
void updateContentVisualSize() noexcept;
124-
void updateSnapPoints() noexcept;
125124
bool scrollToEnd(bool animate) noexcept;
126125
bool scrollToStart(bool animate) noexcept;
127126
bool scrollDown(float delta, bool animate) noexcept;
@@ -135,7 +134,6 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
135134
winrt::Microsoft::ReactNative::Composition::Experimental::IScrollPositionChangedArgs const &args) noexcept;
136135
void updateShowsHorizontalScrollIndicator(bool value) noexcept;
137136
void updateShowsVerticalScrollIndicator(bool value) noexcept;
138-
winrt::Windows::Foundation::Collections::IVector<float> CreateSnapToOffsets(const std::vector<float> &offsets);
139137

140138
facebook::react::Size m_contentSize;
141139
winrt::Microsoft::ReactNative::Composition::Experimental::IScrollVisual m_scrollVisual{nullptr};

0 commit comments

Comments
 (0)