airbnb / lottie-android

Render After Effects animations natively on Android and iOS, Web, and React Native
http://airbnb.io/lottie/
Apache License 2.0
35.01k stars 5.41k forks source link

Support radial gradient highlights #2524

Open piusyikyu opened 3 months ago

piusyikyu commented 3 months ago

Is your feature request related to a problem? Please describe. Radial gradient hightlight is supported in both iOS and web.

Describe the solution you'd like Support highlight in Android.

Describe alternatives you've considered Stacking arbitary number of circles and apply a mask. Not ideal.

Additional context

I have some suggestion on how to implement this on Android.

Concept

The image below is the concept of what 'hightlight' is in lottie. This feature is conventionally known as the focus or the focal point of a radial gradient instead. There are two parameters in lottie for this:

radial gradient with highlight (commented)

Consider a point A lying on somewhere inside the circle defined by start and end in the lottie format. The colour stop at point A is the ratio of the distance between A and the focus to the project of A from the focal point to the circumference of the such circle. The figure below should give a good illustration, the ratio of $L:L'$ should be used to interpolate the colour at the location.

radial gradient with highlight (calc)


Implementation suggestion

MyApplication.zip

I created a sample kotlin project to show case the calculations shown above using min sdk 16 and java 17 like your repo setup.

For Android 12+, you can migrate your use of RadialGradient (here) to the new API and all will be fine.

For sdks below that, I created a custom BitmapShader to simulate the calculation and painted in onto a custom view on a JellyBean emulator. The goal is to show it can achieve the required render, so I did not optimise for performance. Below are some screenshots for your reference.

Android 4.2 image

Android 14 image


Housekeeping

gpeal commented 3 months ago

Thanks for the detailed write up!