The `@Preview(showSystemUi = true)` option shows the status bar overlaid over the content, which is ...
m
The
@Preview(showSystemUi = true)
option shows the status bar overlaid over the content, which is not what's usually wanted. Am I missing something?
1
c
It's borrowed implementation from the old Layout Editor preview but needs some cleanup. Are you expecting not to see systemUi overlaid?
m
I mean that the status bar overlaps my toolbar in the preview, instead of being above the toolbar. Where in the actual app it's fine.
c
Hmm which version of Studio are you using? At least in Dolphin C3 it looks like the system bars are drawn outside the Composable at the top and bottom and not overlapping
m
I have found this was due to having
<item name="android:windowTranslucentStatus">true</item>
in my app theme. It seems to affect the Compose preview (even though it has nothing to do with Compose).
c
Ah I see. There is a connection between the two in Studio since the Preview uses similar infrastructure as the Layout Editor, where in the Activity theme is taken into consideration but more for tooling needs. I can give that feedback to the team though.
And the reality as you know is Compose is rendered within the context of an Activity (and respective theme), so on device, the two worlds inevitably interact with each other
m
Thank you. On the Layout Editor there is a theme dropdown, which allows you to select the theme, and by it's existence makes it clear the theme is affecting the preview. Maybe the Compose preview needs one too.
In this particular case, my Compose screen I was previewing is displaying in an Activity that doesn't have that property set, but I cannot tell the preview that. It seems to use the default theme?
c
Yeah I’m not sure which Activity theme it uses, maybe the first one, in the case you have multiple Activities declared in the manifest but I’ll check with the team. But either way, since there is a direct connection with the Activity theme and Preview, we should 1) make that clearer in docs/tooling, and 2) investigate creating a way to change that in Preview (though it brings up other questions in general about a default Compose theme to set for all Previews, outside of Activity theming).
cc @nosuid
p
Was there an outcome of this?
c
When using
showSystemUi
it needs a theme since we show things in the context of an Activity. We don’t have work planned to allow to change the theme from Preview parameters though since as mentioned it doesn’t and shouldn’t have to be related to Compose. At the moment one can control the theme used via the manifest.
We’ve heard use cases where there is no manifest though, for example, library modules, so we are working on supporting that case which might end up solving this issue as well: https://issuetracker.google.com/240292826