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

Optimized vector drawable doesnt match source #46

Open
AlecKazakova opened this issue Apr 29, 2020 · 1 comment
Open

Optimized vector drawable doesnt match source #46

AlecKazakova opened this issue Apr 29, 2020 · 1 comment

Comments

@AlecKazakova
Copy link

Heres the input:

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

  <group>
    <clip-path android:pathData="M24 0H120C133.255 0 144 10.7452 144 24V136C144 149.255 133.255 160 120 160H24C10.7452 160 0 149.255 0 136V24C0 10.7452 10.7452 0 24 0Z" />

    <group
        android:pivotX="72"
        android:pivotY="80"
        android:rotation="90"
        android:scaleX="2"
        android:scaleY="2"
        android:translateX="1"
        android:translateY="0">

      <path android:pathData="M0 0V160H144V0">

        <aapt:attr name="android:fillColor">

          <gradient
              android:endX="108"
              android:endY="80"
              android:startX="36"
              android:startY="80"
              android:type="linear">

            <item
                android:color="#FFFFFF"
                android:offset="0" />

            <item
                android:color="#00FFFFFF"
                android:offset="1" />

          </gradient>
        </aapt:attr>
      </path>
    </group>
  </group>
</vector>

when run the optimizer loses the rotation

@alexjlockwood
Copy link
Owner

Hmmm..... I will have to think about how to best go about fixing this.

Essentially the problem is that avocado is baking <group> transforms into the <path>, but is not taking the gradient coordinates into account. I messed around for a while here but wasn't able to figure out the fix yet. To be completely honest I haven't looked at this code in a while and I forget how Android draws gradients. I will have to look more into this and figure out how exactly the gradient coordinates need to be transformed...

A temporary workaround could be to add android:name="whatever_you_want" to the <group> tag that has the transform properties. avocado won't optimize groups with android:names (since it usually means that their properties are being animated with an AVD). So if you do that, it will bypass the "bake-transforms-into-paths" behavior that is causing the bug.

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

No branches or pull requests

2 participants