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.04k stars 5.41k forks source link

Support load dotlottie for setAnimation(InputStream) #2409

Closed jhen0409 closed 1 year ago

jhen0409 commented 1 year ago

https://github.com/airbnb/lottie-android/blob/4c805889968bfa2eba6c87cd99a093aa5261beb3/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java#L507-L518

Currently it looks like only support json, can we add support for zip?

I'm using this as workaround for now:

val stream = FileInputStream(File(filepath))
val result = LottieCompositionFactory.fromZipStreamSync(ZipInputStream(stream), filepath.hashCode().toString())
val composition = result.value ?: throw IllegalStateException("Unable to parse ${filepath}")
view.setComposition(composition)

Also, change from fromZipStreamSync to fromZipStream can be complex, maybe make view.setCompositionTask public will be better.

gpeal commented 1 year ago

Sorry, I don't understand the question. Can you attach a zip file that isn't working correctly?

thevoiceless commented 1 year ago

I believe the request is to expose a setter on LottieAnimationView that works with zip/.lottie sources. The existing InputStream setter assumes that the stream is backed by json.

jhen0409 commented 1 year ago

File is here: test.lottie.zip

After #1660 we can use .lottie files by check file extension to use zip input stream, but currently the LottieAnimationView.setAnimation(InputStream) cannot detect for that, it only expected the input is JSON. In my case I want to use local dotlottie files.

Do you think use API like PushBackInputStream to check bytes head is good idea, or just add a new API instead?