Skip to content

[Fabric] Implement snapToAlignment property for ScrollView #14841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

anupriya13
Copy link
Contributor

@anupriya13 anupriya13 commented Jul 4, 2025

Description

Type of Change

  • New feature (non-breaking change which adds functionality)

Why

Implement snapToAlignment property for ScrollView in Fabric

Resolves #13148

What

Implement snapToAlignment property for ScrollView in Fabric
image
https://reactnative.dev/docs/scrollview#snaptoalignment

Background

The snapToAlignment property was available in RNW Paper via ScrollViewManager but missing from the Fabric implementation, causing a parity gap between the two architectures.

Screenshots

Recording.2025-07-09.122123.mp4

Testing

Tested in playground and e2etestappfabric already added

Changes

Core Implementation

  • Extended SetSnapPoints interface in CompositionSwitcher.idl to accept snapToAlignment parameter
  • Added snapToAlignment handling in ScrollViewComponentView.cpp with proper enum conversion from React Native to Windows types
  • Implemented alignment logic in ConfigureSnapInertiaModifiers() to adjust snap positions based on alignment:
    • "start" (Near): No adjustment - content snaps at natural positions
    • "center" (Center): Offsets positions by half viewport size - content centers in viewport
    • "end" (Far): Offsets positions by full viewport size - content aligns to end of viewport

Enum Mapping

React Native -> Windows
ScrollViewSnapToAlignment::Start -> SnapPointsAlignment::Near  
ScrollViewSnapToAlignment::Center -> SnapPointsAlignment::Center
ScrollViewSnapToAlignment::End -> SnapPointsAlignment::Far

Changelog

Should this change be included in the release notes: YES

Add a brief summary of the change to use in the release notes for the next release.
Implement snapToAlignment property for ScrollView in Fabric

Microsoft Reviewers: Open in CodeFlow

…ure (#14830)

* Initial plan

* Implement snapToAlignment support for Fabric ScrollView - interface and prop handling

Co-authored-by: anupriya13 <54227869+anupriya13@users.noreply.github.com>

* Add test support and UI for snapToAlignment in ScrollView Fabric implementation

Co-authored-by: anupriya13 <54227869+anupriya13@users.noreply.github.com>

* Remove unnecessary changes from vnext/codegen files

Co-authored-by: anupriya13 <54227869+anupriya13@users.noreply.github.com>

* Change files

* Run yarn change prerelease, yarn lint:fix, and yarn format as requested

Co-authored-by: anupriya13 <54227869+anupriya13@users.noreply.github.com>

* Remove all changes from vnext/codegen files as requested

Co-authored-by: anupriya13 <54227869+anupriya13@users.noreply.github.com>

* Remove XAML dependency from IDL by defining local SnapAlignment enum

Co-authored-by: anupriya13 <54227869+anupriya13@users.noreply.github.com>

* Extract snap alignment conversion into separate function for better readability

Co-authored-by: anupriya13 <54227869+anupriya13@users.noreply.github.com>

* Revert changes to ScrollViewExample.js as requested

Co-authored-by: anupriya13 <54227869+anupriya13@users.noreply.github.com>

* Revert changes to ScrollViewComponentTest.test.ts as requested

Co-authored-by: anupriya13 <54227869+anupriya13@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: anupriya13 <54227869+anupriya13@users.noreply.github.com>
@anupriya13 anupriya13 marked this pull request as ready for review July 4, 2025 07:45
@anupriya13 anupriya13 requested review from a team as code owners July 4, 2025 07:45
@anupriya13 anupriya13 requested a review from acoates-ms July 4, 2025 07:45
@anupriya13 anupriya13 force-pushed the user/anuverma/snapToAlignment branch from 509e4ca to f87e92f Compare July 4, 2025 10:54
Copy link
Contributor

@satkh satkh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a video recording, displaying how this prop works.

@satkh
Copy link
Contributor

satkh commented Jul 8, 2025

Add this case to scrollview/samples

@anupriya13 anupriya13 changed the title Implement snapToAlignment property for ScrollView in Fabric [Fabric] Implement snapToAlignment property for ScrollView Jul 9, 2025
@anupriya13
Copy link
Contributor Author

Add this case to scrollview/samples

It's already added

snapToAlignment={this.state.alignToStartValue ? 'start' : 'end'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement snapToAlignment property for ScrollView for fabric
3 participants