From 88bc6a80ceba8380ee8af104d74a47048add3358 Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Wed, 11 Sep 2019 10:28:21 -0600 Subject: [PATCH] move await to Begin Invoke and check for disposed (#7192) --- .../Extensions/NSObjectExtensions.cs | 16 ++++++++++++++++ Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs | 14 ++++++++------ .../Xamarin.Forms.Platform.iOS.csproj | 1 + 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 Xamarin.Forms.Platform.iOS/Extensions/NSObjectExtensions.cs diff --git a/Xamarin.Forms.Platform.iOS/Extensions/NSObjectExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/NSObjectExtensions.cs new file mode 100644 index 0000000..8eb1d30 --- /dev/null +++ b/Xamarin.Forms.Platform.iOS/Extensions/NSObjectExtensions.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using Foundation; +using UIKit; + +namespace Xamarin.Forms.Platform.iOS +{ + internal static class NSObjectExtensions + { + public static void QueueForLater(this NSObject nsObject, Action action) => + nsObject.BeginInvokeOnMainThread(action); + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs index 5aa6d64..0a8dba5 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs @@ -360,7 +360,7 @@ namespace Xamarin.Forms.Platform.iOS Control.TableHeaderView = _headerRenderer.NativeView; } - async void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e) + void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e) { if (Superview == null) { @@ -386,15 +386,17 @@ namespace Xamarin.Forms.Platform.iOS Control.Layer.RemoveAllAnimations(); //iOS11 hack if (Forms.IsiOS11OrNewer) - { - await Task.Delay(1); - } - Control.ScrollToRow(NSIndexPath.FromRowSection(index, 0), position, e.ShouldAnimate); + this.QueueForLater(() => + { + if (Control != null && !_disposed) + Control.ScrollToRow(NSIndexPath.FromRowSection(index, 0), position, e.ShouldAnimate); + }); + else + Control.ScrollToRow(NSIndexPath.FromRowSection(index, 0), position, e.ShouldAnimate); } } } - void UpdateFooter() { var footer = ListView.FooterElement; diff --git a/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj b/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj index f9937cb..703645f 100644 --- a/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj +++ b/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj @@ -147,6 +147,7 @@ + -- 2.7.4