Skip to content

Commit

Permalink
Merge branch 'main' into chore-updated-icons
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMarquis authored Sep 5, 2024
2 parents ec52be0 + d23a887 commit 56942f8
Show file tree
Hide file tree
Showing 21 changed files with 149 additions and 74 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Catalog App

### CI
- Icons screenshot are not bound to the theme colors anymore to reduce invalidation not related to the icons themselves.

## 0.11.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED
import org.gradle.api.tasks.testing.logging.TestLogEvent.STARTED
import org.gradle.configurationcache.extensions.capitalized
import org.gradle.kotlin.dsl.withType
import org.gradle.language.base.plugins.LifecycleBasePlugin

Expand Down
14 changes: 7 additions & 7 deletions catalog/src/main/kotlin/com/adevinta/spark/catalog/CatalogApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
Expand All @@ -69,6 +67,7 @@ import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import com.adevinta.spark.SparkFeatureFlag
import com.adevinta.spark.SparkTheme
import com.adevinta.spark.catalog.backdrop.BackdropScaffold
import com.adevinta.spark.catalog.backdrop.BackdropScaffoldDefaults
Expand Down Expand Up @@ -99,10 +98,7 @@ import com.airbnb.android.showkase.models.ShowkaseBrowserComponent
import com.google.accompanist.testharness.TestHarness
import kotlinx.coroutines.launch

@OptIn(
ExperimentalFoundationApi::class,
ExperimentalComposeUiApi::class,
)
@OptIn(ExperimentalFoundationApi::class)
@Composable
internal fun ComponentActivity.CatalogApp(
theme: Theme,
Expand Down Expand Up @@ -130,7 +126,11 @@ internal fun ComponentActivity.CatalogApp(
colors = colors,
shapes = shapes,
typography = typography,
useLegacyStyle = false,
sparkFeatureFlag = SparkFeatureFlag(
useLegacyStyle = theme.useLegacyTheme,
useSparkTokensHighlighter = theme.highlightSparkTokens,
useSparkComponentsHighlighter = theme.highlightSparkComponents,
),
) {
CompositionLocalProvider(LocalRippleTheme provides SparkRippleTheme) {
val layoutDirection = when (theme.textDirection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ internal data class ThemeProperties(
val brandMode: BrandMode,
val fontScaleMode: FontScaleMode,
val textDirection: TextDirection,
val highlightSparkComponents: Boolean,
val highlightSparkTokens: Boolean,
val useLegacyTheme: Boolean,
) {
companion object {
val DEFAULT = ThemeProperties(
Expand All @@ -48,7 +51,9 @@ internal data class ThemeProperties(
colorMode = ColorMode.Baseline,
textDirection = TextDirection.System,
fontScaleMode = FontScaleMode.System,

highlightSparkComponents = false,
highlightSparkTokens = false,
useLegacyTheme = false,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ private fun ThemeProperties.toTheme(): Theme = Theme(
brandMode = brandMode,
fontScaleMode = fontScaleMode,
textDirection = textDirection,
highlightSparkComponents = highlightSparkComponents,
highlightSparkTokens = highlightSparkTokens,
useLegacyTheme = useLegacyTheme,
)

private fun Theme.toDataStoreThemeProperties(): ThemeProperties = ThemeProperties(
Expand All @@ -88,4 +91,7 @@ private fun Theme.toDataStoreThemeProperties(): ThemeProperties = ThemePropertie
brandMode = brandMode,
fontScaleMode = fontScaleMode,
textDirection = textDirection,
highlightSparkComponents = highlightSparkComponents,
highlightSparkTokens = highlightSparkTokens,
useLegacyTheme = useLegacyTheme,
)
12 changes: 12 additions & 0 deletions catalog/src/main/kotlin/com/adevinta/spark/catalog/themes/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public data class Theme(
val fontScale: Float = 1.0f,
val fontScaleMode: FontScaleMode = FontScaleMode.System,
val textDirection: TextDirection = TextDirection.System,
val highlightSparkComponents: Boolean = false,
val highlightSparkTokens: Boolean = false,
val useLegacyTheme: Boolean = false,
)

/**
Expand Down Expand Up @@ -109,6 +112,9 @@ public val ThemeSaver: Saver<Theme, Map<String, Int>> = Saver(
UserModeKey to theme.userMode.ordinal,
FontScaleKey to theme.fontScale.toInt(),
TextDirectionKey to theme.textDirection.ordinal,
HighlightSparkComponentsKey to if (theme.highlightSparkComponents) 1 else 0,
HighlightSparkTokensKey to if (theme.highlightSparkTokens) 1 else 0,
UseLegacyThemeKey to if (theme.useLegacyTheme) 1 else 0,
)
},
restore = { map ->
Expand All @@ -119,6 +125,9 @@ public val ThemeSaver: Saver<Theme, Map<String, Int>> = Saver(
userMode = UserMode.entries[map.getValue(UserModeKey)],
fontScale = map.getValue(FontScaleKey).toFloat(),
textDirection = TextDirection.entries[map.getValue(TextDirectionKey)],
highlightSparkComponents = map.getValue(HighlightSparkComponentsKey) == 1,
highlightSparkTokens = map.getValue(HighlightSparkTokensKey) == 1,
useLegacyTheme = map.getValue(UseLegacyThemeKey) == 1,
)
},
)
Expand All @@ -132,3 +141,6 @@ private const val BrandModeKey = "brandMode"
private const val UserModeKey = "userMode"
private const val FontScaleKey = "fontScale"
private const val TextDirectionKey = "textDirection"
private const val HighlightSparkComponentsKey = "highlightSparkComponents"
private const val HighlightSparkTokensKey = "highlightSparkTokens"
private const val UseLegacyThemeKey = "useLegacyTheme"
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,48 @@ public fun ThemePicker(
)
}
}
item {
SwitchLabelled(
modifier = Modifier.padding(horizontal = ThemePickerPadding),
checked = theme.useLegacyTheme,
onCheckedChange = { checked ->
onThemeChange(theme.copy(useLegacyTheme = checked))
},
) {
Text(
text = "Use LegacyTheme",
modifier = Modifier.fillMaxWidth(),
)
}
}
item {
SwitchLabelled(
modifier = Modifier.padding(horizontal = ThemePickerPadding),
checked = theme.highlightSparkComponents,
onCheckedChange = { checked ->
onThemeChange(theme.copy(highlightSparkComponents = checked))
},
) {
Text(
text = "Highlight Spark Components",
modifier = Modifier.fillMaxWidth(),
)
}
}
item {
SwitchLabelled(
modifier = Modifier.padding(horizontal = ThemePickerPadding),
checked = theme.highlightSparkTokens,
onCheckedChange = { checked ->
onThemeChange(theme.copy(highlightSparkTokens = checked))
},
) {
Text(
text = "Highlight Spark Tokens",
modifier = Modifier.fillMaxWidth(),
)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ internal fun PreviewTheme(
internal fun SparkTenantTheme(
// We don't want to automatically support dark theme in the app but still want it in the previews
useDarkColors: Boolean = isSystemInDarkTheme(),
useSparkTokensHighlighter: Boolean = false,
useSparkComponentsHighlighter: Boolean = false,
useLegacyStyle: Boolean = false,
content: @Composable () -> Unit,
) {
val colors = if (useDarkColors) {
Expand All @@ -81,9 +78,6 @@ internal fun SparkTenantTheme(
colors = colors,
shapes = sparkShapes(),
typography = sparkTypography(),
useSparkTokensHighlighter = useSparkTokensHighlighter,
useSparkComponentsHighlighter = useSparkComponentsHighlighter,
useLegacyStyle = useLegacyStyle,
content = content,
)
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 4 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ internal fun Paparazzi.sparkSnapshot(
// Behave like in Android Studio Preview renderer
CompositionLocalProvider(LocalInspectionMode provides true) {
SparkTheme(
useLegacyStyle = false,
colors = if (isDark) darkSparkColors() else lightSparkColors(),
) {
// The first box acts as a shield from ComposeView which forces the first layout node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
*/
package com.adevinta.spark.icons

import androidx.compose.ui.graphics.Color
import com.adevinta.spark.components.icons.Icon
import com.adevinta.spark.components.icons.IconSize
import com.adevinta.spark.paparazziRule
import com.adevinta.spark.sparkSnapshot
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import com.google.testing.junit.testparameterinjector.TestParameterValuesProvider
Expand All @@ -48,11 +50,12 @@ internal class IconsScreenshot {
@Suppress("JUnitMalformedDeclaration")
fun render(
@TestParameter(valuesProvider = SparkIconProvider::class) icon: SparkIcon,
) = paparazzi.snapshot {
) = paparazzi.sparkSnapshot(drawBackground = false) {
Icon(
sparkIcon = icon,
contentDescription = icon.toString(),
size = IconSize.ExtraLarge,
tint = Color.Black,
)
}
}
2 changes: 1 addition & 1 deletion spark/lint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<lint>
<issue id="ComposeCompositionLocalGetter" severity="warning">
<option name="allowed-composition-locals"
value="LocalSparkColors,LocalSparkShapes,LocalSparkTypography,LocalHighlightToken,LocalHighlightComponents,LocalLegacyStyle,LocalElevationOverlay,LocalWindowSizeClass" />
value="LocalSparkColors,LocalSparkShapes,LocalSparkTypography,LocalSparkFeatureFlag,LocalElevationOverlay,LocalWindowSizeClass" />
</issue>
<issue id="AutoboxingStateCreation" severity="warning"/>
<!--
Expand Down
Loading

0 comments on commit 56942f8

Please sign in to comment.