-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimatedSwitchApp.cs
More file actions
125 lines (114 loc) · 3.64 KB
/
Copy pathAnimatedSwitchApp.cs
File metadata and controls
125 lines (114 loc) · 3.64 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
using UniMob;
using UniMob.UI;
using UniMob.UI.Widgets;
using UnityEngine;
namespace Samples.AnimatedSwitch
{
public class AnimatedSwitchApp : UniMobUIApp
{
[Atom] private int CurrentPage { get; set; }
protected override Widget Build(BuildContext context)
{
return new Column
{
CrossAxisAlignment = CrossAxisAlignment.Center,
Children =
{
new UniMobText
{
Value = $"Page {CurrentPage}",
FontSize = 50,
},
new Container
{
Size = WidgetSize.Fixed(600, 600),
BackgroundColor = Color.white,
Child = new AnimatedSwitcher
{
Child = BuildCurrentPage(),
Duration = 0.25f,
ReverseDuration = 0.15f,
TransitionMode = AnimatedSwitcherTransitionMode.Parallel,
TransitionBuilder = CustomTransitionBuilder,
},
},
BuildPagination(),
},
};
}
private Widget BuildCurrentPage()
{
switch (CurrentPage)
{
case 1: return BuildPage1();
case 2: return BuildPage2();
case 3: return BuildPage3();
default: return null;
}
}
private Widget BuildPage1()
{
return new Container
{
Key = Key.Of("page 1"),
Size = WidgetSize.Stretched,
BackgroundColor = Color.red,
};
}
private Widget BuildPage2()
{
return new Container
{
Key = Key.Of("page 2"),
Size = WidgetSize.Stretched,
BackgroundColor = Color.green,
};
}
private Widget BuildPage3()
{
return new Container
{
Key = Key.Of("page 3"),
Size = WidgetSize.Stretched,
BackgroundColor = Color.blue,
};
}
private Widget BuildPagination()
{
return new PaddingBox(new RectPadding(10, 10, 10, 10))
{
Child = new Container
{
BackgroundColor = Color.green,
Child = new UniMobButton
{
OnClick = () => CurrentPage = (CurrentPage + 1) % 4,
Child = new UniMobText
{
Value = $"Next Page",
FontSize = 50,
},
},
},
};
}
private static Widget CustomTransitionBuilder(IAnimation<float> animation, Widget child)
{
if (animation.Status == AnimationStatus.Reverse)
{
return new CompositeTransition
{
Scale = animation.Drive(new Vector3Tween(new Vector3(0, 1, 1), Vector3.one)),
Opacity = animation,
Child = child,
};
}
return new CompositeTransition
{
Position = animation.Drive(new Vector2Tween(new Vector2(0.0f, -0.2f), Vector2.zero)),
Opacity = animation,
Child = child,
};
}
}
}