Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
import androidx.compose.foundation.lazy.staggeredgrid.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand Down Expand Up @@ -742,3 +743,28 @@ private val randomSizedPhotos = listOf(
randomSampleImageUrl(width = 1600, height = 900),
randomSampleImageUrl(width = 500, height = 500),
)

// [START android_compose_lists_snap_scroll_button]
@Composable
fun MessageList(modifier: Modifier = Modifier) {
val listState = rememberLazyListState()
val coroutineScope = rememberCoroutineScope()

LazyColumn(state = listState, modifier = Modifier.height(120.dp)) {
items(10) { index ->
Text(
modifier = Modifier.height(40.dp),
text = "Item $index"
)
}
}

Button(onClick = {
coroutineScope.launch {
listState.animateScrollToItem(index = 0)
}
}) {
Text(text = "Go top")
}
}
// [END android_compose_lists_snap_scroll_button]