-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathUICollectionViewInPullToRefresh.cs
79 lines (71 loc) · 2.9 KB
/
UICollectionViewInPullToRefresh.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#region Copyright Syncfusion Inc. 2001-2024.
// Copyright Syncfusion Inc. 2001-2024. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// [email protected]. Any infringement will be prosecuted under
// applicable laws.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foundation;
using UIKit;
using Syncfusion.SfPullToRefresh;
using System.Threading.Tasks;
using CoreGraphics;
namespace SampleBrowser
{
public class UICollectionViewInPullToRefresh : SampleView
{
SfPullToRefresh pullToRefresh;
UICollectionView collectionView;
CollectionViewSource collectionViewSource;
UICollectionViewFlowLayout collectionViewFlowLayout;
public UICollectionViewInPullToRefresh()
{
this.pullToRefresh = new SfPullToRefresh();
this.pullToRefresh.Refreshing += PullToRefresh_Refreshing;
this.pullToRefresh.TransitionType = TransitionType.Push;
this.collectionViewFlowLayout = new UICollectionViewFlowLayout()
{
MinimumLineSpacing = 0.5f,
ScrollDirection = UICollectionViewScrollDirection.Vertical,
};
this.collectionView = new UICollectionView(CGRect.Empty, collectionViewFlowLayout);
this.collectionView.ShowsHorizontalScrollIndicator = false;
this.collectionViewSource = new CollectionViewSource();
this.collectionView.DataSource = this.collectionViewSource;
this.collectionView.RegisterClassForCell(typeof(CollectionViewCell), CollectionViewCell.CellID);
this.pullToRefresh.PullableContent = this.collectionView;
this.pullToRefresh.PullableContent.BackgroundColor = UIColor.LightGray;
this.AddSubview(this.pullToRefresh);
this.OptionView = new Options(pullToRefresh);
}
private async void PullToRefresh_Refreshing(object sender, RefreshingEventArgs e)
{
await Task.Delay(3000);
this.collectionViewSource.repository.RefreshItemSource();
this.collectionView.ReloadData();
e.Refreshed = true;
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
this.pullToRefresh.Frame = new CGRect(0, 0, this.Frame.Width, this.Frame.Height);
this.collectionViewFlowLayout.ItemSize = new CGSize(this.Frame.Width, 70);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (pullToRefresh != null)
{
this.pullToRefresh.Refreshing -= PullToRefresh_Refreshing;
this.pullToRefresh.Dispose();
}
}
base.Dispose(disposing);
}
}
}