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
| @ExperimentalMaterialApi @Composable fun ExpandableCard( title: String, titleFontSize: TextUnit = MaterialTheme.typography.h6.fontSize, titleFontWeight: FontWeight = FontWeight.Bold, description: String, descriptionFontSize: TextUnit = MaterialTheme.typography.subtitle1.fontSize, descriptionFontWeight: FontWeight = FontWeight.Normal, descriptionMaxLines: Int = 4, shape: Shape = Shapes.medium, padding: Dp = 12.dp ) { var expandedState by remember { mutableStateOf(false) } val rotationState by animateFloatAsState( targetValue = if (expandedState) 180f else 0f )
Card( modifier = Modifier .fillMaxWidth() .animateContentSize( animationSpec = tween( durationMillis = 300, easing = LinearOutSlowInEasing ) ), shape = shape, onClick = { expandedState = !expandedState } ) { Column( modifier = Modifier .fillMaxWidth() .padding(padding) ) { Row( verticalAlignment = Alignment.CenterVertically ) { Text( modifier = Modifier .weight(6f), text = title, fontSize = titleFontSize, fontWeight = titleFontWeight, maxLines = 1, overflow = TextOverflow.Ellipsis ) IconButton( modifier = Modifier .weight(1f) .alpha(ContentAlpha.medium) .rotate(rotationState), onClick = { expandedState = !expandedState }) { Icon( imageVector = Icons.Default.ArrowDropDown, contentDescription = "Drop-Down Arrow" ) } } if (expandedState) { Text( text = description, fontSize = descriptionFontSize, fontWeight = descriptionFontWeight, maxLines = descriptionMaxLines, overflow = TextOverflow.Ellipsis ) } } } }
|