-
-
Save oianmol/52f25be2a0e8f0d9bd2ca16b5d308625 to your computer and use it in GitHub Desktop.
| @Composable | |
| actual fun PlatformColors(statusBarColor: Color, navBarColor: Color){ | |
| val sysUiController = rememberSystemUiController() | |
| SideEffect { | |
| sysUiController.setSystemBarsColor(color = topColor) | |
| sysUiController.setNavigationBarColor(color = bottomColor) | |
| } | |
| } |
| @Composable | |
| expect fun PlatformColors(statusBarColor: Color, navBarColor: Color) |
| @Composable | |
| private fun statusBarView() = remember { | |
| val keyWindow: UIWindow? = | |
| UIApplication.sharedApplication.windows.firstOrNull { (it as? UIWindow)?.isKeyWindow() == true } as? UIWindow | |
| val tag = 3848245L // https://stackoverflow.com/questions/56651245/how-to-change-the-status-bar-background-color-and-text-color-on-ios-13 | |
| keyWindow?.viewWithTag(tag)?.let { | |
| it | |
| } ?: run { | |
| val height = | |
| keyWindow?.windowScene?.statusBarManager?.statusBarFrame ?: zeroValue<CGRect>() | |
| val statusBarView = UIView(frame = height) | |
| statusBarView.tag = tag | |
| statusBarView.layer.zPosition = 999999.0 | |
| keyWindow?.addSubview(statusBarView) | |
| statusBarView | |
| } | |
| } | |
| @Composable | |
| actual fun PlatformColors( | |
| statusBarColor: Color, | |
| navBarColor: Color | |
| ) { | |
| val statusBar = statusBarView() | |
| SideEffect { | |
| statusBar?.backgroundColor = topColor.toUIColor() | |
| UINavigationBar.appearance().backgroundColor = bottomColor.toUIColor() | |
| } | |
| } | |
| private fun Color.toUIColor(): UIColor = UIColor( | |
| red = this.red.toDouble(), | |
| green = this.green.toDouble(), | |
| blue = this.blue.toDouble(), | |
| alpha = this.alpha.toDouble() | |
| ) |
Could You Please use import packages getting lot of errors.
Why there is no imports? Please share the full source code.
Here are imports @Micoder-dev
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.zeroValue
import platform.CoreGraphics.CGRect
import platform.UIKit.UIApplication
import platform.UIKit.UIColor
import platform.UIKit.UIView
import platform.UIKit.UIWindow
import platform.UIKit.statusBarManager
@ImranAtBhimsoft
Thank You ❤️
@ImranAtBhimsoft did you resolve that space between StatusBar and toolbar please?
@ImranAtBhimsoft did you resolve that space between StatusBar and toolbar please?
tried edge to edge?

Fiz esse implementação e só funcionou em Android