Skip to content

Commit

Permalink
Fix iOS ignoring IsRefreshEnabled
Browse files Browse the repository at this point in the history
It turns out just setting .Enabled on UIRefreshControl doesn't do anything.  The fix is to control if the refresh control is added or not as a subview of the UICollectionView.

Fixes #28
  • Loading branch information
Redth committed Apr 19, 2024
1 parent 75c1bc9 commit 29fc07e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Sample/VirtualListViewSample/SectionedAdapterPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<vlv:VirtualListView
Grid.Row="0"
Grid.Column="0" Grid.ColumnSpan="3"
IsRefreshEnabled="False"
OnRefresh="Vlv_OnOnRefresh"
x:Name="vlv"
OnSelectedItemsChanged="vlv_SelectedItemsChanged"
SelectionMode="Single">
Expand Down
6 changes: 6 additions & 0 deletions Sample/VirtualListViewSample/SectionedAdapterPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
26 changes: 23 additions & 3 deletions VirtualListView/Apple/VirtualListViewHandler.ios.maccatalyst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}
}


Expand Down

0 comments on commit 29fc07e

Please sign in to comment.