diff --git a/Sample/VirtualListViewSample/SectionedAdapterPage.xaml b/Sample/VirtualListViewSample/SectionedAdapterPage.xaml index 3e7ed68..f448b95 100644 --- a/Sample/VirtualListViewSample/SectionedAdapterPage.xaml +++ b/Sample/VirtualListViewSample/SectionedAdapterPage.xaml @@ -10,6 +10,8 @@ diff --git a/Sample/VirtualListViewSample/SectionedAdapterPage.xaml.cs b/Sample/VirtualListViewSample/SectionedAdapterPage.xaml.cs index 12e3944..b7dbc9e 100644 --- a/Sample/VirtualListViewSample/SectionedAdapterPage.xaml.cs +++ b/Sample/VirtualListViewSample/SectionedAdapterPage.xaml.cs @@ -47,4 +47,10 @@ private void vlv_SelectedItemsChanged(object sender, SelectedItemsChangedEventAr } } + + private async void Vlv_OnOnRefresh(object sender, RefreshEventArgs e) + { + await Task.Delay(3000); + e.Complete(); + } } diff --git a/VirtualListView/Apple/VirtualListViewHandler.ios.maccatalyst.cs b/VirtualListView/Apple/VirtualListViewHandler.ios.maccatalyst.cs index 90a5579..76e142b 100644 --- a/VirtualListView/Apple/VirtualListViewHandler.ios.maccatalyst.cs +++ b/VirtualListView/Apple/VirtualListViewHandler.ios.maccatalyst.cs @@ -36,13 +36,21 @@ protected override UICollectionView CreatePlatformView() refreshControl = new UIRefreshControl(); + refreshControl.Enabled = VirtualView?.IsRefreshEnabled ?? false; refreshControl.AddTarget(new EventHandler((s, a) => { refreshControl.BeginRefreshing(); - VirtualView?.Refresh(() => refreshControl.EndRefreshing()); + try + { + VirtualView?.Refresh(() => refreshControl.EndRefreshing()); + } + catch + { + refreshControl.EndRefreshing(); + } }), UIControlEvent.ValueChanged); - collectionView.AddSubview(refreshControl); + //collectionView.AddSubview(refreshControl); collectionView.AlwaysBounceVertical = true; @@ -176,8 +184,20 @@ public static void MapRefreshAccentColor(VirtualListViewHandler handler, IVirtua public static void MapIsRefreshEnabled(VirtualListViewHandler handler, IVirtualListView virtualListView) { + var isRefreshEnabled = virtualListView?.IsRefreshEnabled ?? false; if (handler.refreshControl is not null) - handler.refreshControl.Enabled = virtualListView.IsRefreshEnabled; + { + if (isRefreshEnabled) + { + handler.PlatformView.AddSubview(handler.refreshControl); + handler.refreshControl.Enabled = true; + } + else + { + handler.refreshControl.Enabled = false; + handler.refreshControl.RemoveFromSuperview(); + } + } }