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

View file

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