Skip to content

Commit

Permalink
refactor: Typography is now an object
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Oct 17, 2024
1 parent c46e47c commit a07d12a
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<CustomColorScheme> = staticCompositionLocalOf { CustomColorScheme() }
val LocalWindowAdaptiveInfo = staticCompositionLocalOf<WindowAdaptiveInfo> { error("No WindowAdaptiveInfo provided") }

Expand All @@ -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(),
Expand All @@ -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
Expand Down
177 changes: 74 additions & 103 deletions app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Type.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}

0 comments on commit a07d12a

Please sign in to comment.