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 609
Expand file tree
/
Copy pathBaseDialogViewController.cs
More file actions
133 lines (116 loc) · 4.97 KB
/
BaseDialogViewController.cs
File metadata and controls
133 lines (116 loc) · 4.97 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using UIKit;
using System.Reactive.Linq;
using CodeHub.iOS.TableViewSources;
using CodeHub.iOS.DialogElements;
using CodeHub.iOS.Views;
namespace CodeHub.iOS.ViewControllers
{
public abstract class BaseDialogViewController : TableViewController
{
protected readonly SlideUpTitleView SlideUpTitle;
protected readonly ImageAndTitleHeaderView HeaderView;
private readonly UIView _backgroundHeaderView;
private DialogTableViewSource _dialogSource;
protected DialogTableViewSource DialogSource
{
get { return _dialogSource; }
}
protected RootElement Root{
get { return _dialogSource.Root; }
}
public override string Title
{
get
{
return base.Title;
}
set
{
HeaderView.Text = value;
SlideUpTitle.Text = value;
base.Title = value;
RefreshHeaderView();
}
}
public override UIRefreshControl RefreshControl
{
get { return base.RefreshControl; }
set
{
if (value != null) {
value.TintColor = UIColor.White.ColorWithAlpha(0.8f);
}
base.RefreshControl = value;
}
}
protected BaseDialogViewController()
: base(UITableViewStyle.Grouped)
{
SlideUpTitle = new SlideUpTitleView(44f) { Offset = 100f };
NavigationItem.TitleView = SlideUpTitle;
HeaderView = new ImageAndTitleHeaderView();
_backgroundHeaderView = new UIView();
Appearing
.Where(x => ToolbarItems != null && NavigationController != null)
.Subscribe(x => NavigationController.SetToolbarHidden(false, x));
Disappearing
.Where(x => ToolbarItems != null && NavigationController != null)
.Subscribe(x => NavigationController.SetToolbarHidden(true, x));
Disappearing
.Where(_ => NavigationController != null)
.Subscribe(_ => NavigationController.NavigationBar.ShadowImage = null);
}
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
HeaderView.BackgroundColor = NavigationController.NavigationBar.BarTintColor;
HeaderView.TextColor = NavigationController.NavigationBar.TintColor;
HeaderView.SubTextColor = NavigationController.NavigationBar.TintColor.ColorWithAlpha(0.8f);
(SlideUpTitle.Subviews[0] as UILabel).TextColor = HeaderView.TextColor;
_backgroundHeaderView.BackgroundColor = HeaderView.BackgroundColor;
TableView.TableHeaderView = HeaderView;
}
public override void DidRotate(UIInterfaceOrientation fromInterfaceOrientation)
{
base.DidRotate(fromInterfaceOrientation);
TableView.BeginUpdates();
TableView.TableHeaderView = HeaderView;
TableView.EndUpdates();
}
protected virtual DialogTableViewSource CreateTableViewSource()
{
return new DialogTableViewSource(TableView);
}
protected void RefreshHeaderView(string text = null, string subtext = null)
{
HeaderView.Text = text ?? HeaderView.Text;
HeaderView.SubText = subtext ?? HeaderView.SubText;
TableView.TableHeaderView = HeaderView;
TableView.ReloadData();
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
_dialogSource = CreateTableViewSource();
TableView.SectionHeaderHeight = 0;
TableView.Source = _dialogSource;
var frame = TableView.Bounds;
frame.Y = -frame.Size.Height;
_backgroundHeaderView.Frame = frame;
_backgroundHeaderView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
_backgroundHeaderView.Layer.ZPosition = -1f;
TableView.InsertSubview(_backgroundHeaderView, 0);
var scrollingObservable = _dialogSource.ScrolledObservable.Select(x => x.Y).StartWith(TableView.ContentOffset.Y);
var shadowObs = scrollingObservable.Where(x => x > 0 && NavigationController != null);
var shadowImgObs = scrollingObservable.Where(x => x <= 0).Where(_ => NavigationController != null)
.Where(_ => NavigationController.NavigationBar.ShadowImage == null);
var slideObs = scrollingObservable.Where(_ => SlideUpTitle != null);
OnActivation(d => {
d(shadowObs.Subscribe(_ => NavigationController.NavigationBar.ShadowImage = null));
d(shadowImgObs.Subscribe(_ => NavigationController.NavigationBar.ShadowImage = new UIImage()));
d(slideObs.Subscribe(x => SlideUpTitle.Offset = 108 + 28f - x));
});
}
}
}