Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support loading resource files in the Android Studio preview #1915

Open
Quyunshuo opened this issue Nov 2, 2023 · 4 comments
Open

Support loading resource files in the Android Studio preview #1915

Quyunshuo opened this issue Nov 2, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@Quyunshuo
Copy link

I am using AsyncImage to load a webp image in a resource file, but I have no way to preview it, is there any way to provide a preview without affecting the logic? For example, are there any tools attributes similar to those in xml?

To Reproduce
Load a resource file

Logs/Screenshots
image
image

Version
version: 2.5.0

@colinrtwhite
Copy link
Member

This is currently intended behaviour. Coil only loads the placeholder in the preview environment - mostly since we can guarantee that the placeholder isn't a URL or another data type that can't be loaded in the preview environment. That said, we should re-evaluate this behaviour and likely make it possible to load known-loadable data types (resource ints, bitmaps) in previews.

I'm thinking we could support something like this:

AsyncImage(
    model = if (LocalInspectionMode.current) {
        "https://example.com/image.jpg"
    } else {
        R.drawable.preview_placeholder
    },
    contentDescription = null,
)

@Quyunshuo
Copy link
Author

Looking forward to the follow-up

@colinrtwhite
Copy link
Member

Let's keep this open to track.

@colinrtwhite colinrtwhite reopened this Nov 15, 2023
@colinrtwhite colinrtwhite changed the title Preview issue in the compose version when loading resource files Support loading resource files in the Android Studio preview Nov 15, 2023
@colinrtwhite colinrtwhite added the enhancement New feature or request label Nov 15, 2023
@colinrtwhite
Copy link
Member

This is now more important given androidx's new screenshot testing library sets isPreview = true and doesn't set a Dispatchers.Main implementation. This means FakeImageEngine can't easily be used in that environment.

As a stopgap I think it probably makes sense to introduce a LocalAsyncImagePainterPreviewHandler to allow overriding AsyncImagePainter's preview behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants