-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement snapToAlignment property for ScrollView in Fabric architecture #14830
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
Changes from 7 commits
c0e9db6
bdac15e
24ea534
b29a23a
2e866af
8b8a858
9927cfd
a86cae6
e224904
0d41473
bd72404
b140442
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "Implement snapToAlignment support for Fabric ScrollView - interface and prop handling", | ||
| "packageName": "react-native-windows", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,4 +86,13 @@ describe('ScrollView Tests', () => { | |
| const dump = await dumpVisualTree('scroll_pressable_sticky_header'); | ||
| expect(dump).toMatchSnapshot(); | ||
| });*/ | ||
| test('ScrollView snapToAlignment does not cause errors', async () => { | ||
|
||
| // This test ensures that the snapToAlignment prop is handled without crashing | ||
| // We test this by navigating to the snap options example and verifying it loads | ||
| await goToComponentExample('<ScrollView> SnapTo Options'); | ||
| const component = await app.findElementByTestID('snap_scrollview'); | ||
| await component.waitForDisplayed({timeout: 20000}); | ||
| const dump = await dumpVisualTree('snap_scrollview'); | ||
| expect(dump).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,7 +120,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); | ||
| void SetSnapPoints(Boolean snapToStart, Boolean snapToEnd, Windows.Foundation.Collections.IVectorView<Single> offsets, Windows.UI.Xaml.Controls.SnapPointsAlignment snapToAlignment); | ||
|
||
| } | ||
|
|
||
| [webhosthidden] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -807,12 +807,30 @@ void ScrollViewComponentView::updateProps( | |
| } | ||
|
|
||
| if (oldViewProps.snapToStart != newViewProps.snapToStart || oldViewProps.snapToEnd != newViewProps.snapToEnd || | ||
| oldViewProps.snapToOffsets != newViewProps.snapToOffsets) { | ||
| oldViewProps.snapToOffsets != newViewProps.snapToOffsets || | ||
| oldViewProps.snapToAlignment != newViewProps.snapToAlignment) { | ||
| 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()); | ||
|
|
||
| // Convert React Native snapToAlignment to Windows SnapPointsAlignment enum | ||
| winrt::Windows::UI::Xaml::Controls::SnapPointsAlignment snapAlignment; | ||
| switch (newViewProps.snapToAlignment) { | ||
|
||
| case facebook::react::ScrollViewSnapToAlignment::Center: | ||
| snapAlignment = winrt::Windows::UI::Xaml::Controls::SnapPointsAlignment::Center; | ||
| break; | ||
| case facebook::react::ScrollViewSnapToAlignment::End: | ||
| snapAlignment = winrt::Windows::UI::Xaml::Controls::SnapPointsAlignment::Far; | ||
| break; | ||
| case facebook::react::ScrollViewSnapToAlignment::Start: | ||
| default: | ||
| snapAlignment = winrt::Windows::UI::Xaml::Controls::SnapPointsAlignment::Near; | ||
| break; | ||
| } | ||
|
|
||
| m_scrollVisual.SetSnapPoints( | ||
| newViewProps.snapToStart, newViewProps.snapToEnd, snapToOffsets.GetView(), snapAlignment); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.