Hey everyone. The `isSystemInDarkTheme()` flag do...
# compose-ios
p
Hey everyone. The
isSystemInDarkTheme()
flag does not set dark theme on iOS. It works as expected on android. Using
1.5.0-rc06
version of compose multiplatform.
1
The theme file is structured as follows: The commonMain directory has an expect fun declaration for the theme. Here, the useDarkTheme variable is set to
isSystemInDarkTheme()
flag.
Copy code
@Composable
expect fun AppTheme(
    useDarkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable () -> Unit
)
And here's the iosMain actual implementation of the theme:
Copy code
@Composable
actual fun AppTheme(
    useDarkTheme: Boolean,
    content: @Composable () -> Unit
) {
    val colors = when {
        useDarkTheme -> DarkColors
        else -> LightColors
    }
    MaterialTheme(
        colorScheme = colors,
        content = content
    )
}
a
Seems to work. Can you please create an issue and attach a minimal reproducible project?
👍 1
f
I did this for it to work
Copy code
return ComposeUIViewController {
        val darkTheme = UIScreen.mainScreen.traitCollection.userInterfaceStyle ==
                UIUserInterfaceStyle.UIUserInterfaceStyleDark
       ...
        // Bind safe area as the value for LocalSafeArea
        CompositionLocalProvider(LocalSafeArea provides safeArea) {
            TalamydAppTheme(darkTheme) {
                Surface(
                    color = MaterialTheme.colorScheme.background,
                    modifier = Modifier.fillMaxSize()
                ) {
                    ContentView(
                        component = root,
                    )
                }
            }
        }
    }
Copy code
@Composable
fun TalamydAppTheme(
    darkTheme: Boolean,
    content: @Composable () -> Unit
) {

    val colors = if (darkTheme) DarkColorScheme else LightColorScheme
    MaterialTheme(
        colorScheme = colors,
        content = content,
        typography = Typography
    )
}
gratitude thank you 1
p
@Alexander Zhirkevich Raised a bug with a minimal reproducible project attached: https://github.com/JetBrains/compose-multiplatform/issues/3575
@Farid Benhaimoud Thanks for your help. Will check and see if this works. Meanwhile, I have also raised a bug for the same.
The issue was due to
Copy code
.preferredColorScheme(.light)
this line in iosApp.swift file.
thank you color 1
1
d
Thanks! That was mistake in template project. Already fixed!
🙌 1