Hi, I'm wondering is there a way to provide LocalC...
# compose-desktop
o
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
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
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
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
isSystemInDarkTheme()
(which delegates to checking via skiko as seen here: https://github.com/search?q=repo%3AJetBrains%2Fskiko+%22actual+val+currentSystemTheme%22&type=code) If you want to “force” dark mode, you can just replace any usages of that API with a constant
true
and use a MaterialTheme with values for dark mode.
If you don’t already have a dark material theme, you can generate one here
o
Okay, that makes sense! Thanks for great answer! 🙂 I think I'll try to replace the usage of the
isSystemInDarkTheme
API 🙂
But I think if I do that, I will do it for the whole system and not just one section 🤔
c
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()
    }
  }
}