forked from touchlab/KaMPKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For touchlab#305 - Upstream the Compose theme to the shared module.
This will allow to share it with iOS also. Migrated to Material3 and Dynamic Color support for Android in the meantime. Migrated to support automatic day/night theme support for both platforms.
- Loading branch information
Showing
10 changed files
with
116 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 0 additions & 47 deletions
47
app/src/main/kotlin/co/touchlab/kampkit/android/ui/theme/Theme.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
shared/src/androidMain/kotlin/co/touchlab/kampkit/ui/theme/KaMPKitTheme.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) | ||
} |
2 changes: 1 addition & 1 deletion
2
...ouchlab/kampkit/android/ui/theme/Color.kt → ...lin/co/touchlab/kampkit/ui/theme/Color.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/KaMPKitTheme.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
4 changes: 2 additions & 2 deletions
4
...uchlab/kampkit/android/ui/theme/Shapes.kt → ...in/co/touchlab/kampkit/ui/theme/Shapes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/theme/Theme.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
) |
6 changes: 3 additions & 3 deletions
6
...ab/kampkit/android/ui/theme/Typography.kt → ...o/touchlab/kampkit/ui/theme/Typography.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
shared/src/iosMain/kotlin/co/touchlab/kampkit/ui.theme/KaMPKitTheme.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) | ||
} |