Skip to content

Commit 823cb4e

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents be958fc + 6403d38 commit 823cb4e

File tree

1 file changed

+211
-4
lines changed

1 file changed

+211
-4
lines changed

README.md

Lines changed: 211 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ Add Animatable Material Components in Android Jetpack Compose.
55
Create jetpack compose animation painless.
66

77
What you can create from Material 3 components right now;
8+
* Spacer Animation
89
* Text Animation
910
* Box Animation
1011
* Card Animation
1112
* Icon Animation
12-
* Lazy Row Animation
13+
* LazyRow Animation
1314
* and combinations
1415

1516
## How it looks
1617

17-
|Phone Number|Card Dealer|Insta Story|
18-
|------------|-----------|-----------|
19-
|<img src="https://user-images.githubusercontent.com/50905347/197984728-7bfe5536-b78e-41e1-91cb-5bc167e51850.gif" width="250" height="530">|<img src="https://user-images.githubusercontent.com/50905347/198032696-f78f2b66-964c-494d-9614-14107ecde244.gif" width="250" height="530">|<img src="https://user-images.githubusercontent.com/50905347/199718888-823d86d1-68c9-45cd-9844-590480efe71c.gif" width="250" height="530">|
18+
|Phone Number|Card Dealer|
19+
|------------|-----------|
20+
|<img src="https://user-images.githubusercontent.com/50905347/197984728-7bfe5536-b78e-41e1-91cb-5bc167e51850.gif" width="250" height="530">|<img src="https://user-images.githubusercontent.com/50905347/198032696-f78f2b66-964c-494d-9614-14107ecde244.gif" width="250" height="530">|
2021

2122
### Phone Number
2223

@@ -203,6 +204,10 @@ Box(
203204
```
204205
</details>
205206

207+
|Insta Story|Info Card|
208+
|-----------|---------|
209+
|<img src="https://user-images.githubusercontent.com/50905347/199718888-823d86d1-68c9-45cd-9844-590480efe71c.gif" width="250" height="530">|<img src="https://user-images.githubusercontent.com/50905347/199983119-bb8bcdbf-81da-4352-8d2c-74571577654a.gif" width="250" height="530">|
210+
206211
### Insta Story
207212

208213
<details closed>
@@ -307,6 +312,208 @@ data class Story(
307312
}
308313
```
309314
</details>
315+
316+
### Info Card
317+
318+
<details closed>
319+
<summary>States</summary>
320+
<br>
321+
322+
323+
```kotlin
324+
val lazyListState = rememberLazyListState()
325+
val snapperFlingBehavior = rememberSnapperFlingBehavior(
326+
lazyListState = lazyListState,
327+
snapOffsetForItem = SnapOffsets.Start,
328+
)
329+
val scope = rememberCoroutineScope()
330+
var selectedIndex by remember { mutableStateOf(0) }
331+
332+
val animatableCardState = rememberAnimatableCardState(
333+
initialSize = DpSize(width = 340.dp, height = 180.dp),
334+
targetSize = DpSize(width = Dp.Infinity, height = 340.dp),
335+
initialShape = RoundedCornerShape(32.dp),
336+
targetShape = RoundedCornerShape(0.dp, 0.dp, 32.dp, 32.dp),
337+
toTargetShapeAnimationSpec = tween(750),
338+
initialPadding = PaddingValues(horizontal = 8.dp),
339+
targetPadding = PaddingValues(0.dp),
340+
onAnimation = {
341+
when(it) {
342+
AnimationState.INITIAL -> {}
343+
AnimationState.INITIAL_TO_TARGET -> {
344+
scope.launch {
345+
delay(500)
346+
lazyListState.animateScrollToItem(selectedIndex)
347+
}
348+
}
349+
AnimationState.TARGET -> {}
350+
AnimationState.TARGET_TO_INITIAL -> {}
351+
}
352+
}
353+
)
354+
val animatableBoxState = rememberAnimatableBoxState(
355+
initialAlignment = Alignment.Center,
356+
targetAlignment = Alignment.TopCenter
357+
)
358+
val animatableTextState = rememberAnimatableTextState(
359+
initialFontSize = 0.sp,
360+
targetFontSize = 12.sp,
361+
initialOffset = DpOffset(x = 0.dp, y = 300.dp),
362+
targetOffset = DpOffset(x = 0.dp, y = 0.dp),
363+
toTargetAnimationSpec = tween(250)
364+
)
365+
val animatableSpacerState = rememberAnimatableSpacerState(
366+
initialSize = DpSize(width = 0.dp, height = 0.dp),
367+
targetSize = DpSize(width = 0.dp, height = 16.dp)
368+
)
369+
370+
val infoCards by remember { mutableStateOf(InfoCard.infoCards) }
371+
372+
val cardStates = mutableListOf<AnimatableState>()
373+
val boxStates = mutableListOf<AnimatableState>()
374+
val textStates = mutableListOf<AnimatableState>()
375+
val spacerStates = mutableListOf<AnimatableState>()
376+
377+
infoCards.indices.forEach { index ->
378+
cardStates.add(
379+
animatableCardState.copy(
380+
index = index
381+
)
382+
)
383+
boxStates.add(
384+
animatableBoxState.copy(
385+
index = index
386+
)
387+
)
388+
textStates.add(
389+
animatableTextState.copy(
390+
index = index
391+
)
392+
)
393+
if(index == 0) {
394+
spacerStates.add(
395+
animatableSpacerState.copy(
396+
index = index,
397+
initialSize = DpSize(width = 0.dp, height = 300.dp),
398+
targetSize = DpSize(width = 0.dp, height = 0.dp)
399+
)
400+
)
401+
}
402+
spacerStates.add(
403+
animatableSpacerState.copy(
404+
index = index + 1,
405+
)
406+
)
407+
}
408+
409+
val sharedAnimatableState = rememberSharedAnimatableState(
410+
animatableStates = cardStates + boxStates + textStates + spacerStates
411+
)
412+
```
413+
</details>
414+
<details closed>
415+
<summary>Components</summary>
416+
<br>
417+
418+
419+
```kotlin
420+
Column(
421+
modifier = Modifier.fillMaxSize(),
422+
) {
423+
AnimatableSpacer(
424+
state = sharedAnimatableState
425+
)
426+
LazyRow(
427+
verticalAlignment = Alignment.CenterVertically,
428+
state = lazyListState,
429+
flingBehavior = snapperFlingBehavior
430+
) {
431+
items(infoCards.size) { index ->
432+
AnimatableCard(
433+
onClick = {
434+
selectedIndex = index
435+
sharedAnimatableState.animate()
436+
},
437+
state = sharedAnimatableState,
438+
stateIndex = index,
439+
colors = CardDefaults.cardColors(
440+
containerColor = Color(0xFFE9E7FE)
441+
)
442+
) {
443+
Row(
444+
modifier = Modifier.fillMaxSize(),
445+
verticalAlignment = Alignment.CenterVertically,
446+
horizontalArrangement = Arrangement.SpaceBetween
447+
) {
448+
AnimatableBox(
449+
modifier = Modifier
450+
.weight(1f)
451+
.fillMaxHeight()
452+
.padding(16.dp),
453+
stateIndex = index,
454+
state = sharedAnimatableState
455+
) {
456+
LazyColumn(horizontalAlignment = Alignment.CenterHorizontally) {
457+
item {
458+
Text(
459+
text = infoCards[index].title,
460+
fontSize = 22.sp,
461+
fontWeight = FontWeight.Bold
462+
)
463+
Text(
464+
modifier = Modifier.align(Alignment.CenterStart),
465+
text = "MGS 1",
466+
fontSize = 12.sp,
467+
color = Color.Gray
468+
)
469+
AnimatableSpacer(
470+
stateIndex = index + 1,
471+
state = sharedAnimatableState
472+
)
473+
AnimatableText(
474+
text = infoCards[index].info,
475+
stateIndex = index,
476+
state = sharedAnimatableState,
477+
fontWeight = FontWeight.Bold
478+
)
479+
}
480+
}
481+
}
482+
AsyncImage(
483+
modifier = Modifier
484+
.weight(1f)
485+
.padding(8.dp)
486+
.clip(RoundedCornerShape(32.dp)),
487+
model = infoCards[index].imageUrl,
488+
contentDescription = null,
489+
contentScale = ContentScale.Crop
490+
)
491+
}
492+
}
493+
}
494+
}
495+
}
496+
```
497+
</details>
498+
<details closed>
499+
<summary>Data</summary>
500+
<br>
501+
502+
503+
```kotlin
504+
data class InfoCard(
505+
val imageUrl: String,
506+
val title: String,
507+
val info: String
508+
){
509+
companion object {
510+
val infoCards = listOf(
511+
//
512+
)
513+
}
514+
}
515+
```
516+
</details>
310517
311518
## How to use
312519

0 commit comments

Comments
 (0)