JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.24k stars 1.11k forks source link

`isSystemInDarkTheme()` not causing recomposition when using `UINavigationController` as wrapper on compose `UIViewController` #4987

Open begali opened 1 week ago

begali commented 1 week ago

Describe the bug androidx.compose.foundation.isSystemInDarkTheme() not causing recomposition when using UINavigationController as wrapper on compose UIViewController.

Affected platforms

Versions

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) {}
}
  1. Run this code snippet:
    @Composable
    fun MainViewController() {
       println("APP theme mode: "+ isSystemInDarkTheme())
    }
  2. Click on Simulator-> Features-> Toggle Appearance
elijah-semyonov commented 1 week ago

Can't reproduce

https://github.com/JetBrains/compose-multiplatform/assets/4167681/aa553c9c-82b5-46b9-919f-5e962a1c99fd

elijah-semyonov commented 1 week ago

@begali Can you please send a repro project?

begali commented 1 week ago

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.

alexzhirkevich commented 1 week ago

It overrides user interface style to let you have light keyboard for light app when the system is dark. Interesting side effect

begali commented 6 days ago

@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.