compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

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

Open begali opened this issue 1 year ago • 5 comments

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) {}
}

  1. Run this code snippet:
    @Composable
    fun MainViewController() {
        println("APP theme mode: "+ isSystemInDarkTheme())
    }
    
  2. Click on Simulator-> Features-> Toggle Appearance

begali avatar Jun 17 '24 10:06 begali

Can't reproduce

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

elijah-semyonov avatar Jun 18 '24 12:06 elijah-semyonov

@begali Can you please send a repro project?

elijah-semyonov avatar Jun 18 '24 12:06 elijah-semyonov

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.

begali avatar Jun 18 '24 17:06 begali

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

alexzhirkevich avatar Jun 18 '24 17:06 alexzhirkevich

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

begali avatar Jun 20 '24 01:06 begali

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

okushnikov avatar Aug 26 '24 13:08 okushnikov