Skip to content

Commit

Permalink
Merge pull request #37 from Redth/fix-ios-refreshenabled
Browse files Browse the repository at this point in the history
Fix iOS ignoring IsRefreshEnabled
  • Loading branch information
Redth authored Apr 19, 2024
2 parents 9e51234 + 29fc07e commit f23a080
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 @@ -175,8 +183,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 f23a080

Please sign in to comment.