Open alexfacciorusso opened 10 months ago
A workaround could be to manually put a coloured box or surface underneath the previewed content, but I believe that should be handled by the Preview itself.
a possible workaround:
import org.jetbrains.skiko.currentSystemTheme
@Preview
@Composable
fun Abc() {
Text(currentSystemTheme.name)
}
It didn't work for me on Ubuntu though. it printed - UKNOWN. Perhaps, it works on Windows.
In case it may be of any help to whoever comes here for this bug, I have created this library as a workaround: https://github.com/alexfacciorusso/compose-previewer
In future, I might think of writing a wrapper of the IntelliJ Preview plugin to use it via an annotation.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Describe the bug
The @Preview annotated function seems to be rendered by the androidx.compose.desktop.ui.tooling.preview.runtime.NonInteractivePreviewFacade respecting the system's dark/light setting.
The IntelliJ plugin, adds a white background underneath the resulting image. See
org.jetbrains.compose.desktop.ide.preview.ui.PreviewPanel#paintComponent
function:The result is that if my system is in dark mode, the Composable gets rendered in dark mode, but the Panel in IntelliJ shows it over a white background, making it potentially not visible/not legible and in general, rendering the Preview unuseful.
Currently, the
@Preview
annotation for desktop does not allow forcing dark or light mode, and, to add to the whole,LocalInspectionMode
is also not usable to work around the issue (see bug https://github.com/JetBrains/compose-multiplatform/issues/2852).Affected platforms Select one of the platforms below:
If the bug is Android-only, report it in the Jetpack Compose tracker
Versions
To Reproduce
Expected behavior
TBD. Maybe if the system's dark mode is detected the background should be dark/black otherwise white. Or the @Preview annotation should be able to override dark mode. To be discussed.
Screenshots
Additional context