Skip to content

Commit 2883f91

Browse files
Copilotanupriya13
andcommitted
Implement Windows system-aware scroll wheel behavior
Co-authored-by: anupriya13 <54227869+anupriya13@users.noreply.github.com>
1 parent 71099c7 commit 2883f91

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#pragma warning(pop)
1616

1717
#include <windows.ui.composition.interop.h>
18+
#include <windows.h>
1819

1920
#include <AutoDraw.h>
2021
#include <Fabric/DWriteHelpers.h>
@@ -27,6 +28,13 @@ namespace winrt::Microsoft::ReactNative::Composition::implementation {
2728

2829
constexpr float c_scrollerLineDelta = 16.0f;
2930

31+
// Helper function to get the Windows system setting for wheel scroll lines
32+
static int GetSystemWheelScrollLines() noexcept {
33+
UINT scrollLines = 3; // Default fallback value
34+
SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &scrollLines, 0);
35+
return static_cast<int>(scrollLines);
36+
}
37+
3038
enum class ScrollbarHitRegion : int {
3139
Unknown = -1,
3240
ArrowFirst = 0,
@@ -913,23 +921,32 @@ void ScrollViewComponentView::OnPointerWheelChanged(
913921
const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) noexcept {
914922
auto ppp = args.GetCurrentPoint(-1).Properties();
915923
auto delta = static_cast<float>(ppp.MouseWheelDelta());
924+
925+
// Get the system setting for lines per wheel notch
926+
const int systemLinesPerNotch = GetSystemWheelScrollLines();
927+
928+
// Calculate the number of lines to scroll based on wheel delta and system settings
929+
// Standard Windows wheel delta is 120 per notch
930+
const float notches = delta / 120.0f;
931+
const float linesToScroll = notches * systemLinesPerNotch * c_scrollerLineDelta * m_layoutMetrics.pointScaleFactor;
932+
916933
if (ppp.IsHorizontalMouseWheel()) {
917934
if (delta > 0) {
918-
if (scrollLeft(delta * m_layoutMetrics.pointScaleFactor, true)) {
935+
if (scrollLeft(linesToScroll, true)) {
919936
args.Handled(true);
920937
}
921938
} else if (delta < 0) {
922-
if (scrollRight(-delta * m_layoutMetrics.pointScaleFactor, true)) {
939+
if (scrollRight(-linesToScroll, true)) {
923940
args.Handled(true);
924941
}
925942
}
926943
} else {
927944
if (delta > 0) {
928-
if (scrollUp(delta * m_layoutMetrics.pointScaleFactor, true)) {
945+
if (scrollUp(linesToScroll, true)) {
929946
args.Handled(true);
930947
}
931948
} else if (delta < 0) {
932-
if (scrollDown(-delta * m_layoutMetrics.pointScaleFactor, true)) {
949+
if (scrollDown(-linesToScroll, true)) {
933950
args.Handled(true);
934951
}
935952
}

0 commit comments

Comments
 (0)