Skip to content

Instantly share code, notes, and snippets.

@zivkesten
Last active February 11, 2022 00:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zivkesten/e56e964e9ea166ad092cad69e1e5e036 to your computer and use it in GitHub Desktop.
Save zivkesten/e56e964e9ea166ad092cad69e1e5e036 to your computer and use it in GitHub Desktop.
Expandable Item
@Composable
fun ExpandableListItem() {
var expanded by remember { mutableStateOf(true) }
Card(
elevation = 4.dp,
modifier = Modifier
.fillMaxWidth()
.padding(start = 15.dp, top = 15.dp, end = 15.dp)
.clip(RoundedCornerShape(8.dp))
.clickable(onClick = { expanded = !expanded })
) {
Column(modifier = Modifier.fillMaxWidth().background(colorResource(id = R.color.lemonade_glass))) {
Row(horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier
.padding(end = 32.dp)
.fillMaxWidth()
) {
TitleAndSubtitle(
title = "Expandable item title",
subtitle = "There are more items below! 👇"
)
Icon(
imageVector = Icons.Default.ArrowDropDown,
contentDescription = "ArrowIcon",
modifier = Modifier
.align(CenterVertically)
.graphicsLayer(
rotationZ = animateFloatAsState(
if (expanded) 180f else 0f
).value,
)
)
}
AnimatedVisibility(
visible = expanded,
enter = expandVertically(
animationSpec = tween(durationMillis = 300, easing = FastOutLinearInEasing)
),
exit = shrinkVertically(
animationSpec = tween(durationMillis = 300, easing = FastOutLinearInEasing)
)
) {
Divider(modifier = Modifier.height(1.dp))
Column(modifier = Modifier.padding(start = 15.dp, end = 15.dp, bottom = 15.dp)) {
Spacer(modifier = Modifier.height(10.dp))
ExtraItem(item = Item(
"Look at the date here",
"March 2, 1998")
)
Spacer(modifier = Modifier.height(10.dp))
Divider(modifier = Modifier.height(1.dp))
Spacer(modifier = Modifier.height(10.dp))
ExtraItem(item = Item(
"Message about stuff",
"June 21, 1982")
)
Spacer(modifier = Modifier.height(10.dp))
Divider(modifier = Modifier.height(1.dp))
Spacer(modifier = Modifier.height(10.dp))
ExtraItem(item = Item(
"Look at the date here",
"March 2, 1998")
)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment