ShapeShifter icon indicating copy to clipboard operation
ShapeShifter copied to clipboard

trimPathStart of a Path isn't exported in Animated Vector Drawable, possibly causing bugs

Open NinoDLC opened this issue 7 years ago • 0 comments

Context :

  • I have a path with trimPathStart set to 0
  • I animate trimPathStart from 0 to 1
  • (I also animate trimPathEnd from 0 to 1)

Basically, this is a "tick" that animates like a "writing" from left to right, and after a while, animates (disappears) from left to right. Smooth and stylish.

Exported file is :

<animated-vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt"
    >
    <aapt:attr name="android:drawable">
        <vector
            android:name="vector"
            android:width="56dp"
            android:height="56dp"
            android:viewportWidth="56"
            android:viewportHeight="56"
            >
            (...)
            <path
                android:name="tick"
                android:pathData="M 23 18 L 26.8 21.6 L 33.2 15.4"
                android:strokeColor="#ff0088"
                android:strokeWidth="3"
                android:trimPathEnd="0"
                android:strokeLineCap="square"
                />
        </vector>
    </aapt:attr>
    (...)
    <target android:name="tick">
        <aapt:attr name="android:animation">
            <set>
                <objectAnimator
                    android:propertyName="trimPathEnd"
                    android:startOffset="600"
                    android:duration="300"
                    android:valueFrom="0"
                    android:valueTo="1"
                    android:valueType="floatType"
                    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
                    />
                <objectAnimator
                    android:propertyName="trimPathStart"
                    android:startOffset="2300"
                    android:duration="300"
                    android:valueFrom="0"
                    android:valueTo="1"
                    android:valueType="floatType"
                    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
                    />
            </set>
        </aapt:attr>
    </target>
</animated-vector>

You can see the <path "tick" doesn't have trimPathStart set to 0, only trimPathEnd is set.

Bug : If you run this animation once, it works well. But if you run this animation a second time, the tick won't show between the animation of trimPathEnd and trimPathStart.

(Immediate) fix : Adding android:trimPathStart="0" to the <path "tick" fixed the problem

(Suggested) fix : Add trimPathStart (even if set to 0) to <path that have animation about trimPathStart when generating export file

NinoDLC avatar Jan 26 '18 16:01 NinoDLC