Skip to content

Commit

Permalink
added more colors to material you palette by #847
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Mar 4, 2024
1 parent 552ae64 commit 61ffc60
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ fun Modifier.container(
clip: Boolean = true,
composeColorOnTopOfBackground: Boolean = true,
isShadowClip: Boolean = false,
isStandaloneContainer: Boolean = true
isStandaloneContainer: Boolean = true,
shadowColor: Color = Color.Black
) = this.composed {
val localContainerShape = LocalContainerShape.current
val resultShape = localContainerShape ?: shape
Expand Down Expand Up @@ -119,7 +120,8 @@ fun Modifier.container(
enabled = if (isStandaloneContainer) {
settingsState.drawContainerShadows
} else true,
isClipped = isShadowClip
isClipped = isShadowClip,
color = shadowColor
)
.then(
if (resultShape is CornerBasedShape) cornerModifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Outline
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.Density
Expand All @@ -41,7 +42,8 @@ fun Modifier.materialShadow(
shape: Shape,
elevation: Dp,
enabled: Boolean = true,
isClipped: Boolean = true
isClipped: Boolean = true,
color: Color = Color.Black
) = this.composed {
val isConcavePath by remember(shape) {
derivedStateOf {
Expand All @@ -59,19 +61,24 @@ fun Modifier.materialShadow(
val api29Shadow = if (isClipped) {
Modifier.clippedShadow(
shape = shape,
elevation = elev
elevation = elev,
ambientColor = color,
spotColor = color
)
} else {
Modifier.shadow(
shape = shape,
elevation = elev
elevation = elev,
ambientColor = color,
spotColor = color
)
}

val api21shadow = Modifier.rsBlurShadow(
shape = shape,
radius = elev,
isAlphaContentClip = isClipped
isAlphaContentClip = isClipped,
color = color
)
when {
isConcavePath && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q -> api21shadow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.material.Icon
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ContentPaste
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,39 @@ fun MaterialYouPaletteGroup(
)
}

Row(
modifier = Modifier.height(IntrinsicSize.Max)
) {
MaterialYouPaletteItem(
color = colorScheme.inversePrimary,
colorScheme = colorScheme,
name = "Inverse Primary",
onCopy = onCopy,
modifier = Modifier.weight(1f)
)
MaterialYouPaletteItem(
color = colorScheme.surfaceTint,
colorScheme = colorScheme,
name = "Surface Tint",
onCopy = onCopy,
modifier = Modifier.weight(1f)
)
MaterialYouPaletteItem(
color = colorScheme.surfaceDim,
colorScheme = colorScheme,
name = "Surface Dim",
onCopy = onCopy,
modifier = Modifier.weight(1f)
)
MaterialYouPaletteItem(
color = colorScheme.surfaceBright,
colorScheme = colorScheme,
name = "Surface Bright",
onCopy = onCopy,
modifier = Modifier.weight(1f)
)
}

Row(
modifier = Modifier.height(IntrinsicSize.Max)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package ru.tech.imageresizershrinker.feature.generate_palette.presentation.components

import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -28,16 +29,18 @@ import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import ru.tech.imageresizershrinker.core.ui.utils.helper.toHex
import ru.tech.imageresizershrinker.core.ui.widget.modifier.container
import ru.tech.imageresizershrinker.core.ui.widget.text.AutoSizeText

@Composable
Expand All @@ -49,17 +52,22 @@ fun MaterialYouPaletteItem(
modifier: Modifier = Modifier
) {
val containerColor by animateColorAsState(color)
val contentColor = colorScheme.contentColorFor(containerColor)

Surface(
modifier = modifier,
color = containerColor,
contentColor = colorScheme.contentColorFor(containerColor),
onClick = {
onCopy(containerColor)
}
CompositionLocalProvider(
LocalContentColor provides contentColor
) {
Column(
modifier = Modifier.padding(12.dp)
modifier = modifier
.container(
shape = RectangleShape,
color = containerColor,
resultPadding = 0.dp
)
.clickable {
onCopy(containerColor)
}
.padding(12.dp)
) {
AutoSizeText(
text = name,
Expand All @@ -86,6 +94,7 @@ fun MaterialYouPaletteItem(
}
}
}

}

@Stable
Expand All @@ -103,6 +112,7 @@ private fun ColorScheme.contentColorFor(
errorContainer -> onErrorContainer
inverseSurface -> inverseOnSurface
surface -> onSurface
inversePrimary -> onPrimaryContainer
surfaceVariant -> onSurfaceVariant
surfaceBright -> onSurface
surfaceContainer -> onSurface
Expand Down

0 comments on commit 61ffc60

Please sign in to comment.