Fix broken preview of BottomSheet in Android Studio.

This commit is contained in:
Benoit Marty
2026-06-19 14:04:46 +02:00
parent e98cbdfce1
commit 123037a612
11 changed files with 29 additions and 16 deletions
@@ -65,7 +65,7 @@ fun SimpleModalBottomSheet(
@PreviewsDayNight
@Composable
internal fun SimpleModalBottomSheetPreview() = ElementPreview {
internal fun SimpleModalBottomSheetPreview() = ElementPreview(fillMaxSize = true) {
SimpleModalBottomSheet(title = "A title", onDismiss = {}) {
Text(
text = LoremIpsum(20).values.first(),
@@ -10,8 +10,11 @@ package io.element.android.libraries.designsystem.preview
import androidx.annotation.DrawableRes
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.core.content.res.ResourcesCompat
import coil3.annotation.ExperimentalCoilApi
@@ -29,6 +32,7 @@ import io.element.android.libraries.designsystem.utils.CommonDrawables
fun ElementPreview(
theme: Theme = if (isSystemInDarkTheme()) Theme.Dark else Theme.Light,
showBackground: Boolean = true,
fillMaxSize: Boolean = false,
@DrawableRes
drawableFallbackForImages: Int = CommonDrawables.sample_background,
content: @Composable () -> Unit
@@ -42,9 +46,18 @@ fun ElementPreview(
ElementTheme(theme = theme) {
if (showBackground) {
// If we have a proper contentColor applied we need a Surface instead of a Box
Surface(content = content)
Surface(
modifier = if (fillMaxSize) Modifier.fillMaxSize() else Modifier,
content = content,
)
} else {
content()
if (fillMaxSize) {
Box(modifier = Modifier.fillMaxSize()) {
content()
}
} else {
content()
}
}
}
}