diff --git a/compose-app/src/androidMain/kotlin/dev/androidbroadcast/news/compose/NewsApp.android.kt b/compose-app/src/androidMain/kotlin/dev/androidbroadcast/news/compose/NewsApp.android.kt new file mode 100644 index 0000000..a7b03e6 --- /dev/null +++ b/compose-app/src/androidMain/kotlin/dev/androidbroadcast/news/compose/NewsApp.android.kt @@ -0,0 +1,26 @@ +package dev.androidbroadcast.news.compose + +import android.app.Activity +import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalView +import androidx.core.view.WindowCompat +import dev.androidbroadcast.news.NewsTheme + +@Composable +internal actual fun NewsPlatformTheme( + darkTheme: Boolean, + content: @Composable () -> Unit, +) { + val view = LocalView.current + if (!view.isInEditMode) { + val colorScheme = NewsTheme.colorScheme + SideEffect { + val window = (view.context as Activity).window + window.statusBarColor = colorScheme.primary.toArgb() + WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme + } + } + content() +} diff --git a/compose-app/src/commonMain/kotlin/dev/androidbroadcast/news/compose/NewsApp.kt b/compose-app/src/commonMain/kotlin/dev/androidbroadcast/news/compose/NewsApp.kt index 1d5a2c5..959d472 100644 --- a/compose-app/src/commonMain/kotlin/dev/androidbroadcast/news/compose/NewsApp.kt +++ b/compose-app/src/commonMain/kotlin/dev/androidbroadcast/news/compose/NewsApp.kt @@ -1,5 +1,6 @@ package dev.androidbroadcast.news.compose +import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface @@ -9,16 +10,28 @@ import dev.androidbroadcast.news.NewsTheme import dev.androidbroadcast.news.main.NewsMainScreen import org.koin.compose.KoinContext +/** + * Setup theme for platform + */ +@Composable +internal expect fun NewsPlatformTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + content: @Composable () -> Unit, +) + @Composable public fun NewsApp() { - NewsTheme { - // A surface container using the 'background' color from the theme - Surface( - modifier = Modifier.fillMaxSize(), - color = MaterialTheme.colorScheme.background - ) { - KoinContext { - NewsMainScreen() + val darkTheme = isSystemInDarkTheme() + NewsTheme(darkTheme) { + NewsPlatformTheme(darkTheme) { + // A surface container using the 'background' color from the theme + Surface( + modifier = Modifier.fillMaxSize(), + color = MaterialTheme.colorScheme.background + ) { + KoinContext { + NewsMainScreen() + } } } } diff --git a/compose-app/src/iosMain/kotlin/dev/androidbroadcast/news/compose/NewsApp.ios.kt b/compose-app/src/iosMain/kotlin/dev/androidbroadcast/news/compose/NewsApp.ios.kt new file mode 100644 index 0000000..b85485f --- /dev/null +++ b/compose-app/src/iosMain/kotlin/dev/androidbroadcast/news/compose/NewsApp.ios.kt @@ -0,0 +1,11 @@ +package dev.androidbroadcast.news.compose + +import androidx.compose.runtime.Composable + +@Composable +internal actual fun NewsPlatformTheme( + darkTheme: Boolean, + content: @Composable () -> Unit, +) { + // Do nothing +} diff --git a/compose-app/src/jvmMain/kotlin/dev/androidbroadcast/news/compose/NewsApp.jvm.kt b/compose-app/src/jvmMain/kotlin/dev/androidbroadcast/news/compose/NewsApp.jvm.kt new file mode 100644 index 0000000..b85485f --- /dev/null +++ b/compose-app/src/jvmMain/kotlin/dev/androidbroadcast/news/compose/NewsApp.jvm.kt @@ -0,0 +1,11 @@ +package dev.androidbroadcast.news.compose + +import androidx.compose.runtime.Composable + +@Composable +internal actual fun NewsPlatformTheme( + darkTheme: Boolean, + content: @Composable () -> Unit, +) { + // Do nothing +} diff --git a/core/uikit/src/androidMain/kotlin/dev/androidbroadcast/news/Theme.android.kt b/core/uikit/src/androidMain/kotlin/dev/androidbroadcast/news/Theme.android.kt index 5d1be7f..a095948 100644 --- a/core/uikit/src/androidMain/kotlin/dev/androidbroadcast/news/Theme.android.kt +++ b/core/uikit/src/androidMain/kotlin/dev/androidbroadcast/news/Theme.android.kt @@ -22,18 +22,3 @@ internal actual fun dynamicColorScheme(darkTheme: Boolean): ColorScheme { internal actual fun isPlatformWithDynamicSystemTheme(): Boolean { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S } - -@Composable -internal actual fun platformThemeSetup( - darkTheme: Boolean, - colorScheme: ColorScheme, -) { - val view = LocalView.current - if (!view.isInEditMode) { - SideEffect { - val window = (view.context as Activity).window - window.statusBarColor = colorScheme.primary.toArgb() - WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme - } - } -} diff --git a/core/uikit/src/commonMain/kotlin/dev/androidbroadcast/news/Theme.kt b/core/uikit/src/commonMain/kotlin/dev/androidbroadcast/news/Theme.kt index c57ef36..92de675 100644 --- a/core/uikit/src/commonMain/kotlin/dev/androidbroadcast/news/Theme.kt +++ b/core/uikit/src/commonMain/kotlin/dev/androidbroadcast/news/Theme.kt @@ -38,12 +38,6 @@ internal expect fun isPlatformWithDynamicSystemTheme(): Boolean @Composable internal expect fun dynamicColorScheme(darkTheme: Boolean): ColorScheme -@Composable -internal expect fun platformThemeSetup( - darkTheme: Boolean, - colorScheme: ColorScheme, -) - @Composable fun NewsTheme( darkTheme: Boolean = isSystemInDarkTheme(), @@ -58,8 +52,6 @@ fun NewsTheme( else -> LightColorScheme } - platformThemeSetup(darkTheme, colorScheme) - MaterialTheme( colorScheme = colorScheme, typography = Typography, diff --git a/core/uikit/src/iosMain/kotlin/dev/androidbroadcast/news/Theme.ios.kt b/core/uikit/src/iosMain/kotlin/dev/androidbroadcast/news/Theme.ios.kt index 460fc25..f248f2d 100644 --- a/core/uikit/src/iosMain/kotlin/dev/androidbroadcast/news/Theme.ios.kt +++ b/core/uikit/src/iosMain/kotlin/dev/androidbroadcast/news/Theme.ios.kt @@ -9,11 +9,3 @@ internal actual fun dynamicColorScheme(darkTheme: Boolean): ColorScheme { } internal actual fun isPlatformWithDynamicSystemTheme(): Boolean = false - -@Composable -internal actual fun platformThemeSetup( - darkTheme: Boolean, - colorScheme: ColorScheme, -) { - // Do nothing -} diff --git a/core/uikit/src/jvmMain/kotlin/dev/androidbroadcast/news/Theme.jvm.kt b/core/uikit/src/jvmMain/kotlin/dev/androidbroadcast/news/Theme.jvm.kt index 738accb..f248f2d 100644 --- a/core/uikit/src/jvmMain/kotlin/dev/androidbroadcast/news/Theme.jvm.kt +++ b/core/uikit/src/jvmMain/kotlin/dev/androidbroadcast/news/Theme.jvm.kt @@ -9,8 +9,3 @@ internal actual fun dynamicColorScheme(darkTheme: Boolean): ColorScheme { } internal actual fun isPlatformWithDynamicSystemTheme(): Boolean = false - -@Composable -internal actual fun platformThemeSetup(darkTheme: Boolean, colorScheme: ColorScheme) { - // Do nothing -}