`isSystemInDarkTheme()` not causing recomposition when using `UINavigationController` as wrapper on compose `UIViewController`
Describe the bug
androidx.compose.foundation.isSystemInDarkTheme() not causing recomposition when using UINavigationController as wrapper on compose UIViewController.
Affected platforms
- iOS
Versions
- Libraries:
- Compose Multiplatform version: 1.6.10
- Kotlin version: 2.0.0
To Reproduce Steps to reproduce the behavior:
struct ContentView: View {
var body: some View {
RootNavControllerWrapper()
.ignoresSafeArea(.keyboard)
.ignoresSafeArea(.all)
}
}
struct RootNavControllerWrapper: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UINavigationController {
let rootController = MainViewControllerKt.MainViewController()
let navController = UINavigationController(rootViewController: rootController)
navController.setNavigationBarHidden(true, animated: false)
return navController
}
func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {}
}
- Run this code snippet:
@Composable fun MainViewController() { println("APP theme mode: "+ isSystemInDarkTheme()) } - Click on Simulator-> Features-> Toggle Appearance
Can't reproduce
https://github.com/JetBrains/compose-multiplatform/assets/4167681/aa553c9c-82b5-46b9-919f-5e962a1c99fd
@begali Can you please send a repro project?
In my project I'm using compose cupertino library. CupertinoTheme was the reason of the bug. Link to reproduce the bug https://github.com/begali/CupertinoThemeBug. In my opinion CupertinoTheme somehow blocking recomposition.
It overrides user interface style to let you have light keyboard for light app when the system is dark. Interesting side effect
@elijah-semyonov Can you please check? viewController.overrideUserInterfaceStyle = if (dark) UIUserInterfaceStyle.UIUserInterfaceStyleDark else UIUserInterfaceStyle.UIUserInterfaceStyleLight as mentioned by @alexzhirkevich causing the theme not to change in compose.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.