app: switch to LazyColumn

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-12-17 01:12:08 +05:30
parent 60620eccec
commit 4922f3daf8
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
2 changed files with 21 additions and 18 deletions

View file

@ -8,7 +8,7 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumnFor
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Surface
import androidx.compose.material.Text
@ -150,13 +150,15 @@ fun TagRow(
@Preview
fun Preview() {
LobstersTheme {
LazyColumnFor(items = listOf(TEST_POST, TEST_POST, TEST_POST, TEST_POST, TEST_POST)) { item ->
LobstersItem(
post = item,
onClick = {},
onLongClick = {},
onSaveButtonClick = {},
)
LazyColumn {
items(listOf(TEST_POST, TEST_POST, TEST_POST, TEST_POST, TEST_POST)) { item ->
LobstersItem(
post = item,
onClick = {},
onLongClick = {},
onSaveButtonClick = {},
)
}
}
}
}

View file

@ -1,7 +1,7 @@
package dev.msfjarvis.lobsters.ui.posts
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumnFor
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
@ -21,17 +21,18 @@ fun SavedPosts(
if (posts.isEmpty()) {
EmptyList(saved = true)
} else {
LazyColumnFor(
items = posts,
LazyColumn(
state = listState,
modifier = Modifier.padding(horizontal = 8.dp).then(modifier)
) { item ->
LobstersItem(
post = item,
onClick = { urlLauncher.launch(item.url.ifEmpty { item.commentsUrl }) },
onLongClick = { urlLauncher.launch(item.commentsUrl) },
onSaveButtonClick = { saveAction.invoke(item) },
)
) {
items(posts) { item ->
LobstersItem(
post = item,
onClick = { urlLauncher.launch(item.url.ifEmpty { item.commentsUrl }) },
onLongClick = { urlLauncher.launch(item.commentsUrl) },
onSaveButtonClick = { saveAction.invoke(item) },
)
}
}
}
}