Fixed icon color in compact secondary button

This commit is contained in:
Abdelilah El Aissaoui 2023-04-25 22:34:13 +02:00
parent 35d7b23913
commit 61151e8571
No known key found for this signature in database
GPG Key ID: 7587FC860F594869
2 changed files with 10 additions and 8 deletions

View File

@ -8,7 +8,6 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.focusable
import androidx.compose.foundation.hoverable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsHoveredAsState
@ -25,7 +24,6 @@ import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.input.key.onPreviewKeyEvent
@ -652,7 +650,7 @@ private fun EntriesList(
icon = actionIcon,
isParentHovered = isHeaderHovered,
backgroundButton = actionColor,
textColor = actionTextColor,
onBackgroundColor = actionTextColor,
onClick = onAllAction,
modifier = Modifier.padding(start = 4.dp, end = 16.dp),
)

View File

@ -55,7 +55,7 @@ fun SecondaryButtonCompactable(
modifier: Modifier = Modifier,
icon: String,
text: String,
textColor: Color = MaterialTheme.colors.onPrimary,
onBackgroundColor: Color = MaterialTheme.colors.onPrimary,
backgroundButton: Color,
maxLines: Int = 1,
isParentHovered: Boolean,
@ -74,23 +74,27 @@ fun SecondaryButtonCompactable(
}
val targetBackground: Color
val iconColor: Color
val iconPadding: Float
if (isExpanded) {
targetBackground = backgroundButton
iconColor = onBackgroundColor
iconPadding = 12f
} else {
targetBackground = MaterialTheme.colors.tertiarySurface
iconColor = MaterialTheme.colors.onBackground
iconPadding = 0f
}
val color by animateColorAsState(targetBackground)
val backgroundColorState by animateColorAsState(targetBackground)
val iconColorState by animateColorAsState(iconColor)
val iconPaddingState by animateFloatAsState(iconPadding)
Row(
modifier = modifier
.clip(RoundedCornerShape(4.dp))
.background(color)
.background(backgroundColorState)
.hoverable(hoverInteraction)
.handMouseClickable { onClick() }
.padding(horizontal = 4.dp),
@ -99,7 +103,7 @@ fun SecondaryButtonCompactable(
Icon(
painterResource(icon),
contentDescription = null,
tint = MaterialTheme.colors.onBackground,
tint = iconColorState,
modifier = Modifier
.padding(start = iconPaddingState.dp, end = 8.dp)
.size(18.dp)
@ -111,7 +115,7 @@ fun SecondaryButtonCompactable(
Text(
text = text,
style = MaterialTheme.typography.body2,
color = textColor,
color = onBackgroundColor,
maxLines = maxLines,
modifier = Modifier.padding(top = 4.dp, bottom = 4.dp, end = 12.dp)
)