Vinicius Matheus
10/21/2023, 8:39 PM// main.android.kt
@Composable
actual fun setStatusBarColor(color: Color, isDark: Boolean) {
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
val window = (view.context as Activity).window
window.statusBarColor = color.toArgb()
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !isDark
}
}
}
// main.ios.kt
@Composable
actual fun setStatusBarColor(color: Color, isDark: Boolean) {
val statusBarColor = UIColor(
CIColor(
color.red.toDouble(),
color.green.toDouble(),
color.green.toDouble(),
color.alpha.toDouble(),
),
)
UIApplication
.sharedApplication
.keyWindow
?.windowScene
?.statusBarManager
?.statusBarFrame()
?.let {
UIView(it)
}?.apply {
setBackgroundColor(statusBarColor)
}?.let {
UIApplication.sharedApplication.keyWindow?.addSubview(it)
}
}
लातों वाला भूत
10/22/2023, 4:59 PMval colorScheme = when {
isDynamicColorAvailable && darkTheme -> dynamicDarkColorScheme(context)
isDynamicColorAvailable -> dynamicLightColorScheme(context)
darkTheme -> DarkColors
else -> LightColors
}
val colorScheme = if (darkTheme) DarkColors else LightColors
val statusBarColor = UIColor(CIColor(
red = colorScheme.surfaceVariant.red.toDouble(),
green = colorScheme.surfaceVariant.green.toDouble(),
blue = colorScheme.surfaceVariant.blue.toDouble(),
alpha = colorScheme.surfaceVariant.alpha.toDouble(),
))
UIApplication
.sharedApplication
.keyWindow
?.windowScene
?.statusBarManager
?.statusBarFrame()
?.let {
UIView(it)
}?.apply {
setBackgroundColor(statusBarColor)
}?.let {
UIApplication.sharedApplication.keyWindow?.addSubview(it)
}
Vinicius Matheus
10/23/2023, 12:51 PM