Skip to content

Commit

Permalink
[Jetsnack] Remove color states from the JetsnackColors (#1331)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlykotom authored Apr 10, 2024
2 parents 04649ed + c544137 commit c1c20e5
Showing 1 changed file with 33 additions and 162 deletions.
195 changes: 33 additions & 162 deletions Jetsnack/app/src/main/java/com/example/jetsnack/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ import androidx.compose.material.Colors
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color

Expand Down Expand Up @@ -107,169 +103,44 @@ object JetsnackTheme {
/**
* Jetsnack custom Color Palette
*/
@Stable
class JetsnackColors(
gradient6_1: List<Color>,
gradient6_2: List<Color>,
gradient3_1: List<Color>,
gradient3_2: List<Color>,
gradient2_1: List<Color>,
gradient2_2: List<Color>,
gradient2_3: List<Color>,
brand: Color,
brandSecondary: Color,
uiBackground: Color,
uiBorder: Color,
uiFloated: Color,
interactivePrimary: List<Color> = gradient2_1,
interactiveSecondary: List<Color> = gradient2_2,
interactiveMask: List<Color> = gradient6_1,
textPrimary: Color = brand,
textSecondary: Color,
textHelp: Color,
textInteractive: Color,
textLink: Color,
tornado1: List<Color>,
iconPrimary: Color = brand,
iconSecondary: Color,
iconInteractive: Color,
iconInteractiveInactive: Color,
error: Color,
notificationBadge: Color = error,
isDark: Boolean
) {
var gradient6_1 by mutableStateOf(gradient6_1)
private set
var gradient6_2 by mutableStateOf(gradient6_2)
private set
var gradient3_1 by mutableStateOf(gradient3_1)
private set
var gradient3_2 by mutableStateOf(gradient3_2)
private set
var gradient2_1 by mutableStateOf(gradient2_1)
private set
var gradient2_2 by mutableStateOf(gradient2_2)
private set
var gradient2_3 by mutableStateOf(gradient2_3)
private set
var brand by mutableStateOf(brand)
private set
var brandSecondary by mutableStateOf(brandSecondary)
private set
var uiBackground by mutableStateOf(uiBackground)
private set
var uiBorder by mutableStateOf(uiBorder)
private set
var uiFloated by mutableStateOf(uiFloated)
private set
var interactivePrimary by mutableStateOf(interactivePrimary)
private set
var interactiveSecondary by mutableStateOf(interactiveSecondary)
private set
var interactiveMask by mutableStateOf(interactiveMask)
private set
var textPrimary by mutableStateOf(textPrimary)
private set
var textSecondary by mutableStateOf(textSecondary)
private set
var textHelp by mutableStateOf(textHelp)
private set
var textInteractive by mutableStateOf(textInteractive)
private set
var tornado1 by mutableStateOf(tornado1)
private set
var textLink by mutableStateOf(textLink)
private set
var iconPrimary by mutableStateOf(iconPrimary)
private set
var iconSecondary by mutableStateOf(iconSecondary)
private set
var iconInteractive by mutableStateOf(iconInteractive)
private set
var iconInteractiveInactive by mutableStateOf(iconInteractiveInactive)
private set
var error by mutableStateOf(error)
private set
var notificationBadge by mutableStateOf(notificationBadge)
private set
var isDark by mutableStateOf(isDark)
private set

fun update(other: JetsnackColors) {
gradient6_1 = other.gradient6_1
gradient6_2 = other.gradient6_2
gradient3_1 = other.gradient3_1
gradient3_2 = other.gradient3_2
gradient2_1 = other.gradient2_1
gradient2_2 = other.gradient2_2
gradient2_3 = other.gradient2_3
brand = other.brand
brandSecondary = other.brandSecondary
uiBackground = other.uiBackground
uiBorder = other.uiBorder
uiFloated = other.uiFloated
interactivePrimary = other.interactivePrimary
interactiveSecondary = other.interactiveSecondary
interactiveMask = other.interactiveMask
textPrimary = other.textPrimary
textSecondary = other.textSecondary
textHelp = other.textHelp
textInteractive = other.textInteractive
textLink = other.textLink
tornado1 = other.tornado1
iconPrimary = other.iconPrimary
iconSecondary = other.iconSecondary
iconInteractive = other.iconInteractive
iconInteractiveInactive = other.iconInteractiveInactive
error = other.error
notificationBadge = other.notificationBadge
isDark = other.isDark
}

fun copy(): JetsnackColors = JetsnackColors(
gradient6_1 = gradient6_1,
gradient6_2 = gradient6_2,
gradient3_1 = gradient3_1,
gradient3_2 = gradient3_2,
gradient2_1 = gradient2_1,
gradient2_2 = gradient2_2,
gradient2_3 = gradient2_3,
brand = brand,
brandSecondary = brandSecondary,
uiBackground = uiBackground,
uiBorder = uiBorder,
uiFloated = uiFloated,
interactivePrimary = interactivePrimary,
interactiveSecondary = interactiveSecondary,
interactiveMask = interactiveMask,
textPrimary = textPrimary,
textSecondary = textSecondary,
textHelp = textHelp,
textInteractive = textInteractive,
textLink = textLink,
tornado1 = tornado1,
iconPrimary = iconPrimary,
iconSecondary = iconSecondary,
iconInteractive = iconInteractive,
iconInteractiveInactive = iconInteractiveInactive,
error = error,
notificationBadge = notificationBadge,
isDark = isDark,
)
}
@Immutable
data class JetsnackColors(
val gradient6_1: List<Color>,
val gradient6_2: List<Color>,
val gradient3_1: List<Color>,
val gradient3_2: List<Color>,
val gradient2_1: List<Color>,
val gradient2_2: List<Color>,
val gradient2_3: List<Color>,
val brand: Color,
val brandSecondary: Color,
val uiBackground: Color,
val uiBorder: Color,
val uiFloated: Color,
val interactivePrimary: List<Color> = gradient2_1,
val interactiveSecondary: List<Color> = gradient2_2,
val interactiveMask: List<Color> = gradient6_1,
val textPrimary: Color = brand,
val textSecondary: Color,
val textHelp: Color,
val textInteractive: Color,
val textLink: Color,
val tornado1: List<Color>,
val iconPrimary: Color = brand,
val iconSecondary: Color,
val iconInteractive: Color,
val iconInteractiveInactive: Color,
val error: Color,
val notificationBadge: Color = error,
val isDark: Boolean
)

@Composable
fun ProvideJetsnackColors(
colors: JetsnackColors,
content: @Composable () -> Unit
) {
val colorPalette = remember {
// Explicitly creating a new object here so we don't mutate the initial [colors]
// provided, and overwrite the values set in it.
colors.copy()
}
colorPalette.update(colors)
CompositionLocalProvider(LocalJetsnackColors provides colorPalette, content = content)
CompositionLocalProvider(LocalJetsnackColors provides colors, content = content)
}

private val LocalJetsnackColors = staticCompositionLocalOf<JetsnackColors> {
Expand Down

0 comments on commit c1c20e5

Please sign in to comment.