forked from dotnet/maui
/
NavigationView.cs
205 lines (177 loc) · 4.25 KB
/
NavigationView.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
using ElmSharp;
using System;
using Tizen.UIExtensions.Common;
using Tizen.UIExtensions.ElmSharp;
using EColor = ElmSharp.Color;
using EBox = ElmSharp.Box;
namespace Tizen.UIExtensions.Shell
{
/// <summary>
/// The native widget that is configured with an header and an list of items to be used in NavigationDrawer.
/// </summary>
public class NavigationView : Background, INavigationView
{
static readonly EColor s_defaultBackgroundColor = ElmSharp.ThemeConstants.Shell.ColorClass.DefaultNavigationViewBackgroundColor;
EBox _mainLayout;
EvasObject _header;
EvasObject _footer;
EvasObject _content;
EvasObject _backgroundImage;
EColor _backgroundColor;
/// <summary>
/// Initializes a new instance of the <see cref="Tizen.UIExtensions.ElmSharp.NavigationView2"/> class.
/// </summary>
/// <param name="parent">Parent evas object.</param>
public NavigationView(EvasObject parent) : base(parent)
{
InitializeComponent(parent);
}
/// <summary>
/// Gets or sets the background color of the NavigtiaonView.
/// </summary>
public override EColor BackgroundColor
{
get => _backgroundColor;
set
{
_backgroundColor = value;
EColor effectiveColor = _backgroundColor.IsDefault ? s_defaultBackgroundColor : _backgroundColor;
base.BackgroundColor = effectiveColor;
}
}
/// <summary>
/// Gets or sets the background image of the NavigtiaonView.
/// </summary>
public EvasObject BackgroundImage
{
get => _backgroundImage;
set
{
_backgroundImage = value;
this.SetBackgroundPart(_backgroundImage);
}
}
/// <summary>
/// Gets or sets the header view of the NavigtiaonView.
/// </summary>
public EvasObject Header
{
get => _header;
set => UpdateHeader(value);
}
/// <summary>
/// Gets or sets the footer view of the NavigtiaonView.
/// </summary>
public EvasObject Footer
{
get => _footer;
set => UpdateFooter(value);
}
public EvasObject Content
{
get => _content;
set => UpdateContent(value);
}
/// <summary>
/// Gets or sets the target view of the NavigtiaonView.
/// </summary>
public EvasObject TargetView => this;
/// <summary>
/// Notifies that the layout has been updated.
/// </summary>
public event EventHandler<LayoutEventArgs> LayoutUpdated;
void InitializeComponent(EvasObject parent)
{
base.BackgroundColor = s_defaultBackgroundColor;
_mainLayout = new EBox(parent)
{
AlignmentX = -1,
AlignmentY = -1,
WeightX = 1,
WeightY = 1
};
_mainLayout.SetLayoutCallback(OnLayout);
_mainLayout.Show();
SetContent(_mainLayout);
}
void OnLayout()
{
if (Geometry.Width == 0 || Geometry.Height == 0)
return;
var bound = Geometry;
int headerHeight = 0;
int footerHeight = 0;
if (_header != null)
{
var headerBound = bound;
headerHeight = _header.MinimumHeight;
headerBound.Height = headerHeight;
_header.Geometry = headerBound;
}
if (_footer != null)
{
var footerbound = bound;
footerHeight = _footer.MinimumHeight;
footerbound.Y = bound.Y + bound.Height - footerHeight;
footerbound.Height = footerHeight;
_footer.Geometry = footerbound;
}
if (_content != null)
{
bound.Y += headerHeight;
bound.Height = bound.Height - headerHeight - footerHeight;
_content.Geometry = bound;
}
NotifyOnLayout();
}
void NotifyOnLayout()
{
LayoutUpdated?.Invoke(this, new LayoutEventArgs() { Geometry = Geometry.ToCommon() });
}
void UpdateHeader(EvasObject header)
{
if (_header != null)
{
_mainLayout.UnPack(_header);
_header.Unrealize();
_header = null;
}
if (header != null)
{
_mainLayout.PackStart(header);
}
_header = header;
_header?.Show();
}
void UpdateFooter(EvasObject footer)
{
if (_footer != null)
{
_mainLayout.UnPack(_footer);
_footer.Unrealize();
_footer = null;
}
if (footer != null)
{
_mainLayout.PackEnd(footer);
}
_footer = footer;
_footer?.Show();
}
void UpdateContent(EvasObject content)
{
if (_content != null)
{
_mainLayout.UnPack(_content);
_content.Unrealize();
_content = null;
}
if (content != null)
{
_mainLayout.PackEnd(content);
}
_content = content;
_content?.Show();
}
}
}