diff --git a/app/src/main/kotlin/co/touchlab/kampkit/android/MainActivity.kt b/app/src/main/kotlin/co/touchlab/kampkit/android/MainActivity.kt index 08ae0954..b9f8402d 100644 --- a/app/src/main/kotlin/co/touchlab/kampkit/android/MainActivity.kt +++ b/app/src/main/kotlin/co/touchlab/kampkit/android/MainActivity.kt @@ -3,8 +3,9 @@ package co.touchlab.kampkit.android import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent +import androidx.compose.foundation.isSystemInDarkTheme import co.touchlab.kampkit.android.ui.MainScreen -import co.touchlab.kampkit.android.ui.theme.KaMPKitTheme +import co.touchlab.kampkit.ui.theme.KaMPKitTheme import co.touchlab.kampkit.injectLogger import co.touchlab.kampkit.models.BreedViewModel import co.touchlab.kermit.Logger @@ -19,7 +20,7 @@ class MainActivity : ComponentActivity(), KoinComponent { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { - KaMPKitTheme { + KaMPKitTheme(isSystemInDarkTheme(), true) { MainScreen(viewModel, log) } } diff --git a/app/src/main/kotlin/co/touchlab/kampkit/android/ui/theme/Theme.kt b/app/src/main/kotlin/co/touchlab/kampkit/android/ui/theme/Theme.kt deleted file mode 100644 index d17201c4..00000000 --- a/app/src/main/kotlin/co/touchlab/kampkit/android/ui/theme/Theme.kt +++ /dev/null @@ -1,47 +0,0 @@ -package co.touchlab.kampkit.android.ui.theme - -import androidx.compose.foundation.isSystemInDarkTheme -import androidx.compose.material.MaterialTheme -import androidx.compose.material.darkColors -import androidx.compose.material.lightColors -import androidx.compose.runtime.Composable - -private val DarkColorPalette = darkColors( - primary = Purple200, - primaryVariant = Purple700, - secondary = Teal200 -) - -private val LightColorPalette = lightColors( - primary = Purple500, - primaryVariant = Purple700, - secondary = Teal200 - - // Other default colors to override - // - // background = Color.White, - // surface = Color.White, - // onPrimary = Color.White, - // onSecondary = Color.Black, - // onBackground = Color.Black, - // onSurface = Color.Black, -) - -@Composable -fun KaMPKitTheme( - darkTheme: Boolean = isSystemInDarkTheme(), - content: @Composable () -> Unit -) { - val colors = if (darkTheme) { - DarkColorPalette - } else { - LightColorPalette - } - - MaterialTheme( - colors = colors, - typography = Typography, - shapes = Shapes, - content = content - ) -} diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 9aff8490..d6ee7bf7 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -48,6 +48,8 @@ kotlin { val commonMain by getting { dependencies { implementation(compose.runtime) + implementation(compose.foundation) + implementation(compose.material3) implementation(libs.koin.core) implementation(libs.coroutines.core) implementation(libs.sqlDelight.coroutinesExt) diff --git a/shared/src/androidMain/kotlin/co/touchlab/kampkit/ui/theme/KaMPKitTheme.kt b/shared/src/androidMain/kotlin/co/touchlab/kampkit/ui/theme/KaMPKitTheme.kt new file mode 100644 index 00000000..9fab32ae --- /dev/null +++ b/shared/src/androidMain/kotlin/co/touchlab/kampkit/ui/theme/KaMPKitTheme.kt @@ -0,0 +1,52 @@ +package co.touchlab.kampkit.ui.theme + +import android.app.Activity +import android.os.Build +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalView +import androidx.core.view.WindowCompat + +@Composable +actual fun KaMPKitTheme( + darkTheme: Boolean, + dynamicColor: Boolean, + content: @Composable () -> Unit +) { + val colorScheme = when { + // Dynamic color is only supported on Android 12+ + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + darkTheme -> DarkColorPalette + else -> LightColorPalette + } + + // If not in Android Studio's preview then update also the system bars + val view = LocalView.current + if (!view.isInEditMode) { + SideEffect { + (view.context as Activity).window.apply { + statusBarColor = colorScheme.primary.toArgb() + WindowCompat + .getInsetsController(this, view).apply { + isAppearanceLightStatusBars = darkTheme + isAppearanceLightNavigationBars = darkTheme + } + } + } + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + shapes = Shapes, + content = content + ) +} diff --git a/app/src/main/kotlin/co/touchlab/kampkit/android/ui/theme/Color.kt b/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/Color.kt similarity index 79% rename from app/src/main/kotlin/co/touchlab/kampkit/android/ui/theme/Color.kt rename to shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/Color.kt index 287f01c9..11f754dd 100644 --- a/app/src/main/kotlin/co/touchlab/kampkit/android/ui/theme/Color.kt +++ b/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/Color.kt @@ -1,4 +1,4 @@ -package co.touchlab.kampkit.android.ui.theme +package co.touchlab.kampkit.ui.theme import androidx.compose.ui.graphics.Color diff --git a/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/KaMPKitTheme.kt b/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/KaMPKitTheme.kt new file mode 100644 index 00000000..d5b06f60 --- /dev/null +++ b/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/KaMPKitTheme.kt @@ -0,0 +1,10 @@ +package co.touchlab.kampkit.ui.theme + +import androidx.compose.runtime.Composable + +@Composable +expect fun KaMPKitTheme( + darkTheme: Boolean, + dynamicColor: Boolean, + content: @Composable () -> Unit +) diff --git a/app/src/main/kotlin/co/touchlab/kampkit/android/ui/theme/Shapes.kt b/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/Shapes.kt similarity index 73% rename from app/src/main/kotlin/co/touchlab/kampkit/android/ui/theme/Shapes.kt rename to shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/Shapes.kt index 0260e337..f464b2b5 100644 --- a/app/src/main/kotlin/co/touchlab/kampkit/android/ui/theme/Shapes.kt +++ b/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/Shapes.kt @@ -1,7 +1,7 @@ -package co.touchlab.kampkit.android.ui.theme +package co.touchlab.kampkit.ui.theme import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.Shapes +import androidx.compose.material3.Shapes import androidx.compose.ui.unit.dp val Shapes = Shapes( diff --git a/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/Theme.kt b/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/Theme.kt new file mode 100644 index 00000000..9f76f7a4 --- /dev/null +++ b/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/Theme.kt @@ -0,0 +1,25 @@ +package co.touchlab.kampkit.ui.theme + +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.lightColorScheme + +val DarkColorPalette = darkColorScheme( + primary = Purple200, + inversePrimary = Purple700, + secondary = Teal200 +) + +val LightColorPalette = lightColorScheme( + primary = Purple500, + inversePrimary = Purple700, + secondary = Teal200 + + // Other default colors to override + // + // background = Color.White, + // surface = Color.White, + // onPrimary = Color.White, + // onSecondary = Color.Black, + // onBackground = Color.Black, + // onSurface = Color.Black, +) diff --git a/app/src/main/kotlin/co/touchlab/kampkit/android/ui/theme/Typography.kt b/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/Typography.kt similarity index 86% rename from app/src/main/kotlin/co/touchlab/kampkit/android/ui/theme/Typography.kt rename to shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/Typography.kt index 2c6faca5..92c7665f 100644 --- a/app/src/main/kotlin/co/touchlab/kampkit/android/ui/theme/Typography.kt +++ b/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/Typography.kt @@ -1,6 +1,6 @@ -package co.touchlab.kampkit.android.ui.theme +package co.touchlab.kampkit.ui.theme -import androidx.compose.material.Typography +import androidx.compose.material3.Typography import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight @@ -8,7 +8,7 @@ import androidx.compose.ui.unit.sp // Set of Material typography styles to start with val Typography = Typography( - body1 = TextStyle( + bodyLarge = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Normal, fontSize = 16.sp diff --git a/shared/src/iosMain/kotlin/co/touchlab/kampkit/ui.theme/KaMPKitTheme.kt b/shared/src/iosMain/kotlin/co/touchlab/kampkit/ui.theme/KaMPKitTheme.kt new file mode 100644 index 00000000..253d2ea2 --- /dev/null +++ b/shared/src/iosMain/kotlin/co/touchlab/kampkit/ui.theme/KaMPKitTheme.kt @@ -0,0 +1,18 @@ +package co.touchlab.kampkit.ui.theme + +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable + +@Composable +actual fun KaMPKitTheme( + darkTheme: Boolean, + dynamicColor: Boolean, + content: @Composable () -> Unit +) { + MaterialTheme( + colorScheme = if (darkTheme) DarkColorPalette else LightColorPalette, + typography = Typography, + shapes = Shapes, + content = content + ) +}