-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathShadowsScreen.kt
More file actions
595 lines (559 loc) · 20.1 KB
/
ShadowsScreen.kt
File metadata and controls
595 lines (559 loc) · 20.1 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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
package com.faskn.composeplayground.shadows
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.slideOutVertically
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.automirrored.filled.ArrowForward
import androidx.compose.material.icons.filled.AutoAwesome
import androidx.compose.material.icons.filled.FilterVintage
import androidx.compose.material.icons.filled.Gradient
import androidx.compose.material.icons.filled.Layers
import androidx.compose.material.icons.filled.MultipleStop
import androidx.compose.material.icons.outlined.LightMode
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
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.draw.dropShadow
import androidx.compose.ui.draw.innerShadow
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.shadow.Shadow
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.faskn.composeplayground.carousel.CarouselControlButton
import com.faskn.composeplayground.ui.theme.Black900
import com.faskn.composeplayground.ui.theme.Black950
import com.faskn.composeplayground.ui.theme.Cyan100
import com.faskn.composeplayground.ui.theme.Gray400
import com.faskn.composeplayground.ui.theme.Gray900
import com.faskn.composeplayground.ui.theme.TechBlack
import com.faskn.composeplayground.ui.theme.White900
// Data class for shadow samples
private data class ShadowSample(
val modifier: Modifier,
val title: String,
val description: String,
val borderColor: Color,
val icon: ImageVector,
)
// Shadow configuration constants
data class ShadowConfig(
val strokeColor: Color = Color(0xFFFF9718),
val fillColor: Color = Color(0xFFFF5722),
val secondaryFillColor: Color = Color(0xFF536DFE),
val glassReflectColor: Color = Color(0xFFF3DFAC),
val themeColor: Color = Black900
)
@Composable
fun ShadowsScreen() {
val samples = remember { createShadowSamples() }
var currentIndex by remember { mutableIntStateOf(0) }
Column(
modifier = Modifier
.fillMaxSize()
.background(TechBlack)
.padding(24.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
val sample = samples[currentIndex]
ShadowComposable(
modifier = sample.modifier,
title = sample.title,
description = sample.description,
borderColor = sample.borderColor,
icon = sample.icon
)
Spacer(modifier = Modifier.height(28.dp))
NavigationControls(onPrevious = {
currentIndex = if (currentIndex - 1 < 0) samples.lastIndex else currentIndex - 1
}, onNext = {
currentIndex = if (currentIndex + 1 > samples.lastIndex) 0 else currentIndex + 1
})
}
}
@Composable
private fun NavigationControls(
onPrevious: () -> Unit, onNext: () -> Unit
) {
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
CarouselControlButton(
onClick = onPrevious,
icon = Icons.AutoMirrored.Default.ArrowBack,
)
CarouselControlButton(
onClick = onNext,
icon = Icons.AutoMirrored.Default.ArrowForward,
)
}
}
private fun createShadowSamples(): List<ShadowSample> {
return listOf(
createFillShadowSample(),
createGradientFillShadowSample(),
createCyanVolumetricShadowSample(
ShadowConfig(
strokeColor = Color(0xFF00F5FF),
fillColor = Color(0xFFFF00FF),
secondaryFillColor = Color(0xFF9D00FF),
glassReflectColor = Color(0xFFFFFFFF)
)
),
createVolumetricShadowSample(
ShadowConfig(
strokeColor = Color(0xFF00FF99),
fillColor = Color(0xFF00FF7F),
secondaryFillColor = Color(0xFF39FF14),
glassReflectColor = Color(0xFFFFFFFF),
)
),
createInnerDropShadowSample(),
)
}
private fun createGradientFillShadowSample(): ShadowSample {
val config = ShadowConfig(
strokeColor = Color(0xFFFFD500),
fillColor = Color(0xFFFF6B35),
secondaryFillColor = Color(0xFFFFD500)
)
val modifier = Modifier
.width(200.dp)
.wrapContentHeight()
.dropShadow(
RoundedCornerShape(42.dp), Shadow(
radius = 1.dp,
offset = DpOffset(12.dp, 10.dp),
color = config.strokeColor,
)
)
.dropShadow(
RoundedCornerShape(42.dp), Shadow(
radius = 2.dp,
offset = DpOffset(8.dp, 6.dp),
brush = Brush.linearGradient(
colorStops = arrayOf(
0.25f to config.fillColor,
0.75f to config.secondaryFillColor,
),
start = Offset.Infinite.copy(y = 0f),
end = Offset.Infinite.copy(x = 0f),
),
)
)
.background(config.themeColor, RoundedCornerShape(40.dp))
.graphicsLayer { clip = true }
return ShadowSample(
modifier = modifier,
title = "Gradient Fill Shadow",
description = "Linear gradient shadow transitioning from orange to gold for dynamic effects.",
borderColor = config.strokeColor,
icon = Icons.Default.Gradient
)
}
private fun createFillShadowSample(): ShadowSample {
val config = ShadowConfig(strokeColor = Color(0xFFFA0505))
val modifier = Modifier
.width(200.dp)
.wrapContentHeight()
.dropShadow(
RoundedCornerShape(42.dp), Shadow(
radius = 1.dp,
offset = DpOffset(12.dp, 10.dp),
color = config.strokeColor,
)
)
.dropShadow(
RoundedCornerShape(38.dp), Shadow(
radius = 2.dp,
offset = DpOffset(8.dp, 6.dp),
color = Color(0xFFFAE0E0),
)
)
.background(config.themeColor, RoundedCornerShape(40.dp))
.graphicsLayer { clip = true }
return ShadowSample(
modifier = modifier,
title = "Chaining Drop Shadows",
description = "Chaining two drop shadows with solid color fills to create depth and dimension.",
borderColor = config.strokeColor,
icon = Icons.Default.Layers
)
}
private fun createVolumetricShadowSample(
config: ShadowConfig,
title: String = "Volumetric Shadows",
description: String = "Layering multiple gradient shadows to create realistic 3D depth and dimension.",
icon: ImageVector = Icons.Default.AutoAwesome
): ShadowSample {
val modifier = Modifier
.width(200.dp)
.wrapContentHeight()
.dropShadow(
RoundedCornerShape(40.dp), Shadow(
radius = 1.dp,
offset = DpOffset(14.dp, 10.dp),
brush = Brush.verticalGradient(
colorStops = arrayOf(
0.05f to config.strokeColor,
0.40f to config.strokeColor,
0.70f to config.glassReflectColor.copy(alpha = 0.5f),
0.85f to Color.Transparent,
1f to config.strokeColor.copy(alpha = 0.025f)
),
),
)
)
.dropShadow(
RoundedCornerShape(40.dp), Shadow(
radius = 1.dp,
offset = DpOffset(10.dp, 10.dp),
brush = Brush.horizontalGradient(
colorStops = arrayOf(
0.40f to config.strokeColor,
0.70f to config.glassReflectColor.copy(alpha = 0.5f),
0.85f to Color.Transparent,
1f to config.strokeColor.copy(alpha = 0.025f),
)
),
)
)
.dropShadow(
RoundedCornerShape(36.dp), Shadow(
radius = 2.dp,
offset = DpOffset(8.dp, 6.dp),
brush = Brush.linearGradient(
colorStops = arrayOf(
0.35f to config.fillColor,
0.50f to Color.Black,
0.75f to Color.Black,
0.90f to config.fillColor,
),
start = Offset.Infinite.copy(y = 0f),
end = Offset.Infinite.copy(x = 0f),
),
)
)
.background(config.themeColor, RoundedCornerShape(40.dp))
.graphicsLayer { clip = true }
return ShadowSample(
modifier = modifier,
title = title,
description = description,
borderColor = config.strokeColor,
icon = icon
)
}
private fun createCyanVolumetricShadowSample(
config: ShadowConfig,
title: String = "Glass Effect?",
description: String = "Combining multiple gradient shadows with transparent color stops to simulate a glassy effect.",
icon: ImageVector = Icons.Default.FilterVintage
): ShadowSample {
val modifier = Modifier
.width(200.dp)
.wrapContentHeight()
.dropShadow(
RoundedCornerShape(40.dp), Shadow(
radius = 1.dp,
offset = DpOffset(14.dp, 10.dp),
brush = Brush.verticalGradient(
colorStops = arrayOf(
0.40f to config.strokeColor,
0.70f to config.glassReflectColor.copy(alpha = 0.5f),
0.85f to Color.Transparent,
1f to config.strokeColor.copy(alpha = 0.025f)
),
),
)
)
.dropShadow(
RoundedCornerShape(40.dp), Shadow(
radius = 1.dp,
offset = DpOffset(10.dp, 10.dp),
brush = Brush.horizontalGradient(
colorStops = arrayOf(
0.40f to config.strokeColor,
0.70f to config.glassReflectColor.copy(alpha = 0.5f),
0.85f to Color.Transparent,
1f to config.strokeColor.copy(alpha = 0.025f),
)
),
)
)
.dropShadow(
RoundedCornerShape(36.dp), Shadow(
radius = 2.dp,
offset = DpOffset(8.dp, 6.dp),
brush = Brush.linearGradient(
colorStops = arrayOf(
0.025f to Color.White,
0.35f to config.fillColor,
0.50f to Color.Black,
0.75f to Color.Black,
0.90f to config.fillColor,
0.95f to Color.White,
),
start = Offset.Infinite.copy(y = 0f),
end = Offset.Infinite.copy(x = 0f),
),
)
)
.background(config.themeColor, RoundedCornerShape(40.dp))
.graphicsLayer { clip = true }
return ShadowSample(
modifier = modifier,
title = title,
description = description,
borderColor = config.strokeColor,
icon = icon
)
}
private fun createInnerDropShadowSample(): ShadowSample {
val config = ShadowConfig(
strokeColor = Color(0xFF18C9FF),
fillColor = Color(0xFFFF4081),
glassReflectColor = Color(0xFF40FFE9),
secondaryFillColor = Color(0xFF525B5B)
)
val modifier = Modifier
.width(200.dp)
.wrapContentHeight()
.dropShadow(
RoundedCornerShape(40.dp), Shadow(
radius = 1.dp,
offset = DpOffset(14.dp, 10.dp),
brush = Brush.verticalGradient(
colorStops = arrayOf(
0.40f to config.strokeColor,
0.70f to config.glassReflectColor.copy(alpha = 0.5f),
0.85f to config.glassReflectColor.copy(alpha = 0.15f),
1f to config.strokeColor.copy(alpha = 0.025f)
),
),
)
)
.dropShadow(
RoundedCornerShape(40.dp), Shadow(
radius = 1.dp,
offset = DpOffset(10.dp, 10.dp),
brush = Brush.horizontalGradient(
colorStops = arrayOf(
0.40f to config.strokeColor,
0.70f to config.glassReflectColor.copy(alpha = 0.5f),
0.85f to config.glassReflectColor.copy(alpha = 0.15f),
1f to config.strokeColor.copy(alpha = 0.025f),
)
),
)
)
.dropShadow(
RoundedCornerShape(44.dp), Shadow(
radius = 2.dp,
offset = DpOffset(8.dp, 6.dp),
brush = Brush.linearGradient(
colorStops = arrayOf(
0.05f to Color.White,
0.15f to config.secondaryFillColor,
0.35f to config.fillColor,
0.45f to config.secondaryFillColor,
0.50f to Color.Black,
0.75f to Color.Black,
0.85f to config.fillColor,
0.90f to config.secondaryFillColor,
1f to Color.White,
),
start = Offset.Infinite.copy(y = 0f),
end = Offset.Infinite.copy(x = 0f),
),
)
)
.background(config.themeColor, RoundedCornerShape(40.dp))
.innerShadow(
RoundedCornerShape(42.dp), Shadow(
radius = 50.dp,
offset = DpOffset(10.dp, -10.dp),
brush = Brush.linearGradient(
colors = listOf(
White900,
config.themeColor,
Color.Red,
config.themeColor,
)
),
)
)
.innerShadow(
RoundedCornerShape(42.dp), Shadow(
radius = 50.dp,
offset = DpOffset(-10.dp, 10.dp),
brush = Brush.linearGradient(
colors = listOf(
config.themeColor,
Cyan100,
config.themeColor,
White900,
)
),
)
)
.graphicsLayer { clip = true }
return ShadowSample(
modifier = modifier,
title = "Inner + Drop\nShadows",
description = "Looks like background blur? It's actually inner shadows with high radius values.",
borderColor = config.strokeColor,
icon = Icons.Default.MultipleStop
)
}
@Composable
fun ShadowComposable(
modifier: Modifier = Modifier,
title: String,
description: String,
borderColor: Color,
icon: ImageVector = Icons.Outlined.LightMode,
) {
Box(
modifier = modifier
.border(
width = 4.dp, color = borderColor, shape = RoundedCornerShape(36.dp)
)
.padding(12.dp)
) {
Column(
modifier = Modifier.padding(20.dp), verticalArrangement = Arrangement.SpaceBetween
) {
AnimatedContent(
targetState = icon, transitionSpec = {
(fadeIn() + slideInHorizontally { it / 2 }) togetherWith (fadeOut() + slideOutHorizontally { -it / 2 })
}, label = "IconAnimation"
) { targetIcon ->
IconBox(icon = targetIcon)
}
Spacer(modifier = Modifier.height(24.dp))
AnimatedContent(
targetState = title, transitionSpec = {
(fadeIn() + slideInHorizontally { it / 4 }) togetherWith (fadeOut() + slideOutVertically { -it / 4 })
}, label = "TitleAnimation"
) { targetTitle ->
CardTitle(title = targetTitle)
}
Spacer(modifier = Modifier.height(12.dp))
AnimatedContent(
targetState = description, transitionSpec = {
fadeIn() togetherWith fadeOut()
}, label = "DescriptionAnimation"
) { targetDescription ->
CardDescription(description = targetDescription)
}
}
}
}
@Composable
private fun IconBox(icon: ImageVector) {
Box(
modifier = Modifier
.size(48.dp)
.clip(RoundedCornerShape(12.dp))
.innerShadow(
RoundedCornerShape(12.dp), Shadow(
12.dp,
brush = Brush.linearGradient(
colors = listOf(White900, Gray900),
start = Offset(90f, -90f),
end = Offset.Zero
),
)
)
.border(
width = 1.dp, color = Black950, shape = RoundedCornerShape(12.dp)
)
.padding(12.dp)
) {
Icon(
imageVector = icon,
contentDescription = null,
tint = Color.White,
modifier = Modifier.fillMaxSize()
)
}
}
@Composable
private fun CardTitle(title: String) {
Text(
text = title,
color = Color.White,
fontSize = 20.sp,
fontWeight = FontWeight.ExtraBold,
lineHeight = 24.sp
)
}
@Composable
private fun CardDescription(description: String) {
Text(
text = description, color = Gray400, fontSize = 14.sp
)
}
@Preview
@Composable
fun ShadowsScreenPreview() {
val sample = createCyanVolumetricShadowSample(
ShadowConfig(
strokeColor = Color(0xFF00F5FF),
fillColor = Color(0xFFFF00FF),
secondaryFillColor = Color(0xFF9D00FF),
glassReflectColor = Color(0xFFFFFFFF)
),
title = "Glass Effect?",
description = "Combining multiple gradient shadows with transparent color stops to simulate a glassy effect.",
icon = Icons.Default.AutoAwesome
)
Box(
modifier = Modifier
.background(Black900)
.padding(100.dp)
) {
ShadowComposable(
sample.modifier,
title = sample.title,
description = sample.description,
borderColor = sample.borderColor,
icon = sample.icon
)
}
}