Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Revert \"[Fabric] Implement snapToInterval property for ScrollView (#14847)\"",
"packageName": "react-native-windows",
"email": "54227869+anupriya13@users.noreply.github.com",
"dependentChangeType": "patch"
}
9 changes: 1 addition & 8 deletions vnext/Microsoft.ReactNative/CompositionSwitcher.idl
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ namespace Microsoft.ReactNative.Composition.Experimental
SwitchThumb,
};

enum SnapAlignment
{
Start,
Center,
End,
};

[webhosthidden]
[uuid("172def51-9e1a-4e3c-841a-e5a470065acc")] // uuid needed for empty interfaces
[version(0)]
Expand Down Expand Up @@ -129,7 +122,7 @@ namespace Microsoft.ReactNative.Composition.Experimental
void SetMaximumZoomScale(Single maximumZoomScale);
void SetMinimumZoomScale(Single minimumZoomScale);
Boolean Horizontal;
void SetSnapPoints(Boolean snapToStart, Boolean snapToEnd, Windows.Foundation.Collections.IVectorView<Single> offsets, SnapAlignment snapToAlignment);
void SetSnapPoints(Boolean snapToStart, Boolean snapToEnd, Windows.Foundation.Collections.IVectorView<Single> offsets);
}

[webhosthidden]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

namespace Microsoft::ReactNative::Composition::Experimental {

using namespace winrt::Microsoft::ReactNative::Composition::Experimental;

template <typename TSpriteVisual>
struct CompositionTypeTraits {};

Expand Down Expand Up @@ -903,11 +901,9 @@ struct CompScrollerVisual : winrt::implements<
void SetSnapPoints(
bool snapToStart,
bool snapToEnd,
winrt::Windows::Foundation::Collections::IVectorView<float> const &offsets,
SnapAlignment snapToAlignment) noexcept {
winrt::Windows::Foundation::Collections::IVectorView<float> const &offsets) noexcept {
m_snapToStart = snapToStart;
m_snapToEnd = snapToEnd;
m_snapToAlignment = snapToAlignment;
m_snapToOffsets.clear();
if (offsets) {
for (auto const &offset : offsets) {
Expand Down Expand Up @@ -1164,22 +1160,6 @@ struct CompScrollerVisual : winrt::implements<
}

snapPositions.insert(snapPositions.end(), m_snapToOffsets.begin(), m_snapToOffsets.end());

// Adjust snap positions based on alignment
const float viewportSize = m_horizontal ? visualSize.x : visualSize.y;
if (m_snapToAlignment == SnapAlignment::Center) {
// For center alignment, offset snap positions by half the viewport size
for (auto &position : snapPositions) {
position = std::max(0.0f, position - viewportSize / 2.0f);
}
} else if (m_snapToAlignment == SnapAlignment::End) {
// For end alignment, offset snap positions by the full viewport size
for (auto &position : snapPositions) {
position = std::max(0.0f, position - viewportSize);
}
}
// For Start alignment, no adjustment needed

std::sort(snapPositions.begin(), snapPositions.end());
snapPositions.erase(std::unique(snapPositions.begin(), snapPositions.end()), snapPositions.end());

Expand Down Expand Up @@ -1307,7 +1287,6 @@ struct CompScrollerVisual : winrt::implements<
bool m_snapToStart{true};
bool m_snapToEnd{true};
std::vector<float> m_snapToOffsets;
SnapAlignment m_snapToAlignment{SnapAlignment::Start};
bool m_inertia{false};
bool m_custom{false};
bool m_interacting{false};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
namespace winrt::Microsoft::ReactNative::Composition::implementation {

constexpr float c_scrollerLineDelta = 16.0f;
constexpr auto c_maxSnapPoints = 1000;

enum class ScrollbarHitRegion : int {
Unknown = -1,
Expand Down Expand Up @@ -741,15 +740,6 @@ void ScrollViewComponentView::updateBackgroundColor(const facebook::react::Share
}
}

winrt::Windows::Foundation::Collections::IVector<float> ScrollViewComponentView::CreateSnapToOffsets(
const std::vector<float> &offsets) {
auto snapToOffsets = winrt::single_threaded_vector<float>();
for (const auto &offset : offsets) {
snapToOffsets.Append(offset);
}
return snapToOffsets;
}

void ScrollViewComponentView::updateProps(
facebook::react::Props::Shared const &props,
facebook::react::Props::Shared const &oldProps) noexcept {
Expand Down Expand Up @@ -818,13 +808,11 @@ void ScrollViewComponentView::updateProps(

if (oldViewProps.snapToStart != newViewProps.snapToStart || oldViewProps.snapToEnd != newViewProps.snapToEnd ||
oldViewProps.snapToOffsets != newViewProps.snapToOffsets) {
if (oldViewProps.snapToInterval != newViewProps.snapToInterval) {
updateSnapPoints();
} else {
const auto snapToOffsets = CreateSnapToOffsets(newViewProps.snapToOffsets);
m_scrollVisual.SetSnapPoints(
newViewProps.snapToStart, newViewProps.snapToEnd, snapToOffsets.GetView(), SnapAlignment::Center);
const auto snapToOffsets = winrt::single_threaded_vector<float>();
for (const auto &offset : newViewProps.snapToOffsets) {
snapToOffsets.Append(static_cast<float>(offset));
}
m_scrollVisual.SetSnapPoints(newViewProps.snapToStart, newViewProps.snapToEnd, snapToOffsets.GetView());
}
}

Expand Down Expand Up @@ -875,9 +863,6 @@ void ScrollViewComponentView::updateContentVisualSize() noexcept {
m_verticalScrollbarComponent->ContentSize(contentSize);
m_horizontalScrollbarComponent->ContentSize(contentSize);
m_scrollVisual.ContentSize(contentSize);

// Update snap points if snapToInterval is being used, as content size affects the number of snap points
updateSnapPoints();
}

void ScrollViewComponentView::prepareForRecycle() noexcept {}
Expand Down Expand Up @@ -1476,50 +1461,4 @@ void ScrollViewComponentView::updateShowsVerticalScrollIndicator(bool value) noe
void ScrollViewComponentView::updateDecelerationRate(float value) noexcept {
m_scrollVisual.SetDecelerationRate({value, value, value});
}

SnapAlignment ScrollViewComponentView::convertSnapToAlignment(
facebook::react::ScrollViewSnapToAlignment alignment) noexcept {
switch (alignment) {
case facebook::react::ScrollViewSnapToAlignment::Center:
return SnapAlignment::Center;
case facebook::react::ScrollViewSnapToAlignment::End:
return SnapAlignment::End;
case facebook::react::ScrollViewSnapToAlignment::Start:
default:
return SnapAlignment::Start;
}
}

void ScrollViewComponentView::updateSnapPoints() noexcept {
const auto &viewProps = *std::static_pointer_cast<const facebook::react::ScrollViewProps>(this->viewProps());
const auto snapToOffsets = CreateSnapToOffsets(viewProps.snapToOffsets);
// Typically used in combination with snapToAlignment and decelerationRate="fast"
auto snapAlignment = SnapAlignment::Center;
auto decelerationRate = viewProps.decelerationRate;

// snapToOffsets has priority over snapToInterval (matches React Native behavior)
if (viewProps.snapToInterval > 0 && decelerationRate >= 0.99) {
snapAlignment = convertSnapToAlignment(viewProps.snapToAlignment);
// Generate snap points based on interval
// Calculate the content size to determine how many intervals to create
float contentLength = viewProps.horizontal
? std::max(m_contentSize.width, m_layoutMetrics.frame.size.width) * m_layoutMetrics.pointScaleFactor
: std::max(m_contentSize.height, m_layoutMetrics.frame.size.height) * m_layoutMetrics.pointScaleFactor;

float interval = static_cast<float>(viewProps.snapToInterval) * m_layoutMetrics.pointScaleFactor;

// Ensure we have a reasonable minimum interval to avoid infinite loops or excessive memory usage
if (interval >= 1.0f && contentLength > 0) {
// Generate offsets at each interval, but limit the number of snap points to avoid excessive memory usage
int snapPointCount = 0;

for (float offset = 0; offset <= contentLength && snapPointCount < c_maxSnapPoints; offset += interval) {
snapToOffsets.Append(offset);
snapPointCount++;
}
}
}

m_scrollVisual.SetSnapPoints(viewProps.snapToStart, viewProps.snapToEnd, snapToOffsets.GetView(), snapAlignment);
}
} // namespace winrt::Microsoft::ReactNative::Composition::implementation
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

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

using namespace Microsoft::ReactNative::Composition::Experimental;

struct ScrollBarComponent;

struct ScrollViewComponentView : ScrollViewComponentViewT<ScrollViewComponentView, ViewComponentView> {
Expand Down Expand Up @@ -123,7 +121,6 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
private:
void updateDecelerationRate(float value) noexcept;
void updateContentVisualSize() noexcept;
void updateSnapPoints() noexcept;
bool scrollToEnd(bool animate) noexcept;
bool scrollToStart(bool animate) noexcept;
bool scrollDown(float delta, bool animate) noexcept;
Expand All @@ -137,8 +134,6 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
winrt::Microsoft::ReactNative::Composition::Experimental::IScrollPositionChangedArgs const &args) noexcept;
void updateShowsHorizontalScrollIndicator(bool value) noexcept;
void updateShowsVerticalScrollIndicator(bool value) noexcept;
SnapAlignment convertSnapToAlignment(facebook::react::ScrollViewSnapToAlignment alignment) noexcept;
winrt::Windows::Foundation::Collections::IVector<float> CreateSnapToOffsets(const std::vector<float> &offsets);

facebook::react::Size m_contentSize;
winrt::Microsoft::ReactNative::Composition::Experimental::IScrollVisual m_scrollVisual{nullptr};
Expand Down
Loading