feat(android): switch comments page to a swipe action

This commit is contained in:
Harsh Shandilya 2023-08-02 01:28:48 +05:30
parent 45b6f3c4d5
commit bae671ad23
No known key found for this signature in database
4 changed files with 26 additions and 12 deletions

View file

@ -77,6 +77,7 @@ dependencies {
implementation(libs.napier)
implementation(libs.soloader)
implementation(libs.sqldelight.extensions.coroutines)
implementation(libs.swipe)
implementation(libs.unfurl)
implementation(projects.api)
implementation(projects.common)

View file

@ -1,18 +1,24 @@
/*
* Copyright © 2021-2022 Harsh Shandilya.
* Copyright © 2021-2023 Harsh Shandilya.
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/
package dev.msfjarvis.claw.android.ui.lists
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Reply
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.produceState
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import dev.msfjarvis.claw.common.posts.LobstersCard
import dev.msfjarvis.claw.common.posts.PostActions
import dev.msfjarvis.claw.database.local.SavedPost
import me.saket.swipe.SwipeAction
import me.saket.swipe.SwipeableActionsBox
@Composable
fun ListItem(
@ -22,10 +28,20 @@ fun ListItem(
modifier: Modifier = Modifier,
) {
val saved by produceState(false, item) { value = isSaved(item) }
LobstersCard(
post = item,
isSaved = saved,
postActions = postActions,
modifier = modifier,
)
val commentsAction =
SwipeAction(
icon = rememberVectorPainter(Icons.Filled.Reply),
background = MaterialTheme.colorScheme.tertiary,
onSwipe = { postActions.viewCommentsPage(item.commentsUrl) },
)
SwipeableActionsBox(
endActions = listOf(commentsAction),
) {
LobstersCard(
post = item,
isSaved = saved,
postActions = postActions,
modifier = modifier,
)
}
}