SolveSoul / lottie-android-colorfilter-sample

This repository showcases how to add a color filter to a Lottie animation on Android
22 stars 4 forks source link

Question: ColorFilter vs Lottie's color filter #1

Open AndroidDeveloperLB opened 5 years ago

AndroidDeveloperLB commented 5 years ago

On some Android views (ImageView for example), we can set a ColorFilter: https://medium.com/over-engineering/manipulating-images-and-drawables-with-androids-colorfilter-25bf061843e7 https://developer.android.com/reference/android/graphics/ColorFilter

On some cases we can even use tinting.

But we can do the same on Lottie, using its own API :

LottieAnimationView animationView = findViewById(R.id.animation_view);
animationView.addValueCallback(
        new KeyPath("**"),
        LottieProperty.COLOR_FILTER,
        new SimpleLottieValueCallback<ColorFilter>() {
            @Override
            public ColorFilter getValue(LottieFrameInfo<ColorFilter> frameInfo) {
                return new PorterDuffColorFilter(Color.GREEN, PorterDuff.Mode.SRC_ATOP);
            }
        }
);

Is there any difference between those , maybe in terms of performance? It's just that the Lottie's way is much longer...

SolveSoul commented 5 years ago

Good question, I'm not sure myself actually. I just based this code upon the samples provided by the Lottie team.

Possibly, the Lottie library is "smarter" in the sense that it is aware of the JSON file that represents the animation and that it can manipulate the data rather than the actual drawables/views being created. But that is just speculation on my end.

I'll leave the issue open for discussion so maybe someone can bump in and enlighten us all 😉