forked from anthonysidesap/fluentui-android
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathV2ShimmerActivity.kt
More file actions
344 lines (335 loc) · 16 KB
/
Copy pathV2ShimmerActivity.kt
File metadata and controls
344 lines (335 loc) · 16 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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
package com.microsoft.fluentuidemo.demos
import android.os.Bundle
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.material.ListItem
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import com.microsoft.fluentui.theme.FluentTheme
import com.microsoft.fluentui.theme.ThemeMode
import com.microsoft.fluentui.theme.token.FluentAliasTokens
import com.microsoft.fluentui.theme.token.FluentStyle
import com.microsoft.fluentui.theme.token.controlTokens.AvatarSize
import com.microsoft.fluentui.theme.token.controlTokens.AvatarStatus
import com.microsoft.fluentui.theme.token.controlTokens.BadgeInfo
import com.microsoft.fluentui.theme.token.controlTokens.BadgeTokens
import com.microsoft.fluentui.theme.token.controlTokens.ButtonStyle
import com.microsoft.fluentui.theme.token.controlTokens.ColorStyle
import com.microsoft.fluentui.theme.token.controlTokens.PersonaChipSize
import com.microsoft.fluentui.theme.token.controlTokens.PersonaChipStyle
import com.microsoft.fluentui.theme.token.controlTokens.ShimmerInfo
import com.microsoft.fluentui.theme.token.controlTokens.ShimmerOrientation
import com.microsoft.fluentui.theme.token.controlTokens.ShimmerTokens
import com.microsoft.fluentui.tokenized.controls.Button
import com.microsoft.fluentui.tokenized.controls.Label
import com.microsoft.fluentui.tokenized.controls.RadioButton
import com.microsoft.fluentui.tokenized.controls.ToggleSwitch
import com.microsoft.fluentui.tokenized.notification.Badge
import com.microsoft.fluentui.tokenized.persona.Avatar
import com.microsoft.fluentui.tokenized.persona.Person
import com.microsoft.fluentui.tokenized.persona.PersonaChip
import com.microsoft.fluentui.tokenized.shimmer.Shimmer
import com.microsoft.fluentuidemo.R
import com.microsoft.fluentuidemo.V2DemoActivity
class V2ShimmerActivity : V2DemoActivity() {
init {
setupActivity(this)
}
override val paramsUrl = "https://github.com/microsoft/fluentui-android/wiki/Controls#params-34"
override val controlTokensUrl =
"https://github.com/microsoft/fluentui-android/wiki/Controls#control-tokens-32"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setActivityContent {
CreateShimmerActivityUI()
}
}
private fun getShimmerOrientation(shimmerOrientation: Int): ShimmerOrientation {
return when (shimmerOrientation) {
0 -> ShimmerOrientation.LEFT_TO_RIGHT
1 -> ShimmerOrientation.RIGHT_TO_LEFT
2 -> ShimmerOrientation.TOPLEFT_TO_BOTTOMRIGHT
3 -> ShimmerOrientation.BOTTOMRIGHT_TO_TOPLEFT
else -> ShimmerOrientation.LEFT_TO_RIGHT
}
}
@Composable
private fun CreateShimmerActivityUI() {
var shimmerOrientation by rememberSaveable { mutableStateOf(0) }
var isShimmering by rememberSaveable { mutableStateOf(true) }
val shimmerTokens = object: ShimmerTokens(){
@Composable
override fun delay(shimmerInfo: ShimmerInfo): Int {
return 1000
}
@Composable
override fun orientation(shimmerInfo: ShimmerInfo): ShimmerOrientation {
return getShimmerOrientation(shimmerOrientation)
}
}
Column(
Modifier
.padding(all = 12.dp)
) {
Label(
text = "Box Shimmer",
textStyle = FluentAliasTokens.TypographyTokens.Title2,
colorStyle = ColorStyle.Brand
)
Row(
modifier = Modifier
.padding(top = 8.dp, bottom = 16.dp)
.height(80.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Shimmer(modifier = Modifier.size(120.dp, 80.dp), shimmerTokens = shimmerTokens, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
Column(
Modifier
.height(80.dp)
.padding(top = 10.dp, bottom = 10.dp),
verticalArrangement = Arrangement.SpaceBetween
) {
Shimmer(modifier = Modifier.size(140.dp, 12.dp), shimmerTokens = shimmerTokens, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
Shimmer(modifier = Modifier.size(180.dp, 12.dp), shimmerTokens = shimmerTokens, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
Shimmer(modifier = Modifier.size(200.dp, 12.dp), shimmerTokens = shimmerTokens, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
}
}
Label(
text = "Circle Shimmer",
textStyle = FluentAliasTokens.TypographyTokens.Title2,
colorStyle = ColorStyle.Brand
)
Row(
modifier = Modifier
.padding(top = 8.dp, bottom = 16.dp)
.height(60.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Shimmer(modifier = Modifier.size(60.dp, 60.dp).clip(RoundedCornerShape(50.dp)), shimmerTokens = shimmerTokens, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
Column(
Modifier
.height(80.dp)
.padding(top = 10.dp, bottom = 10.dp),
verticalArrangement = Arrangement.SpaceBetween
) {
Shimmer(modifier = Modifier.size(180.dp, 12.dp), shimmerTokens = shimmerTokens, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
Shimmer(modifier = Modifier.size(180.dp, 12.dp), shimmerTokens = shimmerTokens, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
}
}
Row(
modifier = Modifier
.padding(top = 8.dp, bottom = 16.dp)
.height(60.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Shimmer(modifier = Modifier.size(60.dp, 60.dp).clip(RoundedCornerShape(50.dp)), shimmerTokens = shimmerTokens, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
Column(
Modifier
.height(80.dp)
.padding(top = 10.dp, bottom = 10.dp),
verticalArrangement = Arrangement.SpaceBetween
) {
Shimmer(modifier = Modifier.size(140.dp, 12.dp), shimmerTokens = shimmerTokens, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
Shimmer(modifier = Modifier.size(180.dp, 12.dp), shimmerTokens = shimmerTokens, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
}
}
Row(
modifier = Modifier
.padding(top = 8.dp, bottom = 16.dp)
.height(60.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Shimmer(modifier = Modifier.size(60.dp, 60.dp).clip(RoundedCornerShape(50.dp)), shimmerTokens = shimmerTokens, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
Column(
Modifier
.height(80.dp)
.padding(top = 10.dp, bottom = 10.dp),
verticalArrangement = Arrangement.SpaceBetween
) {
Shimmer(modifier = Modifier.size(140.dp, 12.dp), shimmerTokens = shimmerTokens, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
Shimmer(modifier = Modifier.size(180.dp, 12.dp), shimmerTokens = shimmerTokens, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
}
}
class ShimmerGoldEffectToken : ShimmerTokens() {
@Composable
override fun knockoutEffectColor(shimmerInfo: ShimmerInfo): Color {
return Color(0XFFE1BA27)
}
}
class BadgeColorToken : BadgeTokens() {
@Composable
override fun backgroundBrush(badgeInfo: BadgeInfo): Brush {
return SolidColor(Color(0xFFD59328))
}
@Composable
override fun borderStroke(badgeInfo: BadgeInfo): BorderStroke {
return BorderStroke(
width = 0.dp,
brush = SolidColor(Color(0xFFD59328))
)
}
}
Label(
text = "Shimmer with Content",
textStyle = FluentAliasTokens.TypographyTokens.Title2,
colorStyle = ColorStyle.Brand
)
Row(
modifier = Modifier
.padding(top = 8.dp, bottom = 16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Label(text = "Badge", textStyle = FluentAliasTokens.TypographyTokens.Body1)
Shimmer(content = {
Badge(text = "Badge", badgeTokens = BadgeColorToken())
}, shimmerTokens = ShimmerGoldEffectToken() , cornerRadius = 100.dp, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
}
Row(
modifier = Modifier
.padding(top = 8.dp, bottom = 16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Label(text = "PersonaChip", textStyle = FluentAliasTokens.TypographyTokens.Body1)
Shimmer(cornerRadius = 2.dp, content = {
PersonaChip(
person = Person("PersonaChip"),
selected = true,
size = PersonaChipSize.Small,
style = PersonaChipStyle.Brand
)
}, shimmerTokens = shimmerTokens, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
}
Row(
modifier = Modifier
.padding(top = 8.dp, bottom = 16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Label(text = "Avatar", textStyle = FluentAliasTokens.TypographyTokens.Body1)
Shimmer(cornerRadius = 50.dp, content = {
Avatar(
person = Person(
"Allan", "Munger",
image = R.drawable.avatar_allan_munger,
status = AvatarStatus.Available,
), size = AvatarSize.Size72, enableActivityRings = false
)
}, shimmerTokens = shimmerTokens, isShimmering = isShimmering, shimmerOrientation = getShimmerOrientation(shimmerOrientation))
}
Label(
text = "Change Orientation",
textStyle = FluentAliasTokens.TypographyTokens.Title2,
colorStyle = ColorStyle.Brand
)
Spacer( modifier = Modifier.height(10.dp))
SelectionRow(
text = "Left to Right",
testTag = "Left to Right",
selected = shimmerOrientation == 0,
onClick = { shimmerOrientation = 0 }
)
SelectionRow(
text = "Right to Left",
testTag = "Right to Left",
selected = shimmerOrientation == 1,
onClick = { shimmerOrientation = 1 }
)
SelectionRow(
text = "Top Left to Bottom Right",
testTag = "Top Left to Bottom Right",
selected = shimmerOrientation == 2,
onClick = { shimmerOrientation = 2 }
)
SelectionRow(
text = "Bottom Right to Top Left",
testTag = "Bottom Right to Top Left",
selected = shimmerOrientation == 3,
onClick = { shimmerOrientation = 3 }
)
Spacer(modifier = Modifier.height(10.dp))
Label(
text = "Toggle Animation",
textStyle = FluentAliasTokens.TypographyTokens.Title2,
colorStyle = ColorStyle.Brand
)
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().clickable {
isShimmering = !isShimmering
}
) {
BasicText(
text = "Toggle Shimmer Animation",
modifier = Modifier.weight(1F),
style = TextStyle(
color = FluentTheme.aliasTokens.neutralForegroundColor[FluentAliasTokens.NeutralForegroundColorTokens.Foreground3].value(
themeMode = ThemeMode.Auto
)
)
)
ToggleSwitch(
onValueChange = { isShimmering = !isShimmering },
checkedState = isShimmering
)
}
}
}
@Composable
private fun SelectionRow(
text: String,
testTag: String,
selected: Boolean,
onClick: () -> Unit
) {
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
) {
BasicText(
text = text,
modifier = Modifier.weight(1F),
style = TextStyle(
color = FluentTheme.aliasTokens.neutralForegroundColor[FluentAliasTokens.NeutralForegroundColorTokens.Foreground3].value(
themeMode = ThemeMode.Auto
)
)
)
RadioButton(
modifier = Modifier.testTag(testTag),
selected = selected,
onClick = onClick
)
}
}
}