-
Notifications
You must be signed in to change notification settings - Fork 530
/
IvyTheme.kt
94 lines (83 loc) · 2.58 KB
/
IvyTheme.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.ivy.design.l0_system
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.Colors
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
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.compositionLocalOf
import com.ivy.design.api.IvyDesign
val LocalIvyColors = compositionLocalOf<IvyColors> { error("No IvyColors") }
val LocalIvyTypography = compositionLocalOf<IvyTypography> { error("No IvyTypography") }
val LocalIvyShapes = compositionLocalOf<IvyShapes> { error("No IvyShapes") }
object UI {
val colors: IvyColors
@Composable
@ReadOnlyComposable
get() = LocalIvyColors.current
val typo: IvyTypography
@Composable
@ReadOnlyComposable
get() = LocalIvyTypography.current
val shapes: IvyShapes
@Composable
@ReadOnlyComposable
get() = LocalIvyShapes.current
}
@Composable
fun IvyTheme(
theme: Theme,
design: IvyDesign,
content: @Composable () -> Unit
) {
val colors = design.colors(theme, isSystemInDarkTheme())
val typography = design.typography()
val shapes = design.shapes()
CompositionLocalProvider(
LocalIvyColors provides colors,
LocalIvyTypography provides typography,
LocalIvyShapes provides shapes
) {
MaterialTheme(
colors = adaptColors(colors),
typography = adaptTypography(typography),
shapes = adaptShapes(shapes),
content = content
)
}
}
fun adaptColors(colors: IvyColors): Colors {
return Colors(
primary = colors.primary,
primaryVariant = colors.primary1,
secondary = colors.primary,
secondaryVariant = colors.primary1,
background = colors.pure,
surface = colors.pure,
onSurface = colors.pureInverse,
error = colors.red,
onPrimary = White,
onSecondary = White,
onBackground = colors.pureInverse,
onError = White,
isLight = colors.isLight
)
}
fun adaptTypography(typography: IvyTypography): Typography {
return Typography(
h1 = typography.h1,
h2 = typography.h2,
body1 = typography.b1,
body2 = typography.b2,
caption = typography.c
)
}
fun adaptShapes(shapes: IvyShapes): Shapes {
return Shapes(
large = shapes.r1,
medium = shapes.r2,
small = shapes.r3
)
}