darkmoon_uk
11/17/2021, 8:33 PM@Composable
is being presented in a @Preview
or not? (Something in Locals?)
I know it shouldn't care; but sometimes in the real world there are practical reasons.
In this case the Coil SVG library is crashing in Previews for some class-loader related reason; I need some flag to suppress registering of the SVG handler in Previews so I can get on with building the rest of the View.Andrew Neal
11/17/2021, 8:41 PMdarkmoon_uk
11/17/2021, 8:46 PMLocalImageLoader
- Coils SVG renderer is just exhibiting an incompatibility with `Preview`s right now, and I need something like an isRunningInPreviewMode
flag to suppress it.Ian Lake
11/17/2021, 8:47 PMdarkmoon_uk
11/17/2021, 8:48 PMAndrew Neal
11/17/2021, 8:50 PMLocalImageLoader
in your preview to avoid loading the SVG?Ian Lake
11/17/2021, 9:04 PMLocalImageLoader
specifically wrapping the components you want to preview that is essentially a no-op / has preview specific behavior. That way your component itself doesn't need to know about whether it is in a preview or notdarkmoon_uk
11/17/2021, 9:11 PMLocalImageLoader
from a top-level @Composable
scope and identified that it's enough to just not register the SVG handler during its configuration. The rest of Coil's ImageLoader
isn't a problem, and no components need to be aware; SVG's just won't be handled.implementation
classpath in Gradle and runtime is OK 🤷).ImageLoader
in the end; thanks Andrew & Ian ⭐yschimke
11/18/2021, 8:14 AMfun rememberAstronautPainter(person: Assignment?) =
rememberImagePainter(person?.personImageUrl) {
// Use the generic astronaut SVG for missing or error (404?).
fallback(R.drawable.ic_american_astronaut)
error(R.drawable.ic_american_astronaut)
if (LocalInspectionMode.current) {
// Show error image instead of blank in @Preview
placeholder(R.drawable.ic_american_astronaut)
}
}
darkmoon_uk
11/18/2021, 9:22 AMyschimke
11/18/2021, 9:50 AM