Hari K
02/26/2025, 5:04 PM@Composable
actual fun StatusBarColors(
statusBarColor: Color,
navBarColor: Color,
) {
val statusBar = statusBarView()
SideEffect {
statusBar.backgroundColor = statusBarColor.toUIColor()
UINavigationBar.appearance().backgroundColor = navBarColor.toUIColor()
}
}
@OptIn(ExperimentalForeignApi::class)
@Composable
private fun statusBarView() = remember {
val keyWindow: UIWindow? =
UIApplication.sharedApplication.windows.firstOrNull { (it as? UIWindow)?.isKeyWindow() == true } as? UIWindow
val tag =
3848245L
keyWindow?.viewWithTag(tag) ?: 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
}
}
Max
02/27/2025, 7:57 AMJimmy Nelle
02/27/2025, 12:20 PM.ignoresSafeArea(edges: .all)