-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a pluggable JSON parsing module #3
Comments
This is gonna require a fair amount of work to decouple |
@subtleGradient suggested using FlatBuffer. Tracking progress here. |
@felipecsl That sounds like a good plan. Having better scope protection is also definitely good. |
Alright, I'll start going down this path then :) |
K p |
@felipecsl did you start this? If not I'd like to contribute. I think the core of this is that a composition should be constructable via some conventional way (maybe a builder?). The default could basically be the current JSONObject implementations, with maybe some batteries-included optional artifacts that do it with gson/moshi/etc. |
@hzsweers nope, I was waiting for @gpeal to finish some major JSON parsing refactoring that he had underway. AFAIK the plan was to move the current implementation to a streaming |
@felipecsl @hzsweers I spent quite a long time working on the JsonReader refactor which would have been a good end-all solution to this since it's strictly n time. However, there were some issues with the way the json was formatted that made it almost impossible to do proper parsing when only reading the json beginning to end linearly. Here is my WIP if you're interested: d7227b3 I synced up with Hernan on bodymovin about it and he made a few changes to the json that would make it more feasible: I want to give it another try but it would break compatibility with older versions so maybe splitting json parsing into a module and using the new one if you have a new animation would be a good idea and then we can drop support for older versions eventually. @felipecsl Do you want to take another stab at this? |
For reference, the longest and most complex json file, LottieLogo2.json (90kb) takes about 30ms to parse. |
sounds good |
This is part of issue #3. Pulled static factory methods out of LottieComposition into a static inner class. Made all fields final and initialized them all in the constructor. This will make it easier for follow up refactors where we'll modularize the parsing logic and make it pluggable. Also upgraded the Espresso tests to JUnit 4 so it no longer uses the deprecated ActivityInstrumentationTestCase2
Another change for #3 Pretty mechanical and straightforward change. Extracted a bunch of constructors into more static inner factory classes with a newInstance method by convention. Later on we can pull out all these factories into a separate module that provides the default json parsing implementation.
This was a bit more involved as the JSON parsing in Keyframe and AnimatableValue classes is a lot more involved. Part of #3
Few days ago there was JSON spec created for bodymovin, and I'm working on bringing it to JSON Schema — so it'll be possible in the future autogenerate parser source code. |
In this pass I've converted BaseAnimatableValue and its subclasses. Created a AnimatableValueParser with the common logic to all subclasses. This change caused a "chicken and egg" problem where the AnimatableValueParser calls into Keyframe.Factory.parseKeyframes, which needs the respective instance of BaseAnimatableValue. This caused a circular dependency issue. I've resolved by moving AnimatableValue#valueFromObject() into a separate interface called AnimatableValue.Factory which contains only that method. I think almost all the relevant classes have been refactored by now. Part of #3
Alright let me explain the rest of the changes I have in mind for this issue so I can get input from you guys before sending the PR: Lottie lottie = new Lotite.Builder()
.converter(new DefaultJsonConverter())
.build() Then, we'd need to use this animationView.setAnimation(lottie, "hello-world.json"); We'd also move the current
Finally, the different compile 'com.airbnb.android:lottie-converter-default:version' The What do you guys think? |
Looks good to me; but it's still unclear how will you manage model and logic separation. Also, it's interesting, whether it's possible to parse JSON with databinding; and to provide model automatically from JSON Schema. I wish I had enough time to contribute lot of stuff here |
our model classes are still somewhat coupled to the JSON structure, but over time we should decouple them as much as possible in a way that makes us input format agnostic. All you need is a converter that takes an |
There is any advantage to use this new A This will help when instantiating |
@felipecsl I like the overall approach. What do you think about Lottie including the default parser as a transitive dependency so that a) LottieAnimationView can create the default one and b) users don't have to add a second dependency especially when, as of now, there is only one option |
@gpeal that's not possible because it would cause a circular dependency. |
@felipecsl The idea was to have a new constructor with |
@fabionuno Adding View constructors is pretty unconventional. We could also add something like what RV does with LayoutManager: https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html#attr_android.support.v7.recyclerview:layoutManager |
Should we close this issue? Not sure we're still planning to do anything else for this. |
@felipecsl Let's close this for now. |
Ideally there would be 2 (or n) optional json parsing modules.
1 would use raw json objects so there would be no transitive dependencies
The other would use jackson or another more performant json parsing library.
The text was updated successfully, but these errors were encountered: