Align post action icons properly in LobstersCard (#300)

This commit is contained in:
Sasikanth Miriyampalli 2022-02-20 16:26:11 +05:30 committed by GitHub
parent 3b833083e1
commit 01a2bbc55d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredSize import androidx.compose.foundation.layout.requiredSize
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ripple.rememberRipple import androidx.compose.material.ripple.rememberRipple
@ -50,9 +51,14 @@ fun LobstersCard(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
var localSavedState by remember(post, isSaved) { mutableStateOf(isSaved) } var localSavedState by remember(post, isSaved) { mutableStateOf(isSaved) }
Box(modifier = modifier.clickable { postActions.viewPost(post.url, post.commentsUrl) }) { Box(
modifier =
modifier
.fillMaxWidth()
.clickable { postActions.viewPost(post.url, post.commentsUrl) }
.padding(start = 16.dp, top = 16.dp, end = 4.dp, bottom = 16.dp),
) {
Row( Row(
modifier = Modifier.fillMaxWidth().padding(16.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
) { ) {
@ -61,7 +67,7 @@ fun LobstersCard(
post = post, post = post,
) )
Column( Column(
modifier = Modifier.weight(0.15f).fillMaxHeight(), modifier = Modifier.fillMaxHeight(),
verticalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
) { ) {
@ -77,7 +83,7 @@ fun LobstersCard(
postActions.toggleSave(post) postActions.toggleSave(post)
}, },
) )
Divider() Divider(modifier = Modifier.width(48.dp))
CommentsButton( CommentsButton(
modifier = modifier =
Modifier.combinedClickable( Modifier.combinedClickable(
@ -148,25 +154,29 @@ fun SaveButton(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
Crossfade(targetState = isSaved) { saved -> Crossfade(targetState = isSaved) { saved ->
Box(modifier = modifier.padding(12.dp)) {
Icon( Icon(
painter = if (saved) heartIcon else heartBorderIcon, painter = if (saved) heartIcon else heartBorderIcon,
tint = MaterialTheme.colorScheme.secondary, tint = MaterialTheme.colorScheme.secondary,
contentDescription = if (saved) "Remove from saved posts" else "Add to saved posts", contentDescription = if (saved) "Remove from saved posts" else "Add to saved posts",
modifier = modifier.padding(12.dp), modifier = Modifier.align(Alignment.Center)
) )
} }
}
} }
@Composable @Composable
fun CommentsButton( fun CommentsButton(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
Box(modifier = modifier.padding(12.dp)) {
Icon( Icon(
painter = commentIcon, painter = commentIcon,
tint = MaterialTheme.colorScheme.secondary, tint = MaterialTheme.colorScheme.secondary,
contentDescription = "Open comments", contentDescription = "Open comments",
modifier = modifier.padding(12.dp), modifier = Modifier.align(Alignment.Center),
) )
}
} }
@Composable @Composable