This repository was archived by the owner on Jul 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 610
Expand file tree
/
Copy pathDialogTableViewSource.cs
More file actions
118 lines (99 loc) · 3.9 KB
/
DialogTableViewSource.cs
File metadata and controls
118 lines (99 loc) · 3.9 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using UIKit;
using Foundation;
using System;
using System.Reactive.Subjects;
using CoreGraphics;
using CodeHub.iOS.DialogElements;
using System.Reactive.Linq;
namespace CodeHub.iOS.TableViewSources
{
public class DialogTableViewSource : UITableViewSource
{
private readonly RootElement _root;
private readonly Subject<CGPoint> _scrolledSubject = new Subject<CGPoint>();
private readonly Subject<Element> _selectedSubject = new Subject<Element>();
public IObservable<CGPoint> ScrolledObservable { get { return _scrolledSubject.AsObservable(); } }
public IObservable<Element> SelectedObservable { get { return _selectedSubject.AsObservable(); } }
public RootElement Root
{
get { return _root; }
}
#if DEBUG
~DialogTableViewSource()
{
Console.WriteLine("Goodbye DialogTableViewSource");
}
#endif
public DialogTableViewSource(UITableView container)
{
container.RowHeight = UITableView.AutomaticDimension;
_root = new RootElement(container);
}
public override nint RowsInSection(UITableView tableview, nint section)
{
return Root[(int)section].Count;
}
public override nint NumberOfSections(UITableView tableView)
{
return Root.Count;
}
public override string TitleForHeader(UITableView tableView, nint section)
{
return Root[(int)section].Header;
}
public override string TitleForFooter(UITableView tableView, nint section)
{
return Root[(int)section].Footer;
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var section = Root[indexPath.Section];
var element = section[indexPath.Row];
return element.GetCell(tableView);
}
public override void RowDeselected(UITableView tableView, NSIndexPath indexPath)
{
var section = Root[indexPath.Section];
var element = section[indexPath.Row];
element.Deselected(tableView, indexPath);
}
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
var section = Root[indexPath.Section];
var element = section[indexPath.Row];
element.Selected(tableView, indexPath);
_selectedSubject.OnNext(element);
}
public override UIView GetViewForHeader(UITableView tableView, nint section)
{
var sectionElement = Root[(int)section];
return sectionElement.HeaderView;
}
public override nfloat GetHeightForHeader(UITableView tableView, nint section)
{
var sectionElement = Root[(int)section];
return sectionElement.HeaderView == null ? -1 : sectionElement.HeaderView.Frame.Height;
}
public override UIView GetViewForFooter(UITableView tableView, nint section)
{
var sectionElement = Root[(int)section];
return sectionElement.FooterView;
}
public override nfloat GetHeightForFooter(UITableView tableView, nint section)
{
var sectionElement = Root[(int)section];
return sectionElement.FooterView == null ? -1 : sectionElement.FooterView.Frame.Height;
}
public override void Scrolled(UIScrollView scrollView)
{
_scrolledSubject.OnNext(Root.TableView.ContentOffset);
}
public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
var section = Root[indexPath.Section];
var element = section[indexPath.Row];
var sizable = element as IElementSizing;
return sizable == null ? tableView.RowHeight : sizable.GetHeight(tableView, indexPath);
}
}
}