forked from SIDOVSKY/EBind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfiguration.ios.cs
171 lines (147 loc) · 6.2 KB
/
Configuration.ios.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using System;
using Foundation;
using UIKit;
using static EBind.Platform.Configuration.ExtraEventNames;
namespace EBind.Platform
{
/// <summary>
/// iOS specific configuration for initialization and execution of bindings.
/// Provides triggers, dispatchers, and the default settings.
/// Has some pre-configured triggers – see the README file for details.
/// </summary>
public class Configuration : EBind.Configuration
{
/// <summary>
/// Collection of identifiers for custom pre-registered events.
/// </summary>
/// <remarks>
/// Supposed to be imported with a `using static` directive.
/// </remarks>
public static class ExtraEventNames
{
private const string Prefix = "EBind.Platform.Configuration.ExtraEventNames";
/// <summary>
/// Identifier of the pre-configured event trigger for <see cref="UIControl.TouchUpInside"/>
/// and <see cref="UIView.AddGestureRecognizer(UIGestureRecognizer)"/> <- <see cref="UITapGestureRecognizer"/>.
/// </summary>
/// <remarks>
/// Usage:
/// <code language="c#">
/// using static EBind.Platform.Configuration.ExtraEventNames;<br/>
/// ...<br/>
/// var binding = new EBinding <br/>
/// {<br/>
/// ⠀⠀(uiButton, Tap, OnButtonClick),<br/>
/// ⠀⠀(uiImageView, Tap, OnImageClick),<br/>
/// };
/// </code>
/// </remarks>
// U+2800 BRAILLE PATTERN BLANK ('⠀') is used instead of indent spaces in the code sample block
// because whitespaces are trimmed off.
public const string Tap = Prefix + nameof(Tap);
}
/// <summary>
/// Initializes a new instance of the <see cref="Configuration"/> class.
/// </summary>
public Configuration()
{
ConfigureProperties();
ConfigureExtraEvents();
ConfigureEvents();
}
private void ConfigureExtraEvents()
{
ConfigureTrigger<UIControl>(
Tap,
(o, h) => o.TouchUpInside += h,
(o, h) => o.TouchUpInside -= h);
ConfigureTrigger<UIView, UITapGestureRecognizer>(
Tap,
trigger => new UITapGestureRecognizer(trigger),
(o, h) => o.AddGestureRecognizer(h),
(o, h) => o.RemoveGestureRecognizer(h));
}
private void ConfigureEvents()
{
ConfigureTrigger<UIControl>(
nameof(UIControl.TouchUpInside),
(o, h) => o.TouchUpInside += h,
(o, h) => o.TouchUpInside -= h);
ConfigureTrigger<UIBarButtonItem>(
nameof(UIBarButtonItem.Clicked),
(o, h) => o.Clicked += h,
(o, h) => o.Clicked -= h);
ConfigureTrigger<UITextField>(
nameof(UITextField.EditingDidBegin),
(o, h) => o.EditingDidBegin += h,
(o, h) => o.EditingDidBegin -= h);
ConfigureTrigger<UITextField>(
nameof(UITextField.EditingChanged),
(o, h) => o.EditingChanged += h,
(o, h) => o.EditingChanged -= h);
ConfigureTrigger<UITextField>(
nameof(UITextField.EditingDidEnd),
(o, h) => o.EditingDidEnd += h,
(o, h) => o.EditingDidEnd -= h);
ConfigureTrigger<UITextView>(
nameof(UITextView.Changed),
(o, h) => o.Changed += h,
(o, h) => o.Changed -= h);
ConfigureTrigger<UISearchBar, UISearchBarTextChangedEventArgs>(
nameof(UISearchBar.TextChanged),
(o, h) => o.TextChanged += h,
(o, h) => o.TextChanged -= h);
ConfigureTrigger<UIControl>(
nameof(UIControl.ValueChanged),
(o, h) => o.ValueChanged += h,
(o, h) => o.ValueChanged -= h);
ConfigureTrigger<UITabBarController, UITabBarSelectionEventArgs>(
nameof(UITabBarController.ViewControllerSelected),
(o, h) => o.ViewControllerSelected += h,
(o, h) => o.ViewControllerSelected -= h);
}
private void ConfigureProperties()
{
ConfigureTrigger<UITextField, string?>(
o => o.Text,
(o, h) => o.EditingChanged += h,
(o, h) => o.EditingChanged -= h);
ConfigureTrigger<UITextView, string?>(
o => o.Text,
(o, h) => o.Changed += h,
(o, h) => o.Changed -= h);
ConfigureTrigger<UISearchBar, UISearchBarTextChangedEventArgs, string?>(
o => o.Text,
(o, h) => o.TextChanged += h,
(o, h) => o.TextChanged -= h);
ConfigureTrigger<UISlider, float>(
o => o.Value,
(o, h) => o.ValueChanged += h,
(o, h) => o.ValueChanged -= h);
ConfigureTrigger<UIStepper, double>(
o => o.Value,
(o, h) => o.ValueChanged += h,
(o, h) => o.ValueChanged -= h);
ConfigureTrigger<UISwitch, bool>(
o => o.On,
(o, h) => o.ValueChanged += h,
(o, h) => o.ValueChanged -= h);
ConfigureTrigger<UIDatePicker, NSDate>(
o => o.Date,
(o, h) => o.ValueChanged += h,
(o, h) => o.ValueChanged -= h);
ConfigureTrigger<UISegmentedControl, nint>(
o => o.SelectedSegment,
(o, h) => o.ValueChanged += h,
(o, h) => o.ValueChanged -= h);
ConfigureTrigger<UITabBarController, UITabBarSelectionEventArgs, nint>(
o => o.SelectedIndex,
(o, h) => o.ViewControllerSelected += h,
(o, h) => o.ViewControllerSelected -= h);
ConfigureTrigger<UIPageControl, nint>(
o => o.CurrentPage,
(o, h) => o.ValueChanged += h,
(o, h) => o.ValueChanged -= h);
}
}
}