@@ -47,6 +47,7 @@ import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
4747import androidx.compose.foundation.lazy.staggeredgrid.items
4848import androidx.compose.foundation.rememberScrollState
4949import androidx.compose.foundation.verticalScroll
50+ import androidx.compose.material3.Button
5051import androidx.compose.material3.Text
5152import androidx.compose.runtime.Composable
5253import androidx.compose.runtime.LaunchedEffect
@@ -67,11 +68,11 @@ import androidx.paging.compose.itemKey
6768import coil.compose.AsyncImage
6869import coil.compose.rememberAsyncImagePainter
6970import com.example.compose.snippets.util.randomSampleImageUrl
70- import kotlin.random.Random
7171import kotlinx.coroutines.flow.distinctUntilChanged
7272import kotlinx.coroutines.flow.filter
7373import kotlinx.coroutines.flow.map
7474import kotlinx.coroutines.launch
75+ import kotlin.random.Random
7576
7677private object ListsSnippetsColumn {
7778 // [START android_compose_layouts_list_column]
@@ -742,3 +743,28 @@ private val randomSizedPhotos = listOf(
742743 randomSampleImageUrl(width = 1600 , height = 900 ),
743744 randomSampleImageUrl(width = 500 , height = 500 ),
744745)
746+
747+ // [START android_compose_lists_snap_scroll_button]
748+ @Composable
749+ fun MessageList (modifier : Modifier = Modifier ) {
750+ val listState = rememberLazyListState()
751+ val coroutineScope = rememberCoroutineScope()
752+
753+ LazyColumn (state = listState, modifier = Modifier .height(120 .dp)) {
754+ items(10 ) { index ->
755+ Text (
756+ modifier = Modifier .height(40 .dp),
757+ text = " Item $index "
758+ )
759+ }
760+ }
761+
762+ Button (onClick = {
763+ coroutineScope.launch {
764+ listState.animateScrollToItem(index = 0 )
765+ }
766+ }) {
767+ Text (text = " Go top" )
768+ }
769+ }
770+ // [END android_compose_lists_snap_scroll_button]
0 commit comments