summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.MacOS/Extensions/NSScrollViewExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.MacOS/Extensions/NSScrollViewExtensions.cs')
-rw-r--r--Xamarin.Forms.Platform.MacOS/Extensions/NSScrollViewExtensions.cs36
1 files changed, 36 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.MacOS/Extensions/NSScrollViewExtensions.cs b/Xamarin.Forms.Platform.MacOS/Extensions/NSScrollViewExtensions.cs
new file mode 100644
index 0000000..f9104d4
--- /dev/null
+++ b/Xamarin.Forms.Platform.MacOS/Extensions/NSScrollViewExtensions.cs
@@ -0,0 +1,36 @@
+´╗┐using System.Threading.Tasks;
+using AppKit;
+using PointF = CoreGraphics.CGPoint;
+
+namespace Xamarin.Forms.Platform.MacOS
+{
+ internal static class NSScrollViewExtensions
+ {
+ public static Task ScrollToPositionAsync(this NSScrollView scrollView, PointF point, bool animate,
+ double duration = 0.5)
+ {
+ if (!animate)
+ {
+ var nsView = scrollView.DocumentView as NSView;
+ nsView?.ScrollPoint(point);
+ return Task.FromResult(true);
+ }
+
+ TaskCompletionSource<bool> source = new TaskCompletionSource<bool>();
+
+ NSAnimationContext.BeginGrouping();
+
+ NSAnimationContext.CurrentContext.CompletionHandler += () => { source.TrySetResult(true); };
+
+ NSAnimationContext.CurrentContext.Duration = duration;
+
+ var animator = scrollView.ContentView.Animator as NSView;
+
+ animator?.SetBoundsOrigin(point);
+
+ NSAnimationContext.EndGrouping();
+
+ return source.Task;
+ }
+ }
+} \ No newline at end of file