Skip to content

Instantly share code, notes, and snippets.

@rubywai
Created January 18, 2026 17:36
Show Gist options
  • Select an option

  • Save rubywai/d1f48f1b639296b23106299c9fe2bfbd to your computer and use it in GitHub Desktop.

Select an option

Save rubywai/d1f48f1b639296b23106299c9fe2bfbd to your computer and use it in GitHub Desktop.
@10 list (lazy row & lazy column)
package com.rubylearner.composeapp
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Person
import androidx.compose.material3.ElevatedButton
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.ListItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.rubylearner.composeapp.ui.theme.ComposeAppTheme
class MainActivity : ComponentActivity() {
@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
ComposeAppTheme {
Scaffold(
modifier = Modifier.fillMaxSize(),
topBar = {
TopAppBar(
title = {
Text("My Compose Lesson")
}
)
}
) { innerPadding ->
MyCompose(
modifier = Modifier.padding(innerPadding)
)
}
}
}
}
@Composable
fun MyCompose(modifier: Modifier) {
//mutable
//recomposition
val contactStateList = remember {
mutableStateListOf("Person 1", "Person 2")
}
Column(modifier = modifier) {
Text("Active persons")
LazyRow {
items(30){
Box(modifier = Modifier
.padding(4.dp)
.background (color= Color.Gray, shape = RoundedCornerShape(20))) {
Column(
modifier = Modifier.padding(8.dp)
) {
Icon(Icons.Default.Person, contentDescription = "Person $it")
Text("Person $it")
}
}
}
}
ElevatedButton(onClick = {
contactStateList.add("Person ${contactStateList.size + 1}")
}) {
Text("Add Person")
}
LazyColumn {
items(contactStateList.size) {
ListItem(
modifier = Modifier.animateItem(
fadeInSpec = tween(durationMillis = 1000),
fadeOutSpec = tween(durationMillis = 1000),
placementSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
)
),
leadingContent = {
Icon(Icons.Filled.Person, contentDescription = "Person $it")
},
headlineContent = {
Text(contactStateList[it])
},
supportingContent = {
Text("099999999")
},
trailingContent = {
IconButton(
onClick = {
contactStateList.removeAt(it)
}
) {
Icon(
Icons.Default.Delete,
contentDescription = "Delete Person $it",
)
}
}
)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment