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

Should support VectorDrawable resource id #1463

Open
ohshi000 opened this issue Sep 8, 2016 · 8 comments
Open

Should support VectorDrawable resource id #1463

ohshi000 opened this issue Sep 8, 2016 · 8 comments

Comments

@ohshi000
Copy link

ohshi000 commented Sep 8, 2016

tag need support. v21 and AppCompat already support v9 and up api level.

@kirwan
Copy link
Contributor

kirwan commented Sep 8, 2016

Where do you want to use VectorDrawable resource IDs?

Right now, Fresco will only load bitmaps for the primary image but for placeholders, backgrounds, overlays, loading drawables and failures they should work.

If you could give a small code snippet we can double check what your issue is.

@kirwan kirwan added the needs-details This issue or PR is currently not actionable as it misses details (e.g. for reproducing the problem) label Sep 8, 2016
@ohshi000
Copy link
Author

ohshi000 commented Sep 8, 2016




This is a vector image on res/drawable/ic_arrow.xml
So i need load the vector image with Fresco.
SimpleDraweeView.setImageUri("res://package/id")

@ohshi000
Copy link
Author

ohshi000 commented Sep 8, 2016

<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportHeight="24.0" android:viewportWidth="24.0"> <path android:fillColor="#cccccc" android:pathData="M8.59,16.34l4.58,-4.59 -4.58,-4.59L10,5.75l6,6 -6,6z"/> </vector>

@kirwan
Copy link
Contributor

kirwan commented Sep 8, 2016

DraweeView doesn't support VectorDrawables as the main image, only bitmaps. I think you would need to simply use an ImageView in this case.

DraweeView does extend ImageView but as the documentation on the class says, that shouldn't be taken as a sign that it supports everything that does.

@consp1racy
Copy link

DraweeViews support several XML attributes that load images from resources. The best and easiest way to extend functionality would be using

fun Context.getDrawableCompat(@DrawableRes resId: Int): Drawable? {
    try {
        // Public API recently introduced in AppCompat.
        return AppCompatResources.getDrawable(this, resId)
    } catch (ex: NoSuchMethodError) {
        try {
            // Private library API so far present in AppCompat at least since 23.4.0.
            return AppCompatDrawableManager.get().getDrawable(context, resId, false);
        } catch (ex: NoSuchMethodError) {
            // Fall back to platform handling.
            return ContextCompat.getDrawable(this, resId)
        }
    }
}

instead of plain

context.resources.getDrawable(...)

(Optimizations welcome.)

@marcosalis
Copy link

+1!
It's a pretty common scenario to need using a vector drawable in some cases instead of a Bitmap. The lack of support means that client code needs to handle this scenario manually, by setting a placeholder image in those cases. And this can be painful when views are recycled in an adapter, because it means you have to constantly reset the correct placeholder when the view is recycled...

@oprisnik oprisnik added enhancement and removed needs-details This issue or PR is currently not actionable as it misses details (e.g. for reproducing the problem) labels Jul 10, 2017
@diegobarle
Copy link

@consp1racy please use ContextCompat to support getDrawable in old android versions:

ContextCompat.getDrawable(context, R.drawable.your_vector_drawable)

@consp1racy
Copy link

@diegobarle For two years I've been doing a whole lot more. Check the code sample again.

You may want to google what's the point of ContextCompat.getDrawable (it doesn't solve anything, it just hides an if-else check), when do you need it, and why you may want to use AppCompatResources.getDrawable instead (backport theme references and vector drawables). For example this SO question: https://stackoverflow.com/questions/43004886/resourcescompat-getdrawable-vs-appcompatresources-getdrawable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants