Skip to content

Instantly share code, notes, and snippets.

@fjr619
Created August 16, 2022 06:22
Show Gist options
  • Save fjr619/be5441117a7b59471efb64f41f5ce4e9 to your computer and use it in GitHub Desktop.
Save fjr619/be5441117a7b59471efb64f41f5ce4e9 to your computer and use it in GitHub Desktop.
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
val books = (1..10).map { "Book $it" }.toList()
val wishlisted = (1..50).map { "Wishlisted Book $it" }
@Composable
fun NestedScrollScreen() {
LazyColumn(
modifier = Modifier.fillMaxSize(),
) {
// My Books section
item {
Column(modifier = Modifier.fillMaxWidth()) {
Text("My Books", style = MaterialTheme.typography.h4)
LazyRow(
modifier = Modifier
.fillMaxWidth()
) {
items(books) { item ->
Box(
modifier = Modifier
.padding(4.dp)
.height(120.dp)
.width(90.dp)
.background(color = Color.Gray, shape = RoundedCornerShape(8.dp))
) {
Text(item, modifier = Modifier.align(Alignment.Center))
}
}
}
}
}
item {
Text("Whishlisted Books", style = MaterialTheme.typography.h4)
}
// // Turning the list in a list of lists of two elements each
items(wishlisted.windowed(2, 2, true)) { sublist ->
Row(Modifier.fillMaxWidth()) {
sublist.forEach { item ->
Text(
item, modifier = Modifier
.height(120.dp)
.padding(4.dp)
.background(Color.Yellow)
.fillParentMaxWidth(.5f)
)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment