android6-1 Exercise 2: Expandable cards and scroll to top ====================================================== import androidx.compose.animation.animateContentSize import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material3.Card import androidx.compose.material3.Text import androidx.compose.runtime.* import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp @Composable fun ExpandableNote(text: String, modifier: Modifier = Modifier) { var expanded by rememberSaveable { mutableStateOf(false) } Card( modifier = modifier .animateContentSize() // before the size modifiers, per the docs .fillMaxWidth() .clickable { expanded = !expanded } ) { Text( text = text, maxLines = if (expanded) Int.MAX_VALUE else 2, overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(16.dp) ) } } import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.KeyboardArrowUp import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.Icon import androidx.compose.runtime.* import kotlinx.coroutines.launch @Composable fun NotesList(notes: List) { val listState = rememberLazyListState() val scope = rememberCoroutineScope() // Recomputes only when the answer changes, not on every scroll pixel val showScrollToTop by remember { derivedStateOf { listState.firstVisibleItemIndex > 0 } } Box { LazyColumn(state = listState) { items(notes, key = { it.id }, contentType = { "note" }) { note -> ExpandableNote(text = note.text) } } AnimatedVisibility(visible = showScrollToTop, modifier = Modifier.align(Alignment.BottomEnd)) { FloatingActionButton(onClick = { scope.launch { listState.animateScrollToItem(0) } }) { Icon(Icons.Filled.KeyboardArrowUp, contentDescription = "Scroll to top") } } } } Test: add 40+ notes (the refresh from Android Development with Compose: Architecture & Data 7 gives 100 sample notes). Expected: cards expand and collapse with an animated size change; the button appears after scrolling past the first item, fades in and out, and scrolls to the top. computedStateOf: the docs search said Compose 1.13 introduced it and recommends it over derivedStateOf for most cases. Check your Compose BOM or Compose runtime version in the version catalog, open the current Compose State docs, and note whether it is available and what its signature is. If it is, switch and compare. Report your findings; the signature is not confirmed here. Code unrun.