lottie-android icon indicating copy to clipboard operation
lottie-android copied to clipboard

LottieComposition: Add getHeight & getWidth function to return original dimensions.

Open vanniktech opened this issue 1 year ago • 3 comments
trafficstars

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.

vanniktech avatar Jun 28 '24 13:06 vanniktech

I also thought about that. But then I'd kind of rely on the implementation that's inside Lottie. If that changes for some reason, I'm screwed. iOS also offers to get the original size:

Screenshot 2024-06-29 at 14 01 07

Also after dividing, I'd need to round it (I want the integer value).

vanniktech avatar Jun 29 '24 07:06 vanniktech

Can you divide the returned width/height by Resources.getSystem().getDisplayMetrics().density instead? That's all the scaling is doing.

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.

gpeal avatar Jun 29 '24 15:06 gpeal

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.

vanniktech avatar Jun 30 '24 08:06 vanniktech

Snapshot Tests API 23: Report Diff API 31: Report Diff

github-actions[bot] avatar Jul 02 '24 04:07 github-actions[bot]

Do you also want me to prefix the exposed API with unscaled?

vanniktech avatar Jul 02 '24 07:07 vanniktech

Do you also want me to prefix the exposed API with unscaled?

Yes, please!

gpeal avatar Jul 02 '24 17:07 gpeal

Should be good to go now.

vanniktech avatar Jul 03 '24 02:07 vanniktech

Snapshot Tests API 23: Report Diff API 31: Report Diff

github-actions[bot] avatar Aug 01 '24 18:08 github-actions[bot]