Need to provide a LocalAsyncImagePreviewHandler for previews to work correctly with coil3
https://coil-kt.github.io/coil/compose/#previews
This commit is contained in:
parent
3a09d1c4ca
commit
42fcf31080
1 changed files with 13 additions and 6 deletions
|
|
@ -9,9 +9,14 @@ package io.element.android.libraries.designsystem.preview
|
||||||
|
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import coil3.annotation.ExperimentalCoilApi
|
||||||
|
import coil3.compose.AsyncImagePreviewHandler
|
||||||
|
import coil3.compose.LocalAsyncImagePreviewHandler
|
||||||
import io.element.android.compound.theme.ElementTheme
|
import io.element.android.compound.theme.ElementTheme
|
||||||
import io.element.android.libraries.designsystem.theme.components.Surface
|
import io.element.android.libraries.designsystem.theme.components.Surface
|
||||||
|
|
||||||
|
@OptIn(ExperimentalCoilApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@Suppress("ModifierMissing")
|
@Suppress("ModifierMissing")
|
||||||
fun ElementPreview(
|
fun ElementPreview(
|
||||||
|
|
@ -19,12 +24,14 @@ fun ElementPreview(
|
||||||
showBackground: Boolean = true,
|
showBackground: Boolean = true,
|
||||||
content: @Composable () -> Unit
|
content: @Composable () -> Unit
|
||||||
) {
|
) {
|
||||||
ElementTheme(darkTheme = darkTheme) {
|
CompositionLocalProvider(LocalAsyncImagePreviewHandler provides AsyncImagePreviewHandler { null }) {
|
||||||
if (showBackground) {
|
ElementTheme(darkTheme = darkTheme) {
|
||||||
// If we have a proper contentColor applied we need a Surface instead of a Box
|
if (showBackground) {
|
||||||
Surface(content = content)
|
// If we have a proper contentColor applied we need a Surface instead of a Box
|
||||||
} else {
|
Surface(content = content)
|
||||||
content()
|
} else {
|
||||||
|
content()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue