Skip to content

Commit

Permalink
[FEAT/#6] theme ์„ค์ •
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyobeen-Park committed Jul 5, 2024
1 parent 99c6461 commit c33d2c8
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions core/src/main/java/com/terning/core/designsystem/theme/Theme.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.terning.core.designsystem.theme

import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf

private val DarkColorScheme = darkColorScheme(
primary = Purple80,
Expand All @@ -32,26 +31,40 @@ private val LightColorScheme = lightColorScheme(
*/
)

private val LocalTerningTypography = staticCompositionLocalOf<TerningTypography> {
error("No TerningTypography provided")
}

object TerningTheme {
val typography: TerningTypography
@Composable
get() = LocalTerningTypography.current
}

@Composable
fun ProvideTerningTypography(typography: TerningTypography, content: @Composable () -> Unit) {
val provideTypography = remember { typography.copy() }
provideTypography.update(typography)
CompositionLocalProvider(
LocalTerningTypography provides provideTypography,
content = content
)
}

@Composable
fun TerningAndroidTheme(
fun TerningTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
content: @Composable () -> Unit
) {
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}

darkTheme -> DarkColorScheme
else -> LightColorScheme
}
val colorScheme = LightColorScheme
val typography = TerningTypography()

MaterialTheme(
colorScheme = colorScheme,
typography = Typography,
content = content
)
ProvideTerningTypography(typography = typography) {
MaterialTheme(
colorScheme = colorScheme,
content = content,
)
}
}

0 comments on commit c33d2c8

Please sign in to comment.