File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
compose/snippets/src/main/java/com/example/compose/snippets/lists Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
47
47
import androidx.compose.foundation.lazy.staggeredgrid.items
48
48
import androidx.compose.foundation.rememberScrollState
49
49
import androidx.compose.foundation.verticalScroll
50
+ import androidx.compose.material3.Button
50
51
import androidx.compose.material3.Text
51
52
import androidx.compose.runtime.Composable
52
53
import androidx.compose.runtime.LaunchedEffect
@@ -742,3 +743,28 @@ private val randomSizedPhotos = listOf(
742
743
randomSampleImageUrl(width = 1600 , height = 900 ),
743
744
randomSampleImageUrl(width = 500 , height = 500 ),
744
745
)
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]
You can’t perform that action at this time.
0 commit comments