Skip to content

Commit

Permalink
Add new FlipperPallet (#872)
Browse files Browse the repository at this point in the history
**Background**

We are now moving to a new design system. The first step is to migrate
the design system

**Changes**

- Made a palette generator from a JSON file with Figma
(https://github.com/LionZXY/FlipperPalletGenerator)
- Add LocalPalletV2 provider

**Test plan**

Try assemble and launch app
  • Loading branch information
LionZXY authored Jun 6, 2024
1 parent 3287a46 commit 3f99a19
Show file tree
Hide file tree
Showing 9 changed files with 4,162 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# 1.6.10 - In Progress

- [KMP] Migration core:activityholder, core:di, core:progpress, core:ui:decompose
- [Feature] Add new FlipperPallet

# 1.6.9

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ import com.flipperdevices.core.ui.theme.composable.FlipperTypography
import com.flipperdevices.core.ui.theme.composable.getThemedFlipperPallet
import com.flipperdevices.core.ui.theme.composable.getTypography
import com.flipperdevices.core.ui.theme.composable.isLight
import com.flipperdevices.core.ui.theme.composable.pallet.generated.FlipperPalletV2
import com.flipperdevices.core.ui.theme.composable.pallet.getThemedFlipperPalletV2
import com.flipperdevices.core.ui.theme.composable.toMaterialColors
import com.flipperdevices.core.ui.theme.composable.toTextSelectionColors
import com.flipperdevices.core.ui.theme.viewmodel.ThemeViewModel

val LocalPallet = compositionLocalOf<FlipperPallet> { error("No local pallet") }
val LocalPalletV2 = compositionLocalOf<FlipperPalletV2> { error("No local pallet") }
val LocalTypography = compositionLocalOf<FlipperTypography> { error("No local typography") }

@Composable
Expand All @@ -38,20 +41,22 @@ fun FlipperTheme(
val theme by themeViewModel.getAppTheme().collectAsState()
val isLight = isLight(
systemIsDark = isSystemInDarkTheme(),
themeViewModel = themeViewModel
theme = theme
)
val pallet = getThemedFlipperPallet(theme, isLight)
val pallet = getThemedFlipperPallet(isLight)
FlipperTheme(
content = content,
pallet = pallet,
palletV2 = getThemedFlipperPalletV2(isLight),
isLight = isLight
)
}

@Composable
private fun FlipperTheme(
pallet: FlipperPallet,
isLight: Boolean = !isSystemInDarkTheme(),
palletV2: FlipperPalletV2,
isLight: Boolean,
content: @Composable () -> Unit
) {
val colors = pallet.toMaterialColors(isLight)
Expand All @@ -63,6 +68,7 @@ private fun FlipperTheme(
) {
CompositionLocalProvider(
LocalPallet provides pallet,
LocalPalletV2 provides palletV2,
LocalTypography provides getTypography(),
LocalContentColor provides colors.contentColorFor(backgroundColor = pallet.background),
LocalTextSelectionColors provides pallet.toTextSelectionColors(),
Expand All @@ -79,7 +85,9 @@ fun FlipperThemeInternal(
) {
FlipperTheme(
pallet = getThemedFlipperPallet(!isSystemInDarkTheme()),
content = content
palletV2 = getThemedFlipperPalletV2(!isSystemInDarkTheme()),
content = content,
isLight = !isSystemInDarkTheme()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package com.flipperdevices.core.ui.theme.composable

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.graphics.Color
import com.flipperdevices.core.preference.pb.SelectedTheme
import com.flipperdevices.core.ui.theme.viewmodel.ThemeViewModel

/**
* Please, use LocalPallet instead
Expand All @@ -15,29 +13,18 @@ import com.flipperdevices.core.ui.theme.viewmodel.ThemeViewModel
*/
@Composable
fun getThemedFlipperPallet(isLight: Boolean): FlipperPallet {
return if (isLight) lightPallet else darkPallet
}

@Composable
fun getThemedFlipperPallet(
theme: SelectedTheme,
isLight: Boolean = !isSystemInDarkTheme()
): FlipperPallet {
return when (theme) {
SelectedTheme.LIGHT -> lightPallet
SelectedTheme.DARK -> darkPallet
SelectedTheme.UNRECOGNIZED,
SelectedTheme.SYSTEM -> getThemedFlipperPallet(isLight)
return if (isLight) {
lightPallet
} else {
darkPallet
}.toAnimatePallet()
}

@Composable
internal fun isLight(
themeViewModel: ThemeViewModel,
theme: SelectedTheme,
systemIsDark: Boolean = isSystemInDarkTheme()
): Boolean {
val theme by themeViewModel.getAppTheme().collectAsState()

return when (theme) {
SelectedTheme.LIGHT -> true
SelectedTheme.DARK -> false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.flipperdevices.core.ui.theme.composable.pallet

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import com.flipperdevices.core.ui.theme.composable.pallet.generated.FlipperPalletV2
import com.flipperdevices.core.ui.theme.composable.pallet.generated.getDarkPallet
import com.flipperdevices.core.ui.theme.composable.pallet.generated.getLightPallet
import com.flipperdevices.core.ui.theme.composable.pallet.generated.toAnimatePallet

/**
* Please, use instead LocalPalletV2
*
* @return the necessary Pallet depending on the theme
*/
@Composable
fun getThemedFlipperPalletV2(isLight: Boolean): FlipperPalletV2 {
return remember(isLight) {
if (isLight) {
getLightPallet()
} else {
getDarkPallet()
}
}.toAnimatePallet()
}
Loading

0 comments on commit 3f99a19

Please sign in to comment.