Add Util Function to ease life

This commit is contained in:
Iamlooker 2022-04-24 00:54:14 +05:30
parent a7e9949d44
commit 1e9dd3f03a
3 changed files with 24 additions and 5 deletions

View File

@ -21,6 +21,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.looker.droidify.ui.compose.utils.compositeOverBackground
private enum class SelectionState { Unselected, Selected }
@ -49,7 +50,10 @@ private fun categoryChipTransition(selected: Boolean): CategoryChipTransition {
val contentColor = transition.animateColor(label = "chip_content_alpha") { state ->
when (state) {
SelectionState.Unselected -> MaterialTheme.colorScheme.surface
SelectionState.Selected -> MaterialTheme.colorScheme.inversePrimary.copy(alpha = 0.8f)
SelectionState.Selected -> MaterialTheme.colorScheme.primaryContainer.compositeOverBackground(
alpha = 0.8f,
background = MaterialTheme.colorScheme.onBackground
)
}
}
val checkScale = transition.animateFloat(

View File

@ -10,7 +10,6 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@ -30,11 +29,13 @@ fun CustomChip(
shape = Shapes.Full,
border = BorderStroke(
width = borderWidth,
color = borderColor.copy(0.5f).compositeOver(MaterialTheme.colorScheme.surface)
color = borderColor.compositeOverBackground(
alpha = 0.5f,
MaterialTheme.colorScheme.surface
)
),
colors = chipColors(
backgroundColor = containerColor.copy(0.1f)
.compositeOver(MaterialTheme.colorScheme.background)
backgroundColor = containerColor.compositeOverBackground(alpha = 0.1f)
),
onClick = { onClick(text) }
) {

View File

@ -0,0 +1,14 @@
package com.looker.droidify.ui.compose.utils
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
@Stable
@Composable
fun Color.compositeOverBackground(
alpha: Float,
background: Color = MaterialTheme.colorScheme.background
) = this.copy(alpha).compositeOver(background)