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

Abbondanzo added a commit to Abbondanzo/react-native that referenced this issue Jul 9, 2024
Summary:
Fresco has indicated that they have no plans to support loading vector assets and similar drawable types in Drawee-backed views ([issue](facebook/fresco#329), [issue](facebook/fresco#1463), [issue](facebook/fresco#2463)). Guidance has been to instead load the vector drawable onto the backing image view ourselves. On the React Native side, having the ability to load vector drawables has been requested many times ([issue](facebook#16651), [issue](facebook#27502)).

I went this route over using a custom Fresco decoder for XML assets because vector drawables are compiled down into binary XML and I couldn't find a trivial, performant way to parse those files in a context-aware manner. This change only accounts for vector drawables, not any of the other XML-based drawable types (layer lists, level lists, state lists, 9-patch, etc.). Support could be added easily in the future by expanding the `getDrawableIfUnsupported` function.

## Changelog

[Android] [Added] - Added support for rendering XML assets provide to `Image`

Differential Revision: D59530172
Abbondanzo added a commit to Abbondanzo/react-native that referenced this issue Jul 10, 2024
Summary:
Pull Request resolved: facebook#45354

Fresco has indicated that they have no plans to support loading vector assets and similar drawable types in Drawee-backed views ([issue](facebook/fresco#329), [issue](facebook/fresco#1463), [issue](facebook/fresco#2463)). Guidance has been to instead load the vector drawable onto the backing image view ourselves. On the React Native side, having the ability to load vector drawables has been requested many times ([issue](facebook#16651), [issue](facebook#27502)).

I went this route over using a custom Fresco decoder for XML assets because vector drawables are compiled down into binary XML and I couldn't find a trivial, performant way to parse those files in a context-aware manner. This change only accounts for vector drawables, not any of the other XML-based drawable types (layer lists, level lists, state lists, 9-patch, etc.). Support could be added easily in the future by expanding the `getDrawableIfUnsupported` function.

## Changelog

[Android] [Added] - Added support for rendering XML assets provided to `Image`

Differential Revision: D59530172
Abbondanzo added a commit to Abbondanzo/react-native that referenced this issue Jul 12, 2024
Summary:
Pull Request resolved: facebook#45354

Fresco has indicated that they have no plans to support loading vector assets and similar drawable types in Drawee-backed views ([issue](facebook/fresco#329), [issue](facebook/fresco#1463), [issue](facebook/fresco#2463)). Guidance has been to instead load the vector drawable onto the backing image view ourselves. On the React Native side, having the ability to load vector drawables has been requested many times ([issue](facebook#16651), [issue](facebook#27502)).

I went this route over using a custom Fresco decoder for XML assets because vector drawables are compiled down into binary XML and I couldn't find a trivial, performant way to parse those files in a context-aware manner. This change only accounts for vector drawables, not any of the other XML-based drawable types (layer lists, level lists, state lists, 9-patch, etc.). Support could be added easily in the future by expanding the `getDrawableIfUnsupported` function.

## Changelog

[Android] [Added] - Added support for rendering XML assets provided to `Image`

Reviewed By: javache

Differential Revision: D59530172
Abbondanzo added a commit to Abbondanzo/react-native that referenced this issue Jul 12, 2024
Summary:
Fresco has indicated that they have no plans to support loading vector assets and similar drawable types in Drawee-backed views ([issue](facebook/fresco#329), [issue](facebook/fresco#1463), [issue](facebook/fresco#2463)). Guidance has been to instead load the vector drawable onto the backing image view ourselves. On the React Native side, having the ability to load vector drawables has been requested many times ([issue](facebook#16651), [issue](facebook#27502)).

I went this route over using a custom Fresco decoder for XML assets because vector drawables are compiled down into binary XML and I couldn't find a trivial, performant way to parse those files in a context-aware manner. This change only accounts for vector drawables, not any of the other XML-based drawable types (layer lists, level lists, state lists, 9-patch, etc.). Support could be added easily in the future by expanding the `getDrawableIfUnsupported` function.

## Changelog

[Android] [Added] - Added support for rendering XML assets provide to `Image`

Differential Revision: D59530172
Abbondanzo added a commit to Abbondanzo/react-native that referenced this issue Jul 12, 2024
Summary:
Pull Request resolved: facebook#45354

Fresco has indicated that they have no plans to support loading vector assets and similar drawable types in Drawee-backed views ([issue](facebook/fresco#329), [issue](facebook/fresco#1463), [issue](facebook/fresco#2463)). Guidance has been to instead load the vector drawable onto the backing image view ourselves. On the React Native side, having the ability to load vector drawables has been requested many times ([issue](facebook#16651), [issue](facebook#27502)).

I went this route over using a custom Fresco decoder for XML assets because vector drawables are compiled down into binary XML and I couldn't find a trivial, performant way to parse those files in a context-aware manner. This change only accounts for vector drawables, not any of the other XML-based drawable types (layer lists, level lists, state lists, 9-patch, etc.). Support could be added easily in the future by expanding the `getDrawableIfUnsupported` function.

## Changelog

[Android] [Added] - Added support for rendering XML assets provided to `Image`

Reviewed By: javache

Differential Revision: D59530172
Abbondanzo added a commit to Abbondanzo/react-native that referenced this issue Jul 12, 2024
Summary:
Fresco has indicated that they have no plans to support loading vector assets and similar drawable types in Drawee-backed views ([issue](facebook/fresco#329), [issue](facebook/fresco#1463), [issue](facebook/fresco#2463)). Guidance has been to instead load the vector drawable onto the backing image view ourselves. On the React Native side, having the ability to load vector drawables has been requested many times ([issue](facebook#16651), [issue](facebook#27502)).

I went this route over using a custom Fresco decoder for XML assets because vector drawables are compiled down into binary XML and I couldn't find a trivial, performant way to parse those files in a context-aware manner. This change only accounts for vector drawables, not any of the other XML-based drawable types (layer lists, level lists, state lists, 9-patch, etc.). Support could be added easily in the future by expanding the `getDrawableIfUnsupported` function.

## Changelog

[Android] [Added] - Added support for rendering XML assets provide to `Image`

Differential Revision: D59530172
Abbondanzo added a commit to Abbondanzo/react-native that referenced this issue Jul 12, 2024
Summary:
Pull Request resolved: facebook#45354

Fresco has indicated that they have no plans to support loading vector assets and similar drawable types in Drawee-backed views ([issue](facebook/fresco#329), [issue](facebook/fresco#1463), [issue](facebook/fresco#2463)). Guidance has been to instead load the vector drawable onto the backing image view ourselves. On the React Native side, having the ability to load vector drawables has been requested many times ([issue](facebook#16651), [issue](facebook#27502)).

I went this route over using a custom Fresco decoder for XML assets because vector drawables are compiled down into binary XML and I couldn't find a trivial, performant way to parse those files in a context-aware manner. This change only accounts for vector drawables, not any of the other XML-based drawable types (layer lists, level lists, state lists, 9-patch, etc.). Support could be added easily in the future by expanding the `getDrawableIfUnsupported` function.

## Changelog

[Android] [Added] - Added support for rendering XML assets provided to `Image`

Reviewed By: javache

Differential Revision: D59530172
Abbondanzo added a commit to Abbondanzo/react-native that referenced this issue Jul 12, 2024
Summary:
Fresco has indicated that they have no plans to support loading vector assets and similar drawable types in Drawee-backed views ([issue](facebook/fresco#329), [issue](facebook/fresco#1463), [issue](facebook/fresco#2463)). Guidance has been to instead load the vector drawable onto the backing image view ourselves. On the React Native side, having the ability to load vector drawables has been requested many times ([issue](facebook#16651), [issue](facebook#27502)).

I went this route over using a custom Fresco decoder for XML assets because vector drawables are compiled down into binary XML and I couldn't find a trivial, performant way to parse those files in a context-aware manner. This change only accounts for vector drawables, not any of the other XML-based drawable types (layer lists, level lists, state lists, 9-patch, etc.). Support could be added easily in the future by expanding the `getDrawableIfUnsupported` function.

## Changelog

[Android] [Added] - Added support for rendering XML assets provide to `Image`

Differential Revision: D59530172
facebook-github-bot pushed a commit to facebook/react-native that referenced this issue Jul 15, 2024
Summary:
Pull Request resolved: #45354

Fresco has indicated that they have no plans to support loading vector assets and similar drawable types in Drawee-backed views ([issue](facebook/fresco#329), [issue](facebook/fresco#1463), [issue](facebook/fresco#2463)). Guidance has been to instead load the vector drawable onto the backing image view ourselves. On the React Native side, having the ability to load vector drawables has been requested many times ([issue](#16651), [issue](#27502)).

I went this route over using a custom Fresco decoder for XML assets because vector drawables are compiled down into binary XML and I couldn't find a trivial, performant way to parse those files in a context-aware manner. This change only accounts for vector drawables, not any of the other XML-based drawable types (layer lists, level lists, state lists, 9-patch, etc.). Support could be added easily in the future by expanding the `getDrawableIfUnsupported` function.

## Changelog

[Android] [Added] - Added support for rendering XML assets provided to `Image`

Reviewed By: javache

Differential Revision: D59530172

fbshipit-source-id: 3d427c06238287e0a3b7f9570ac20e43d76126c7
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