-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92a1614
commit 6166ce6
Showing
6 changed files
with
109 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ kotlin { | |
} | ||
} | ||
|
||
jvm() | ||
|
||
sourceSets { | ||
commonMain.dependencies { | ||
api(compose.ui) | ||
|
99 changes: 2 additions & 97 deletions
99
core/uikit/src/androidMain/kotlin/dev/androidbroadcast/news/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 |
---|---|---|
@@ -1,102 +1,7 @@ | ||
package dev.androidbroadcast.news | ||
|
||
import android.app.Activity | ||
import android.os.Build | ||
import androidx.compose.foundation.isSystemInDarkTheme | ||
import androidx.compose.material3.ColorScheme | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Shapes | ||
import androidx.compose.material3.Typography | ||
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.runtime.ReadOnlyComposable | ||
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 | ||
|
||
private val DarkColorScheme = | ||
darkColorScheme( | ||
primary = Purple80, | ||
secondary = PurpleGrey80, | ||
tertiary = Pink80 | ||
) | ||
|
||
private val LightColorScheme = | ||
lightColorScheme( | ||
primary = Purple40, | ||
secondary = PurpleGrey40, | ||
tertiary = Pink40 | ||
/* Other default colors to override | ||
background = Color(0xFFFFFBFE), | ||
surface = Color(0xFFFFFBFE), | ||
onPrimary = Color.White, | ||
onSecondary = Color.White, | ||
onTertiary = Color.White, | ||
onBackground = Color(0xFF1C1B1F), | ||
onSurface = Color(0xFF1C1B1F), | ||
*/ | ||
) | ||
|
||
@Composable | ||
fun NewsTheme( | ||
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 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 | ||
} | ||
} | ||
|
||
MaterialTheme( | ||
colorScheme = colorScheme, | ||
typography = Typography, | ||
content = content | ||
) | ||
} | ||
|
||
object NewsTheme { | ||
/** | ||
* Retrieves the current [ColorScheme] at the call site's position in the hierarchy. | ||
*/ | ||
val colorScheme: ColorScheme | ||
@Composable | ||
@ReadOnlyComposable | ||
get() = MaterialTheme.colorScheme | ||
|
||
/** | ||
* Retrieves the current [Typography] at the call site's position in the hierarchy. | ||
*/ | ||
val typography: Typography | ||
@Composable | ||
@ReadOnlyComposable | ||
get() = MaterialTheme.typography | ||
|
||
/** | ||
* Retrieves the current [Shapes] at the call site's position in the hierarchy. | ||
*/ | ||
val shapes: Shapes | ||
@Composable | ||
@ReadOnlyComposable | ||
get() = MaterialTheme.shapes | ||
internal actual fun isPlatformWithDynamicSystemTheme(): Boolean { | ||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S | ||
} |
File renamed without changes.
98 changes: 98 additions & 0 deletions
98
core/uikit/src/commonMain/kotlin/dev/androidbroadcast/news/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,98 @@ | ||
package dev.androidbroadcast.news | ||
|
||
import androidx.compose.foundation.isSystemInDarkTheme | ||
import androidx.compose.material3.ColorScheme | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Shapes | ||
import androidx.compose.material3.Typography | ||
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.runtime.ReadOnlyComposable | ||
import androidx.compose.ui.platform.LocalContext | ||
|
||
private val DarkColorScheme = | ||
darkColorScheme( | ||
primary = Purple80, | ||
secondary = PurpleGrey80, | ||
tertiary = Pink80 | ||
) | ||
|
||
private val LightColorScheme = | ||
lightColorScheme( | ||
primary = Purple40, | ||
secondary = PurpleGrey40, | ||
tertiary = Pink40 | ||
/* Other default colors to override | ||
background = Color(0xFFFFFBFE), | ||
surface = Color(0xFFFFFBFE), | ||
onPrimary = Color.White, | ||
onSecondary = Color.White, | ||
onTertiary = Color.White, | ||
onBackground = Color(0xFF1C1B1F), | ||
onSurface = Color(0xFF1C1B1F), | ||
*/ | ||
) | ||
|
||
internal expect fun isPlatformWithDynamicSystemTheme(): Boolean | ||
|
||
@Composable | ||
fun NewsTheme( | ||
darkTheme: Boolean = isSystemInDarkTheme(), | ||
// Dynamic color is available on Android 12+ | ||
dynamicColor: Boolean = true, | ||
content: @Composable () -> Unit | ||
) { | ||
val colorScheme = | ||
when { | ||
dynamicColor && isPlatformWithDynamicSystemTheme() -> { | ||
val context = LocalContext.current | ||
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) | ||
} | ||
|
||
darkTheme -> DarkColorScheme | ||
else -> LightColorScheme | ||
} | ||
// 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 | ||
// } | ||
// } | ||
|
||
MaterialTheme( | ||
colorScheme = colorScheme, | ||
typography = Typography, | ||
content = content | ||
) | ||
} | ||
|
||
object NewsTheme { | ||
/** | ||
* Retrieves the current [ColorScheme] at the call site's position in the hierarchy. | ||
*/ | ||
val colorScheme: ColorScheme | ||
@Composable | ||
@ReadOnlyComposable | ||
get() = MaterialTheme.colorScheme | ||
|
||
/** | ||
* Retrieves the current [Typography] at the call site's position in the hierarchy. | ||
*/ | ||
val typography: Typography | ||
@Composable | ||
@ReadOnlyComposable | ||
get() = MaterialTheme.typography | ||
|
||
/** | ||
* Retrieves the current [Shapes] at the call site's position in the hierarchy. | ||
*/ | ||
val shapes: Shapes | ||
@Composable | ||
@ReadOnlyComposable | ||
get() = MaterialTheme.shapes | ||
} |
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
core/uikit/src/jvmMain/kotlin/dev/androidbroadcast/news/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,7 @@ | ||
package dev.androidbroadcast.news | ||
|
||
import android.os.Build | ||
|
||
internal actual fun isPlatformWithDynamicSystemTheme(): Boolean { | ||
return false | ||
} |