Skip to content

Commit 63e9eaa

Browse files
authored
Revert commits to fix ScrollView regression (#15182)
* Revert "[Fabric] Implement snapToAlignment property for ScrollView (#14841)" This reverts commit 6bd0793. * Revert "[Fabric] Implement snapToInterval property for ScrollView (#14847)" This reverts commit 2cde3f1. * Change files
1 parent 355a8da commit 63e9eaa

File tree

5 files changed

+13
-100
lines changed

5 files changed

+13
-100
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Revert \"[Fabric] Implement snapToInterval property for ScrollView (#14847)\"",
4+
"packageName": "react-native-windows",
5+
"email": "54227869+anupriya13@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative/CompositionSwitcher.idl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ namespace Microsoft.ReactNative.Composition.Experimental
3131
SwitchThumb,
3232
};
3333

34-
enum SnapAlignment
35-
{
36-
Start,
37-
Center,
38-
End,
39-
};
40-
4134
[webhosthidden]
4235
[uuid("172def51-9e1a-4e3c-841a-e5a470065acc")] // uuid needed for empty interfaces
4336
[version(0)]
@@ -129,7 +122,7 @@ namespace Microsoft.ReactNative.Composition.Experimental
129122
void SetMaximumZoomScale(Single maximumZoomScale);
130123
void SetMinimumZoomScale(Single minimumZoomScale);
131124
Boolean Horizontal;
132-
void SetSnapPoints(Boolean snapToStart, Boolean snapToEnd, Windows.Foundation.Collections.IVectorView<Single> offsets, SnapAlignment snapToAlignment);
125+
void SetSnapPoints(Boolean snapToStart, Boolean snapToEnd, Windows.Foundation.Collections.IVectorView<Single> offsets);
133126
}
134127

135128
[webhosthidden]

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

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
namespace Microsoft::ReactNative::Composition::Experimental {
2929

30-
using namespace winrt::Microsoft::ReactNative::Composition::Experimental;
31-
3230
template <typename TSpriteVisual>
3331
struct CompositionTypeTraits {};
3432

@@ -903,11 +901,9 @@ struct CompScrollerVisual : winrt::implements<
903901
void SetSnapPoints(
904902
bool snapToStart,
905903
bool snapToEnd,
906-
winrt::Windows::Foundation::Collections::IVectorView<float> const &offsets,
907-
SnapAlignment snapToAlignment) noexcept {
904+
winrt::Windows::Foundation::Collections::IVectorView<float> const &offsets) noexcept {
908905
m_snapToStart = snapToStart;
909906
m_snapToEnd = snapToEnd;
910-
m_snapToAlignment = snapToAlignment;
911907
m_snapToOffsets.clear();
912908
if (offsets) {
913909
for (auto const &offset : offsets) {
@@ -1164,22 +1160,6 @@ struct CompScrollerVisual : winrt::implements<
11641160
}
11651161

11661162
snapPositions.insert(snapPositions.end(), m_snapToOffsets.begin(), m_snapToOffsets.end());
1167-
1168-
// Adjust snap positions based on alignment
1169-
const float viewportSize = m_horizontal ? visualSize.x : visualSize.y;
1170-
if (m_snapToAlignment == SnapAlignment::Center) {
1171-
// For center alignment, offset snap positions by half the viewport size
1172-
for (auto &position : snapPositions) {
1173-
position = std::max(0.0f, position - viewportSize / 2.0f);
1174-
}
1175-
} else if (m_snapToAlignment == SnapAlignment::End) {
1176-
// For end alignment, offset snap positions by the full viewport size
1177-
for (auto &position : snapPositions) {
1178-
position = std::max(0.0f, position - viewportSize);
1179-
}
1180-
}
1181-
// For Start alignment, no adjustment needed
1182-
11831163
std::sort(snapPositions.begin(), snapPositions.end());
11841164
snapPositions.erase(std::unique(snapPositions.begin(), snapPositions.end()), snapPositions.end());
11851165

@@ -1307,7 +1287,6 @@ struct CompScrollerVisual : winrt::implements<
13071287
bool m_snapToStart{true};
13081288
bool m_snapToEnd{true};
13091289
std::vector<float> m_snapToOffsets;
1310-
SnapAlignment m_snapToAlignment{SnapAlignment::Start};
13111290
bool m_inertia{false};
13121291
bool m_custom{false};
13131292
bool m_interacting{false};

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

Lines changed: 4 additions & 65 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 {
@@ -818,13 +808,11 @@ void ScrollViewComponentView::updateProps(
818808

819809
if (oldViewProps.snapToStart != newViewProps.snapToStart || oldViewProps.snapToEnd != newViewProps.snapToEnd ||
820810
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));
827814
}
815+
m_scrollVisual.SetSnapPoints(newViewProps.snapToStart, newViewProps.snapToEnd, snapToOffsets.GetView());
828816
}
829817
}
830818

@@ -875,9 +863,6 @@ void ScrollViewComponentView::updateContentVisualSize() noexcept {
875863
m_verticalScrollbarComponent->ContentSize(contentSize);
876864
m_horizontalScrollbarComponent->ContentSize(contentSize);
877865
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();
881866
}
882867

883868
void ScrollViewComponentView::prepareForRecycle() noexcept {}
@@ -1476,50 +1461,4 @@ void ScrollViewComponentView::updateShowsVerticalScrollIndicator(bool value) noe
14761461
void ScrollViewComponentView::updateDecelerationRate(float value) noexcept {
14771462
m_scrollVisual.SetDecelerationRate({value, value, value});
14781463
}
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-
}
15251464
} // namespace winrt::Microsoft::ReactNative::Composition::implementation

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
namespace winrt::Microsoft::ReactNative::Composition::implementation {
2020

21-
using namespace Microsoft::ReactNative::Composition::Experimental;
22-
2321
struct ScrollBarComponent;
2422

2523
struct ScrollViewComponentView : ScrollViewComponentViewT<ScrollViewComponentView, ViewComponentView> {
@@ -123,7 +121,6 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
123121
private:
124122
void updateDecelerationRate(float value) noexcept;
125123
void updateContentVisualSize() noexcept;
126-
void updateSnapPoints() noexcept;
127124
bool scrollToEnd(bool animate) noexcept;
128125
bool scrollToStart(bool animate) noexcept;
129126
bool scrollDown(float delta, bool animate) noexcept;
@@ -137,8 +134,6 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
137134
winrt::Microsoft::ReactNative::Composition::Experimental::IScrollPositionChangedArgs const &args) noexcept;
138135
void updateShowsHorizontalScrollIndicator(bool value) noexcept;
139136
void updateShowsVerticalScrollIndicator(bool value) noexcept;
140-
SnapAlignment convertSnapToAlignment(facebook::react::ScrollViewSnapToAlignment alignment) noexcept;
141-
winrt::Windows::Foundation::Collections::IVector<float> CreateSnapToOffsets(const std::vector<float> &offsets);
142137

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

0 commit comments

Comments
 (0)