-
-
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
LottieComposition: Add getUnscaledHeight & getUnscaledWidth functions. #2514
LottieComposition: Add getUnscaledHeight & getUnscaledWidth functions. #2514
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you divide the returned width/height by Resources.getSystem().getDisplayMetrics().density
instead? That's all the scaling is doing.
@@ -107,7 +107,7 @@ public static LottieComposition parse(JsonReader reader) throws IOException { | |||
Rect bounds = new Rect(0, 0, scaledWidth, scaledHeight); | |||
|
|||
composition.init(bounds, startFrame, endFrame, frameRate, layers, layerMap, precomps, | |||
images, Utils.dpScale(), characters, fonts, markers); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I do pass the unscaled width & height here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make the names very clearly named unscaledWidth
and unscaledHeight
?
The implementation of that definitely won't change. I'd like to keep the API surface area of Lottie as small as possible. If the difference here really is dividing by that number, I would prefer not to add it to the core library. |
The difference is by dividing that number and needing to round it which may yield 399 instead of the original 400 depending on the scale and the rounding mode. It's really not a lot that is added to the API surface, has parity with the iOS implementation and yields something that is part of the format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean with regards to potentially being off by one due to multiplying a rounded value.
Depending on your use case, you could create a JsonReader for the same animation file and read the h
and h
top-level properties yourself.
We can add this to the core library but let's make the API naming very explicit.
@@ -107,7 +107,7 @@ public static LottieComposition parse(JsonReader reader) throws IOException { | |||
Rect bounds = new Rect(0, 0, scaledWidth, scaledHeight); | |||
|
|||
composition.init(bounds, startFrame, endFrame, frameRate, layers, layerMap, precomps, | |||
images, Utils.dpScale(), characters, fonts, markers); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make the names very clearly named unscaledWidth
and unscaledHeight
?
a08adc3
to
dc5fbda
Compare
Do you also want me to prefix the exposed API with |
Yes, please! |
dc5fbda
to
86a2bad
Compare
86a2bad
to
79520d3
Compare
Should be good to go now. |
Use case: I just want to know the unscaled original height / width of the LottieAnimation. I want to do my own scaling by calculating for instance given an aspect ratio or weighted settings, how big/small I can stretch the animation.