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

[Android] Vector images from native resources is not working #27502

Open
yonatanganot opened this issue Dec 13, 2019 · 18 comments
Open

[Android] Vector images from native resources is not working #27502

yonatanganot opened this issue Dec 13, 2019 · 18 comments
Labels
Bug Component: Image Never gets stale Prevent those issues and PRs from getting stale Platform: Android Android applications.

Comments

@yonatanganot
Copy link

Based on React Native documentation, we should be able to fetch images from native resources.
This is works great on iOS, but in Android you can't load vector images using uri.

React Native version:

react-native: 0.61.5

Steps To Reproduce

Placing vector image named image.xml in drawable folder and using this code, is not working:
<Image width={100} height={100} source={{ uri: 'image' }} style={{ width: 100, height: 100 }} />

Placing the vector image in assets folder and using this code, is not working either:
<Image width={100} height={100} source={{ uri: 'asset:/image.xml' }} style={{ width: 100, height: 100 }} />

Note that placing .jpg or .png images is working without any issues.

@yonatanganot
Copy link
Author

Mentioned in #16651 also.

@crazyjooe
Copy link

Having the same issue, unfortunately

@xelven
Copy link

xelven commented Apr 14, 2020

same issue here

@Omelyan
Copy link

Omelyan commented Apr 21, 2020

the same

@stale
Copy link

stale bot commented Jul 20, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jul 20, 2020
@yonatanganot
Copy link
Author

still exist in version 0.63.1

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Jul 21, 2020
@valin0k
Copy link

valin0k commented Sep 30, 2020

and the same issue for me

@aprilmintacpineda
Copy link

aprilmintacpineda commented Oct 22, 2020

I'm getting the same effect on my end, in my case, I was implementing a splash screen with https://github.com/crazycodeboy/react-native-splash-screen, here's launch_screen.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#5C4FA0"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/LaunchLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="150dp"
        android:contentDescription="@string/LaunchLogoContentDescription"
        android:minWidth="50dp"
        android:minHeight="50dp"
        app:srcCompat="@drawable/ic_circle_with_wallet" />

    <TextView
        android:id="@+id/AppName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="310dp"
        android:fontFamily="sans-serif-black"
        android:text="@string/app_name"
        android:textColor="#fff"
        android:textSize="36sp" />
</RelativeLayout>

I'm doing this via Layout editor on Android studio, in there, it's displaying the image, but when I run the app, the image is not being displayed. I don't get any errors whatsoever, after about an hour of googling around, I found people talking about extending AppCompatActivity (haven't tried doing that because MainActivity is already extending ReactActivity) etc., some even recommended using android.support.v7.widget.AppCompatImageView which doesn't work

https://stackoverflow.com/questions/38221986/android-vector-drawable-appsrccompat-not-showing-images

@lrlineroa
Copy link

I solved it, creating any other container for example Linear Layout and putting svg as background


and works fine.
image

I´m using react-native-splash-screen for the splash flow

@mattmcdonald-uk
Copy link

This issue still exists in 0.68 (the originally reported issue, unrelated to splash screens).

@cjimenezst
Copy link

Same issue in 0.69.8

@github-actions
Copy link

github-actions bot commented Sep 7, 2023

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Sep 7, 2023
@yonatanganot
Copy link
Author

The issue still exists in version 0.72.4

@github-actions github-actions bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Sep 8, 2023
@SamuelBrucksch
Copy link

Same issue here unfortunately. Will this ever be supported?

@andrewli-eb
Copy link

Also seeing this issue

Copy link

github-actions bot commented Jun 6, 2024

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jun 6, 2024
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 13, 2024
@Abbondanzo Abbondanzo reopened this Jul 9, 2024
@Abbondanzo Abbondanzo added Never gets stale Prevent those issues and PRs from getting stale and removed Stale There has been a lack of activity on this issue and it may be closed soon. labels Jul 9, 2024
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 Abbondanzo linked a pull request Jul 10, 2024 that will close this issue
Abbondanzo added a commit to Abbondanzo/react-native that referenced this issue Jul 11, 2024
Summary:
Changelog: [Internal]

The current `Image` implementation does not support loading [vector drawables](https://developer.android.com/develop/ui/views/graphics/vector-drawable-resources) on Android, and support has been requested many times ([issue](facebook#16651), [issue](facebook#27502)). I am proposing to put support behind this feature flag in order to validate against performance regressions. Adding support will require reading files from disk to determine if the resource is actually an XML file.

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

Changelog: [Internal]

The current `Image` implementation does not support loading [vector drawables](https://developer.android.com/develop/ui/views/graphics/vector-drawable-resources) on Android, and support has been requested many times ([issue](facebook#16651), [issue](facebook#27502)). I am proposing to put support behind this feature flag in order to validate against performance regressions. Adding support will require reading files from disk to determine if the resource is actually an XML file.

Differential Revision: D59647903
facebook-github-bot pushed a commit that referenced this issue Jul 12, 2024
Summary:
Pull Request resolved: #45394

Changelog: [Internal]

The current `Image` implementation does not support loading [vector drawables](https://developer.android.com/develop/ui/views/graphics/vector-drawable-resources) on Android, and support has been requested many times ([issue](#16651), [issue](#27502)). I am proposing to put support behind this feature flag in order to validate against performance regressions. Adding support will require reading files from disk to determine if the resource is actually an XML file.

Reviewed By: cortinico

Differential Revision: D59647903

fbshipit-source-id: 2445d71b6769266abe4c2dda521cc2be89bf4064
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 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
@Abbondanzo
Copy link
Contributor

Abbondanzo commented Jul 15, 2024

Support for loading vector drawables has just landed in #45354. It's currently sitting behind a feature flag called loadVectorDrawablesOnImages while we investigate performance implications of parsing every local image resource. If all goes well and there aren't any regressive behaviors from this change, I'm going to try and get this out in 0.76.0.

Separately, I'm also working on adding Metro support so you can import vector drawable images same as you would any other image by import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Component: Image Never gets stale Prevent those issues and PRs from getting stale Platform: Android Android applications.
Projects
None yet
Development

Successfully merging a pull request may close this issue.