I'm `@Compose`-ing views that are dependent on bun...
# compose
d
I'm
@Compose
-ing views that are dependent on bundled resources at runtime; so these fail during preview. Is there a way I can check whether I'm running in
@Preview
mode
in the composition, so that I can just put colored block instead of the asset?
I've settled for setting an
Ambient
flag for this.
☝️ 1
See thread above. The very concept of such a function makes me very nervous.  It makes me think your widget is not sufficiently isolated / is not a function of its parameters.  Why do you want to know if you're in a preview?
d
Understand it's not a desirable concept. Reason for asking is that the IDE doesn't appear to be able to use raw Android file resources during Compose previews. The same is not a problem when deploying a preview to the device or emulator. Use case is rendering SVG files at runtime which we've opted for, to reduce image asset management overhead on a multiplatform project, and so these are held as 'raw' Android resource files.
This is possibly a bug rather than an intended limitation.
m
I suspect that what Jim is suggesting is that your composable should accept a parameter that indicates what is to be displayed. The default value would be "show the colored block"; the real calls would pass in something identifying the SVG to render.
@Preview
would use the default value. IOW, the rule of what to show is a function of the inputs, not a function of some "are we in preview" quasi-state.
j
Reason for asking is that the IDE doesn't appear to be able to use raw Android file resources during Compose previews.
I'm actually ok with Chris' answer: "resource issues". The current resource API leaves a lot to be desired, especially in terms of MPP (eg. Compose for Desktop), and I think it's reasonable for widgets to be able to have resources associated with the widget, and to the extent that is not supported, it should be treated as a bug and Chris is working around that bug. This won't make the 1.0 cut, but after 1.0, I think our team will need to do some serious thinking about how resources should be managed in Compose applications. Thanks for the feedback!
👍 3