Hi, I'm wondering is there a way to provide LocalConfiguration in Compose for Desktop. If that exists for desktop, which dependency is that part of? 🙂
c
chr
06/21/2023, 12:06 AM
Given that it returns a
android.content.res.Configuration
, I assume accessing
LocalConfiguration
can only be done on a platform that defines
Configuration
, which is Android-only.
o
Odin
06/21/2023, 12:12 AM
Ah that makes sense. Thanks for the answere! 😊🙏 Do u know if there is any other way to force dark mode on a section of compose code in compose desktop? 😊 if that even makes sense on desktop 🤔
c
chr
06/21/2023, 12:16 AM
There’s no way to force the OS you’re running on to enable Dark Mode (since it’s a per-platform feature), but you can query it via
and use a MaterialTheme with values for dark mode.
chr
06/21/2023, 12:16 AM
If you don’t already have a dark material theme, you can generate one here
o
Odin
06/21/2023, 12:39 AM
Okay, that makes sense! Thanks for great answer! 🙂 I think I'll try to replace the usage of the
isSystemInDarkTheme
API 🙂
Odin
06/21/2023, 12:41 AM
But I think if I do that, I will do it for the whole system and not just one section 🤔
c
chr
06/21/2023, 6:53 AM
You can apply it to just a particular scope of your app. If you have a method to apply your theme like so:
Copy code
@Composable
fun MyTheme(isDarkMode: Boolean = isSystemInDarkTheme()) {
if (isDarkMode) {
MaterialTheme(colors = /* dark colors */)
} else {
MaterialTheme(colors = /* light colors */)
}
}
you can force only a specific part of the app to be in dark mode, if you want:
Copy code
MyTheme {
// This is in either light mode or dark mode, depending on the platform
Box {
MainContent()
MyTheme(isDarkMode = true) {
// This part will always be in dark mode
PopupContent()
}
}
}