Hi! Can somebody help me with using `android:force...
# compose
m
Hi! Can somebody help me with using
android:forceDarkAllowed = true
I didn't find any useful resources on how to use this with Compose. Thanks in advance.
c
Are you trying to use this in Views or in Compose? There's a system call you can use to know if the device is in dark theme and act accordingly there, e.g. pass dark colors, etc https://developer.android.com/jetpack/compose/themes/material#dark-theme
m
Yeah, I am aware of that. Before moving to Jetpack Compose, by setting
android:forceDarkAllowed = true
flag in styles.xml I got the app to convert into dark theme colors (I know you can't choose colors) when dark theme toggle is on, but with compose, I am not sure how to apply the same thing. I tried to do it in themes.xml but that is not auto converting all the views into dark theme colors.
c
So you want to force your Compose hierarchies to be dark colors or Views in a Compose hierarchy?
The colors you pass to MaterialTheme can be directly controlled by your app. The defaults are a set of baseline light and dark colors from Material spec but you override that when passing in your own set
So forcing a screen/hierarchy to be dark colors is really passing only dark colors to the theme. And also ensuring the elements in that hierarchy are using references to MaterialTheme
This is how the Jetcaster sample is done on GitHub. It only has dark colors for its theme
m
Force Dark analyzes each view of your light-themed app, and applies a dark theme automatically before it is drawn to the screen
I want all the views to be drawn in dark mode.
Copy code
<https://developer.android.com/guide/topics/ui/look-and-feel/darktheme#force-dark>
By the way, I already have different themes and colors implemented for dark theme using Material spec, I am looking to force everything on screen (views) to be drawn in dark colors when the dark theme setting is turned on.
c
Is passing dark colors to your theme Composable that wraps your Compose hierarchy not working when in dark mode? If so, do you have a code snippet?
m
The issue is I have a few UI components that I have no control over such as a list that opens up on a button (my dark theme colors for this button works fine) tap, I don't think I can apply dark color theme to that since it is not in my code. That is why I am looking for ForceDark, any ideas on how to deal with this?
c
I don't believe that mechanism exists yet but I would suggest reaching out to the developer of that code to make that list component dark theme aware or at least manually themeable.
Is this list component a public library?
m
No, It is coming from our SDK side of things and I can make it dark theme aware, but we already have non-compose apps that use forceDarkAllowed and it works fine for us. Just want to do the same for this app as well, but it is not working as expected. Are there any plans of working on it? If so, what are the timelines? Should we open a bug or something?
c
Sure you can file a request. I'm going to cc @Louis Pullen-Freilich [G] here as well who might have thoughts.
m
Thank you!
c
I don't think we have plans to support this type of attribute because a) theming works fundamentally different in Compose, and b) to that end it was designed to give devs more explicit control
l
Force dark is separate from theming, it's more of a flag to best effort invert colours - I agree the existing framework APIs should work here if they don't. Please file a bug with a sample app that shows the problem
🙏 1
👍 2