I'm using Compose Multiplatform 1.8.2 and in my commonMain, I have the following composable function with a preview:
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.unit.dp
import blitz_split.feature.login.login_presentation.generated.resources.Res
import blitz_split.feature.login.login_presentation.generated.resources.blitz_split_login_art
import blitz_split.feature.login.login_presentation.generated.resources.split_screen_message
import com.blitzplit.component.logo.Logo
import com.blitzsplit.spacer.VerticalSpacer
import com.blitzsplit.theme.AppTheme
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource
@Composable
fun LoginContent(
isLoading: Boolean,
onLoginWithGoogleClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Column(
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.SpaceAround
) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Logo(modifier = Modifier.fillMaxWidth())
VerticalSpacer()
Text(
modifier = Modifier
.padding(horizontal = 32.dp),
text = stringResource(Res.string.split_screen_message),
style = MaterialTheme.typography.bodyLarge.copy(
fontWeight = FontWeight.Bold,
color = LocalContentColor.current.copy(alpha = 0.6f)
),
textAlign = TextAlign.Center,
)
VerticalSpacer(32.dp)
Image(
painter = painterResource(Res.drawable.blitz_split_login_art),
contentDescription = "background login"
)
}
val dynamicModifier = Modifier.fillMaxWidth()
LoginWithGoogleButton(
modifier = dynamicModifier.padding(horizontal = 32.dp),
onLoginWithGoogleClick = onLoginWithGoogleClick,
isLoading = isLoading,
)
}
}
@Composable
@PreviewLightDark
private fun LoginContentPreview() {
AppTheme {
LoginContent(
isLoading = false,
onLoginWithGoogleClick = {}
)
}
}
It shows the preview correctly for light and dark. But it doesn't show the background:
If I change the preview function to use:
@Composable
@PreviewLightDark
@Preview(showBackground = true)
Then I'll see three preview functions (the light without background, the dark without background, and the light with background). But it doesn't show me the dark background:
How can I see the background for the dark and light previews in the compose multiplatform?
