From a207b0774f5e14eab97187bc927e66bc304d7116 Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Thu, 17 Oct 2024 11:36:33 +0200 Subject: [PATCH] refactor: Typography is now an object --- .../swisstransfer/ui/theme/Theme.kt | 6 +- .../infomaniak/swisstransfer/ui/theme/Type.kt | 177 ++++++++---------- 2 files changed, 75 insertions(+), 108 deletions(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt index 0c0bedb8b..a2d042d97 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt @@ -28,7 +28,6 @@ import androidx.compose.runtime.* import androidx.compose.ui.graphics.Color val LocalIsDarkMode = staticCompositionLocalOf { false } -val LocalCustomTypography = staticCompositionLocalOf { Typography } val LocalCustomColorScheme: ProvidableCompositionLocal = staticCompositionLocalOf { CustomColorScheme() } val LocalWindowAdaptiveInfo = staticCompositionLocalOf { error("No WindowAdaptiveInfo provided") } @@ -39,7 +38,6 @@ fun SwissTransferTheme( ) { val customColors = if (isDarkTheme) CustomDarkColorScheme else CustomLightColorScheme CompositionLocalProvider( - LocalCustomTypography provides Typography, LocalTextStyle provides Typography.bodyRegular, LocalCustomColorScheme provides customColors, LocalWindowAdaptiveInfo provides currentWindowAdaptiveInfo(), @@ -54,9 +52,7 @@ fun SwissTransferTheme( } object SwissTransferTheme { - val typography: CustomTypography - @Composable - get() = LocalCustomTypography.current + val typography = Typography val colors: CustomColorScheme @Composable get() = LocalCustomColorScheme.current diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Type.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Type.kt index a64a5b6cc..c73882eda 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Type.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Type.kt @@ -17,123 +17,94 @@ */ package com.infomaniak.swisstransfer.ui.theme -import androidx.compose.runtime.Immutable import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.sp -private val h1 = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.SemiBold, - fontSize = 22.sp, - lineHeight = 28.sp, -) +object Typography { -private val h2 = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.SemiBold, - fontSize = 18.sp, - lineHeight = 24.sp, -) + val h1 = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.SemiBold, + fontSize = 22.sp, + lineHeight = 28.sp, + ) -private val bodyMedium = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Medium, - fontSize = 16.sp, - lineHeight = 20.sp, -) + val h2 = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.SemiBold, + fontSize = 18.sp, + lineHeight = 24.sp, + ) -private val bodyRegular = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Normal, - fontSize = 16.sp, - lineHeight = 20.sp, -) + val bodyMedium = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 16.sp, + lineHeight = 20.sp, + ) -private val bodySmallMedium = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Medium, - fontSize = 14.sp, - lineHeight = 20.sp, -) + val bodyRegular = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 20.sp, + ) -private val bodySmallRegular = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Normal, - fontSize = 14.sp, - lineHeight = 20.sp, -) + val bodySmallMedium = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 14.sp, + lineHeight = 20.sp, + ) -private val labelMedium = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Medium, - fontSize = 12.sp, - lineHeight = 18.sp, -) + val bodySmallRegular = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 14.sp, + lineHeight = 20.sp, + ) -private val labelRegular = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Normal, - fontSize = 12.sp, - lineHeight = 18.sp, -) + val labelMedium = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 12.sp, + lineHeight = 18.sp, + ) -private val specificMedium22 = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Medium, - fontSize = 22.sp, - lineHeight = 28.sp, -) + val labelRegular = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 12.sp, + lineHeight = 18.sp, + ) -private val specificMedium32 = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Medium, - fontSize = 32.sp, - lineHeight = 42.sp, -) + val specificMedium22 = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 22.sp, + lineHeight = 28.sp, + ) -private val specificLight22 = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Light, - fontSize = 22.sp, - lineHeight = 28.sp, -) + val specificMedium32 = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 32.sp, + lineHeight = 42.sp, + ) -private val specificLight18 = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Light, - fontSize = 18.sp, - lineHeight = 24.sp, -) + val specificLight22 = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Light, + fontSize = 22.sp, + lineHeight = 28.sp, + ) -val Typography = CustomTypography( - h1 = h1, - h2 = h2, - bodyMedium = bodyMedium, - bodyRegular = bodyRegular, - bodySmallMedium = bodySmallMedium, - bodySmallRegular = bodySmallRegular, - labelMedium = labelMedium, - labelRegular = labelRegular, - specificMedium32 = specificMedium32, - specificMedium22 = specificMedium22, - specificLight22 = specificLight22, - specificLight18 = specificLight18, -) - -@Immutable -data class CustomTypography( - val h1: TextStyle, - val h2: TextStyle, - val bodyMedium: TextStyle, - val bodyRegular: TextStyle, - val bodySmallMedium: TextStyle, - val bodySmallRegular: TextStyle, - val labelMedium: TextStyle, - val labelRegular: TextStyle, - val specificMedium32: TextStyle, - val specificMedium22: TextStyle, - val specificLight22: TextStyle, - val specificLight18: TextStyle, -) + val specificLight18 = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Light, + fontSize = 18.sp, + lineHeight = 24.sp, + ) +}