alexjlockwood/avocado

Avocado removes @string paths

FrancoisBlavoet opened this issue · 3 comments

I ran Avocado on this xml :

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:width="108dp"
        android:height="108dp"
        android:viewportHeight="108.0"
        android:viewportWidth="108.0">
    <group
        android:translateX="23"
        android:translateY="23">
        <path
            android:fillColor="#2A7618"
            android:fillType="nonZero"
            android:pathData="@string/ic__core_path_carrot"
            tools:targetApi="n"/>
        <path
            android:fillColor="#2A7618"
            android:fillType="nonZero"
            android:pathData="@string/ic__core_path_carrot_leaves"
            tools:targetApi="n"/>
    </group>
</vector>

Here is the output I got :

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="108dp"
        android:height="108dp"
        android:viewportHeight="108.0"
        android:viewportWidth="108.0"/>

In all fairness, it is smaller, but I did lose a bit of info there :p

Oops, good catch. The tool doesn't know how to optimize string resources yet, but until then it should just ignore them instead of deleting them entirely.

haha, no pb
I just wanted to see if it was going to bake this translation into the path for me and it does 🎉 (as long as it is not a string reference anyway, but that's fair)

For future reference, I need to update the regex string in the removeHiddenElems plugin to detect string resources: https://github.com/alexjlockwood/avocado/blob/master/src/plugins/removeHiddenElems.ts#L4

I also need to update the mergePaths plugin so that it doesn't attempt to concatenate paths that reference string resources: https://github.com/alexjlockwood/avocado/blob/master/src/plugins/mergePaths.ts

Probably worth double checking the convertPathData plugin as well to make sure it isn't making any assumptions about the validity of the path data attribute value: https://github.com/alexjlockwood/avocado/blob/master/src/plugins/convertPathData.ts