Closed paxbun closed 2 months ago
Thanks! I will take a look
Maybe related to this issue: https://github.com/JetBrains/compose-multiplatform/issues/4045
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Describe the bug On iPad,
displayCutoutPadding
applies zero insets in landspace modes but applies some insets in portrait modes. In the normal portrait mode, there is a top inset; in the upside-down portrait mode, there is a bottom inset.Affected platforms
Versions
To Reproduce Steps and/or the code snippet to reproduce the behavior:
composeApp/src/iosMain/kotlin/MainViewController.kt
as follows. (The button in the example shows/hides the status bar)fun MainViewController() = ComposeUIViewController { val uiViewController = LocalUIViewController.current val rootViewController = uiViewController.view.window?.rootViewController val statusBarController = remember { StatusBarController() } DisposableEffect(rootViewController) { if (rootViewController != null) { with(statusBarController) { rootViewController.addChildViewController(this) rootViewController.view.addSubview(view) didMoveToParentViewController(rootViewController) } } onDispose { with(statusBarController) { willMoveToParentViewController(null) view.removeFromSuperview() } } } MaterialTheme { Box(Modifier.fillMaxSize()) { Box(Modifier.displayCutoutPadding().fillMaxSize().background(Color.Red).zIndex(0.0f)) Box(Modifier.safeContentPadding().fillMaxSize().background(Color.Blue).zIndex(10.0f)) Box(Modifier.safeContentPadding().zIndex(20.0f)) { Button(onClick = { statusBarController.statusBarHidden = !statusBarController.statusBarHidden }) { Text("Click me!") } } } } }
@OptIn(ExperimentalForeignApi::class) class StatusBarController : UIViewController(nibName = null, bundle = null) { init { view.setBounds(CGRectZero.readValue()) }
}
Expected behavior With every screen orientation, displayCutoutPadding must behave the same.
Screenshots
https://github.com/JetBrains/compose-multiplatform/assets/17005454/cc08d043-df50-456a-93c3-cb5d76879a4e
Additional context The current implementation relies on
UIViewController.safeAreaInsets
, and on iPadOS,safeAreaInsets
does not return different values by screen orientation. So,WindowInsets.Companion.displayCutout
should check forUIDevice.currentDevice.userInterfaceIdiom
and useiosSafeArea.only(WindowInsetsSides.Top)
regardless of the orientation on iPad. However, that makesdisplayCutoutPadding
always put some top insets when the status bar is present. This is becausesafeAreaInsets
behaves differently on devices without notches, even on the iPhone SE. The only way to make the value ofsafeAreaInsets.top
0 is to hide the status bar, as shown in the example above. One way to "fix" this problem would be to ignoresafeAreaInsets
on iPad and iPhone SE and set a manualadditionalSafeAreaInsets
.