-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathTabs.cs
65 lines (52 loc) · 1.94 KB
/
Tabs.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
namespace UniMob.UI.Widgets
{
public class Tabs : MultiChildLayoutWidget
{
public Tabs(TabController tabController)
{
TabController = tabController;
}
public TabController TabController { get; }
public bool UseMask { get; set; } = true;
public bool Draggable {get; set;} = true;
public AxisSize CrossAxisSize { get; set; } = AxisSize.Min;
public AxisSize MainAxisSize { get; set; } = AxisSize.Min;
public WidgetSize? Size { get; set; }
public override State CreateState() => new TabsState();
}
public class TabsState : MultiChildLayoutState<Tabs>, ITabsState
{
public override WidgetViewReference View { get; }
= WidgetViewReference.Resource("UniMob.Tabs");
public TabController TabController => Widget.TabController;
public bool UseMask => Widget.UseMask;
[Atom] public WidgetSize InnerSize => CalculateInnerSize();
[Atom] public bool Draggable => Widget.Draggable;
public override WidgetSize CalculateSize()
{
if (Widget.Size.HasValue)
{
return Widget.Size.Value;
}
var (minWidth, minHeight, maxWidth, maxHeight) = InnerSize;
if (Widget.CrossAxisSize == AxisSize.Max)
{
maxWidth = float.PositiveInfinity;
}
if (Widget.MainAxisSize == AxisSize.Max)
{
maxHeight = float.PositiveInfinity;
}
return new WidgetSize(minWidth, minHeight, maxWidth, maxHeight);
}
private WidgetSize CalculateInnerSize()
{
var size = default(WidgetSize?);
foreach (var child in Children)
{
size = size.HasValue ? WidgetSize.StackZ(size.Value, child.Size) : child.Size;
}
return size.GetValueOrDefault(WidgetSize.Zero);
}
}
}