Skip to content

Commit

Permalink
BAU BAU - Why not generating cards every 0.5 sec?
Browse files Browse the repository at this point in the history
  • Loading branch information
Loup-1234 committed Mar 8, 2024
1 parent b9c2425 commit f201388
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
43 changes: 39 additions & 4 deletions .idea/cody_history.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,33 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import com.example.an_other_manga_app.R
import kotlinx.coroutines.delay

@Composable
fun LibraryFragment(navController: NavHostController) {
val items = generateInfiniteListOfItems()
Box(modifier = Modifier.padding(bottom = 80.dp)) {
LazyVerticalGrid(
columns = GridCells.Fixed(2),
contentPadding = PaddingValues(8.dp)
) {
items(10) { index ->
items(items) { index ->
Box(
modifier = Modifier
.fillMaxSize()
Expand Down Expand Up @@ -73,4 +79,22 @@ fun LibraryFragment(navController: NavHostController) {
}
}
}
}

data class Item(val id: Int)

@Composable
fun generateInfiniteListOfItems(): List<Item> {

val items = remember { mutableStateListOf<Item>() }

LaunchedEffect(Unit) {
var index = 0
while(true) {
items.add(Item(index++))
delay(500)
}
}

return items
}

0 comments on commit f201388

Please sign in to comment.