It looks like LottieComposition.Factory is deprecated already. I'm wondering how I can define a LottieDrawable? I could not find the documentation for this.
The reason I want a Drawable is because I want to pass a Lottie animation into fresco as a placeholder drawable.
I realise this is an old question, but since I too came against the same problem and managed to find how to do it, might as well share it.
So a LottieCompositionFactory can be used to obtain a LottieComposition from a raw .json file, URL, or assets in the assets folder etc. using the corresponding function as given in the API reference, and then use the composition to assign it to a LottieDrawable.
For example, using a .json file
val animDrawable = LottieDrawable()
LottieCompositionFactory.fromRawRes(requireContext(), R.raw.anim_file).addListener {comp ->
animDrawable.composition = comp
}
Then the drawable can be used anywhere a Drawable can be passed.
the right answer is :
val animDrawable = LottieDrawable()
LottieCompositionFactory.fromRawRes(context, R.raw.loading_banner).addListener { comp ->
animDrawable.composition = comp
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With