Skip to content

Commit 1baf215

Browse files
authored
Update README.md
1 parent 36412b9 commit 1baf215

File tree

1 file changed

+202
-0
lines changed

1 file changed

+202
-0
lines changed

README.md

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

0 commit comments

Comments
 (0)