react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Android] Vector images from native resources is not working

Open yonatanganot opened this issue 6 years ago • 17 comments

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 avatar Dec 13 '19 10:12 yonatanganot

Mentioned in #16651 also.

yonatanganot avatar Dec 28 '19 22:12 yonatanganot

Having the same issue, unfortunately

crazyjooe avatar Feb 07 '20 13:02 crazyjooe

same issue here

xelven avatar Apr 14 '20 11:04 xelven

the same

Omelyan avatar Apr 21 '20 17:04 Omelyan

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[bot] avatar Jul 20 '20 18:07 stale[bot]

still exist in version 0.63.1

yonatanganot avatar Jul 21 '20 07:07 yonatanganot

and the same issue for me

valin0k avatar Sep 30 '20 17:09 valin0k

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

aprilmintacpineda avatar Oct 22 '20 15:10 aprilmintacpineda

I solved it, creating any other container for example Linear Layout and putting svg as background <LinearLayout android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_centerInParent = "true" android: background = "@ drawable / ic_splash_icon" android: orientation = "horizontal"> </LinearLayout> and works fine. image

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

lrlineroa avatar Jul 25 '21 18:07 lrlineroa

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

mattmcdev avatar Apr 29 '22 14:04 mattmcdev

Same issue in 0.69.8

ghost avatar Mar 10 '23 23:03 ghost

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[bot] avatar Sep 07 '23 05:09 github-actions[bot]

The issue still exists in version 0.72.4

yonatanganot avatar Sep 07 '23 20:09 yonatanganot

Same issue here unfortunately. Will this ever be supported?

SamuelBrucksch avatar Oct 28 '23 17:10 SamuelBrucksch

Also seeing this issue

andrewli-eb avatar Dec 09 '23 00:12 andrewli-eb

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[bot] avatar Jun 06 '24 05:06 github-actions[bot]

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

github-actions[bot] avatar Jun 13 '24 05:06 github-actions[bot]

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.

Abbondanzo avatar Jul 15 '24 16:07 Abbondanzo