Add shape to surface and decouple shape from Material theme
This commit is contained in:
parent
c2a2437b6b
commit
782d35e91a
4 changed files with 50 additions and 11 deletions
|
@ -792,7 +792,7 @@ style:
|
|||
Compose:
|
||||
CompositionLocalAllowlist:
|
||||
active: true
|
||||
allowedCompositionLocals: [LocalColors, LocalElevations, LocalImages, LocalSizes, LocalSpacings]
|
||||
allowedCompositionLocals: [LocalColors, LocalElevations, LocalImages, LocalShapes, LocalSizes, LocalSpacings]
|
||||
ContentEmitterReturningValues:
|
||||
active: true
|
||||
ModifierComposable:
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package app.k9mail.core.ui.compose.designsystem.atom
|
||||
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.requiredHeight
|
||||
import androidx.compose.foundation.layout.requiredWidth
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.RectangleShape
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.k9mail.core.ui.compose.theme.MainTheme
|
||||
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
|
||||
import androidx.compose.material.Surface as MaterialSurface
|
||||
|
@ -13,12 +17,14 @@ import androidx.compose.material.Surface as MaterialSurface
|
|||
@Composable
|
||||
fun Surface(
|
||||
modifier: Modifier = Modifier,
|
||||
shape: Shape = RectangleShape,
|
||||
color: Color = MainTheme.colors.surface,
|
||||
elevation: Dp = MainTheme.elevations.default,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
MaterialSurface(
|
||||
modifier = modifier,
|
||||
shape = shape,
|
||||
content = content,
|
||||
elevation = elevation,
|
||||
color = color,
|
||||
|
@ -30,8 +36,27 @@ fun Surface(
|
|||
internal fun SurfacePreview() {
|
||||
PreviewWithThemes {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
modifier = Modifier
|
||||
.requiredHeight(100.dp)
|
||||
.requiredWidth(100.dp),
|
||||
content = {},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
internal fun SurfaceWithShapePreview() {
|
||||
PreviewWithThemes {
|
||||
Background {
|
||||
Surface(
|
||||
modifier = Modifier
|
||||
.requiredHeight(MainTheme.sizes.larger)
|
||||
.requiredWidth(MainTheme.sizes.larger),
|
||||
shape = MainTheme.shapes.small,
|
||||
color = MainTheme.colors.primary,
|
||||
content = {},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package app.k9mail.core.ui.compose.theme
|
|||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Shapes
|
||||
import androidx.compose.material.Typography
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
|
@ -34,17 +33,20 @@ fun MainTheme(
|
|||
|
||||
SetSystemBarsColor(color = colors.toolbar)
|
||||
|
||||
val shapes = MainTheme.shapes
|
||||
|
||||
CompositionLocalProvider(
|
||||
LocalColors provides colors,
|
||||
LocalElevations provides Elevations(),
|
||||
LocalImages provides images,
|
||||
LocalSizes provides Sizes(),
|
||||
LocalSpacings provides Spacings(),
|
||||
LocalShapes provides shapes,
|
||||
) {
|
||||
MaterialTheme(
|
||||
colors = colors.toMaterialColors(),
|
||||
typography = typography,
|
||||
shapes = shapes,
|
||||
shapes = shapes.toMaterialShapes(),
|
||||
content = content,
|
||||
)
|
||||
}
|
||||
|
@ -64,7 +66,7 @@ object MainTheme {
|
|||
val shapes: Shapes
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
get() = MaterialTheme.shapes
|
||||
get() = LocalShapes.current
|
||||
|
||||
val spacings: Spacings
|
||||
@Composable
|
||||
|
|
|
@ -1,11 +1,23 @@
|
|||
package app.k9mail.core.ui.compose.theme
|
||||
|
||||
import androidx.compose.foundation.shape.CornerBasedShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Shapes
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.material.Shapes as MaterialShapes
|
||||
|
||||
val shapes = Shapes(
|
||||
small = RoundedCornerShape(8.dp),
|
||||
medium = RoundedCornerShape(4.dp),
|
||||
large = RoundedCornerShape(0.dp),
|
||||
@Immutable
|
||||
data class Shapes(
|
||||
val small: CornerBasedShape = RoundedCornerShape(8.dp),
|
||||
val medium: CornerBasedShape = RoundedCornerShape(4.dp),
|
||||
val large: CornerBasedShape = RoundedCornerShape(0.dp),
|
||||
)
|
||||
|
||||
internal fun Shapes.toMaterialShapes() = MaterialShapes(
|
||||
small = small,
|
||||
medium = medium,
|
||||
large = large,
|
||||
)
|
||||
|
||||
internal val LocalShapes = staticCompositionLocalOf { Shapes() }
|
||||
|
|
Loading…
Reference in a new issue