Skip to content

Commit 72ebc77

Browse files
committed
Revert "[Fabric] Implement snapToAlignment property for ScrollView (microsoft#14841)"
This reverts commit 6bd0793.
1 parent 853633a commit 72ebc77

File tree

4 files changed

+12
-57
lines changed

4 files changed

+12
-57
lines changed

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)]
@@ -127,7 +120,7 @@ namespace Microsoft.ReactNative.Composition.Experimental
127120
void SetMaximumZoomScale(Single maximumZoomScale);
128121
void SetMinimumZoomScale(Single minimumZoomScale);
129122
Boolean Horizontal;
130-
void SetSnapPoints(Boolean snapToStart, Boolean snapToEnd, Windows.Foundation.Collections.IVectorView<Single> offsets, SnapAlignment snapToAlignment);
123+
void SetSnapPoints(Boolean snapToStart, Boolean snapToEnd, Windows.Foundation.Collections.IVectorView<Single> offsets);
131124
}
132125

133126
[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

@@ -873,11 +871,9 @@ struct CompScrollerVisual : winrt::implements<
873871
void SetSnapPoints(
874872
bool snapToStart,
875873
bool snapToEnd,
876-
winrt::Windows::Foundation::Collections::IVectorView<float> const &offsets,
877-
SnapAlignment snapToAlignment) noexcept {
874+
winrt::Windows::Foundation::Collections::IVectorView<float> const &offsets) noexcept {
878875
m_snapToStart = snapToStart;
879876
m_snapToEnd = snapToEnd;
880-
m_snapToAlignment = snapToAlignment;
881877
m_snapToOffsets.clear();
882878
if (offsets) {
883879
for (auto const &offset : offsets) {
@@ -1104,22 +1100,6 @@ struct CompScrollerVisual : winrt::implements<
11041100
}
11051101

11061102
snapPositions.insert(snapPositions.end(), m_snapToOffsets.begin(), m_snapToOffsets.end());
1107-
1108-
// Adjust snap positions based on alignment
1109-
const float viewportSize = m_horizontal ? visualSize.x : visualSize.y;
1110-
if (m_snapToAlignment == SnapAlignment::Center) {
1111-
// For center alignment, offset snap positions by half the viewport size
1112-
for (auto &position : snapPositions) {
1113-
position = std::max(0.0f, position - viewportSize / 2.0f);
1114-
}
1115-
} else if (m_snapToAlignment == SnapAlignment::End) {
1116-
// For end alignment, offset snap positions by the full viewport size
1117-
for (auto &position : snapPositions) {
1118-
position = std::max(0.0f, position - viewportSize);
1119-
}
1120-
}
1121-
// For Start alignment, no adjustment needed
1122-
11231103
std::sort(snapPositions.begin(), snapPositions.end());
11241104
snapPositions.erase(std::unique(snapPositions.begin(), snapPositions.end()), snapPositions.end());
11251105

@@ -1247,7 +1227,6 @@ struct CompScrollerVisual : winrt::implements<
12471227
bool m_snapToStart{true};
12481228
bool m_snapToEnd{true};
12491229
std::vector<float> m_snapToOffsets;
1250-
SnapAlignment m_snapToAlignment{SnapAlignment::Start};
12511230
bool m_inertia{false};
12521231
bool m_custom{false};
12531232
winrt::Windows::Foundation::Numerics::float3 m_targetPosition;

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

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -817,13 +817,16 @@ void ScrollViewComponentView::updateProps(
817817
}
818818

819819
if (oldViewProps.snapToStart != newViewProps.snapToStart || oldViewProps.snapToEnd != newViewProps.snapToEnd ||
820-
oldViewProps.snapToOffsets != newViewProps.snapToOffsets) {
821-
if (oldViewProps.snapToInterval != newViewProps.snapToInterval) {
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".
822826
updateSnapPoints();
823827
} else {
824-
const auto snapToOffsets = CreateSnapToOffsets(newViewProps.snapToOffsets);
825-
m_scrollVisual.SetSnapPoints(
826-
newViewProps.snapToStart, newViewProps.snapToEnd, snapToOffsets.GetView(), SnapAlignment::Center);
828+
auto snapToOffsets = CreateSnapToOffsets(newViewProps.snapToOffsets);
829+
m_scrollVisual.SetSnapPoints(newViewProps.snapToStart, newViewProps.snapToEnd, snapToOffsets.GetView());
827830
}
828831
}
829832
}
@@ -1451,29 +1454,12 @@ void ScrollViewComponentView::updateDecelerationRate(float value) noexcept {
14511454
m_scrollVisual.SetDecelerationRate({value, value, value});
14521455
}
14531456

1454-
SnapAlignment ScrollViewComponentView::convertSnapToAlignment(
1455-
facebook::react::ScrollViewSnapToAlignment alignment) noexcept {
1456-
switch (alignment) {
1457-
case facebook::react::ScrollViewSnapToAlignment::Center:
1458-
return SnapAlignment::Center;
1459-
case facebook::react::ScrollViewSnapToAlignment::End:
1460-
return SnapAlignment::End;
1461-
case facebook::react::ScrollViewSnapToAlignment::Start:
1462-
default:
1463-
return SnapAlignment::Start;
1464-
}
1465-
}
1466-
14671457
void ScrollViewComponentView::updateSnapPoints() noexcept {
14681458
const auto &viewProps = *std::static_pointer_cast<const facebook::react::ScrollViewProps>(this->viewProps());
14691459
const auto snapToOffsets = CreateSnapToOffsets(viewProps.snapToOffsets);
1470-
// Typically used in combination with snapToAlignment and decelerationRate="fast"
1471-
auto snapAlignment = SnapAlignment::Center;
1472-
auto decelerationRate = viewProps.decelerationRate;
14731460

14741461
// snapToOffsets has priority over snapToInterval (matches React Native behavior)
1475-
if (viewProps.snapToInterval > 0 && decelerationRate >= 0.99) {
1476-
snapAlignment = convertSnapToAlignment(viewProps.snapToAlignment);
1462+
if (viewProps.snapToInterval > 0) {
14771463
// Generate snap points based on interval
14781464
// Calculate the content size to determine how many intervals to create
14791465
float contentLength = viewProps.horizontal
@@ -1494,6 +1480,6 @@ void ScrollViewComponentView::updateSnapPoints() noexcept {
14941480
}
14951481
}
14961482

1497-
m_scrollVisual.SetSnapPoints(viewProps.snapToStart, viewProps.snapToEnd, snapToOffsets.GetView(), snapAlignment);
1483+
m_scrollVisual.SetSnapPoints(viewProps.snapToStart, viewProps.snapToEnd, snapToOffsets.GetView());
14981484
}
14991485
} // namespace winrt::Microsoft::ReactNative::Composition::implementation

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

Lines changed: 0 additions & 3 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> {
@@ -137,7 +135,6 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
137135
winrt::Microsoft::ReactNative::Composition::Experimental::IScrollPositionChangedArgs const &args) noexcept;
138136
void updateShowsHorizontalScrollIndicator(bool value) noexcept;
139137
void updateShowsVerticalScrollIndicator(bool value) noexcept;
140-
SnapAlignment convertSnapToAlignment(facebook::react::ScrollViewSnapToAlignment alignment) noexcept;
141138
winrt::Windows::Foundation::Collections::IVector<float> CreateSnapToOffsets(const std::vector<float> &offsets);
142139

143140
facebook::react::Size m_contentSize;

0 commit comments

Comments
 (0)