Skip to content

Commit c906316

Browse files
committed
feat(scrollviewer): Prevent touch scrolling on forbidden axis
1 parent 4d43906 commit c906316

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.Managed.cs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
namespace Windows.UI.Xaml.Controls
1919
{
20-
public partial class ScrollContentPresenter : ContentPresenter, ICustomClippingElement, IScrollContentPresenter
20+
public partial class ScrollContentPresenter : ContentPresenter, ICustomClippingElement
2121
{
2222
// Default physical amount to scroll with Up/Down/Left/Right key
2323
const double ScrollViewerLineDelta = 16.0;
@@ -92,19 +92,9 @@ public object ScrollOwner
9292
}
9393
private ScrollViewer Scroller => ScrollOwner as ScrollViewer;
9494

95-
public ScrollMode HorizontalScrollMode { get; set; }
95+
public bool CanHorizontallyScroll { get; set; }
9696

97-
public ScrollMode VerticalScrollMode { get; set; }
98-
99-
public float MinimumZoomScale { get; set; }
100-
101-
public float MaximumZoomScale { get; set; }
102-
103-
ScrollBarVisibility IScrollContentPresenter.VerticalScrollBarVisibility { get => VerticalScrollBarVisibility; set => VerticalScrollBarVisibility = value; }
104-
internal ScrollBarVisibility VerticalScrollBarVisibility { get; set; }
105-
106-
ScrollBarVisibility IScrollContentPresenter.HorizontalScrollBarVisibility { get => HorizontalScrollBarVisibility; set => HorizontalScrollBarVisibility = value; }
107-
internal ScrollBarVisibility HorizontalScrollBarVisibility { get; set; }
97+
public bool CanVerticallyScroll { get; set; }
10898

10999
public double HorizontalOffset { get; private set; }
110100

@@ -126,7 +116,8 @@ public ScrollContentPresenter()
126116
PointerWheelChanged += ScrollContentPresenter_PointerWheelChanged;
127117

128118
// Touch scroll support
129-
ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY;
119+
ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY; // Updated in PrepareTouchScroll!
120+
ManipulationStarting += PrepareTouchScroll;
130121
ManipulationStarted += BeginTouchScroll;
131122
ManipulationDelta += UpdateTouchScroll;
132123
ManipulationCompleted += CompleteTouchScroll;
@@ -158,6 +149,10 @@ protected override void OnContentChanged(object oldValue, object newValue)
158149
}
159150
}
160151

152+
internal void OnMinZoomFactorChanged(float newValue) { }
153+
154+
internal void OnMaxZoomFactorChanged(float newValue) { }
155+
161156
internal bool Set(
162157
double? horizontalOffset = null,
163158
double? verticalOffset = null,
@@ -232,12 +227,12 @@ private void ScrollContentPresenter_PointerWheelChanged(object sender, Input.Poi
232227

233228
if (Content is UIElement)
234229
{
235-
var canScrollHorizontally = HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled;
236-
var canScrollVertically = VerticalScrollBarVisibility != ScrollBarVisibility.Disabled;
230+
var canScrollHorizontally = CanHorizontallyScroll;
231+
var canScrollVertically = CanVerticallyScroll;
237232

238233
if (e.KeyModifiers == VirtualKeyModifiers.Control)
239234
{
240-
// TODO: Handle zoom
235+
// TODO: Handle zoom https://github.com/unoplatform/uno/issues/4309
241236
}
242237
else if (!canScrollVertically || properties.IsHorizontalMouseWheel || e.KeyModifiers == VirtualKeyModifiers.Shift)
243238
{
@@ -253,6 +248,19 @@ private void ScrollContentPresenter_PointerWheelChanged(object sender, Input.Poi
253248
}
254249
}
255250

251+
private void PrepareTouchScroll(object sender, ManipulationStartingRoutedEventArgs e)
252+
{
253+
if (!CanVerticallyScroll || ExtentHeight <= 0)
254+
{
255+
e.Mode &= ~ManipulationModes.TranslateY;
256+
}
257+
258+
if (!CanHorizontallyScroll || ExtentWidth <= 0)
259+
{
260+
e.Mode &= ~ManipulationModes.TranslateX;
261+
}
262+
}
263+
256264
private void BeginTouchScroll(object sender, ManipulationStartedRoutedEventArgs e)
257265
{
258266
if (e.PointerDeviceType != PointerDeviceType.Touch)

0 commit comments

Comments
 (0)