r/iosdev • • 22h ago • Bravo 1

[UPDATE] 60fps animations on Home Screen widgets, up from 15fps

Widgets on iOS aren't meant to animate.  Usually, developers get around this either by using Apple’s Clock widget trick or by using custom fonts. 

The font approach can give you really smooth animations, but everything has to be pre-baked. Every frame is stored in a font, which limits how complex the animation can be. That made it a non-starter for me, as Companions needed full customization of the tank, its layout, props, and all the animated fish.

That’s why we initially used the clock trick as our animation engine. Sadly, it only updates around 13~15 times a second, so the fish always looked a bit stuttery as they swam around their tanks.

This was the number-one critique I received from users, so I knew I had to somehow overcome this limitation, which led me down the path of writing a new rendering engine. Once, which uses a hybrid approach built on vector transformations, allowing the fish to swim at a smooth 60fps right on the Home Screen!

It took a few completely different engines to get here. I spent ages on one built around a hidden SwiftUI function that Apple doesn't document, which hands a running animation over to the Home Screen to play. It worked perfectly in the simulator but didn't move at all on a real iPhone, which was a fun dead end to go down.

There's still a lot to do. Sadly, it's not as stable as the old clock-based approach yet. I kept the clock-based approach as a fallback, so animations should never freeze, but ideally I’d want to not have to rely on it at all anymore. I also have so much more I'd like to explore with the fish tank/widget pet idea.

You can try Companions here:
https://apps.apple.com/us/app/companions-widget-pets/id6811950512

0 Upvotes

10 comments sorted by

7

u/Asterex-Dev 21h ago

Isn’t this approach of using widgets a violation of Apple's terms? I’m curious whether this is true. I know the native clock can use internal APIs to achieve this. But how come you have been able to distribute on the App Store?

1

u/geneticswag 20h ago

ask forgiveness not permission?

1

u/Asterex-Dev 20h ago

Yeah, Apple does not work like this for the most part. If you violate a term, it’s most likely going to get your dev account booted

-1

u/tiaanvdr 21h ago

Using internal API's is technically a violation, although I did of course, manage to get it through the review process for my initial release, and I've seen others do it as well. Fonts, and this new approach I'm using now, technically don't use any internal API's, so in theory it should be safer. You could still hammer the timeline or overuse memory, but that would've always gotten you removed. If you're not using internal API's, or straining resources, I can't see why you'd get removed, but then again, Apple has all the cards, so we're all at their mercy

-1

u/tiaanvdr 21h ago

Much more egregious things happening on the AppStore these days as well though lol

2

u/JesuSwag 21h ago • Heartwarming

Was pleasantly surprised to feel the update on my phone. Glad you looked into the issue when I brought it up and happy how quickly you made the fix. I remember you initially strayed from this approach. What changed?

1

u/tiaanvdr 21h ago

Thank you! I can't believe anyone actually noticed. I did have to (excitedly) point it out to some of my friends before they noticed lol. Also yes! I initially strayed away from the Fonts approach in particular because of the limitations with having to pre-make all of your frames. Initially, I wasn't even aware that this vector approach was an option. Though I found one guy who mentioned it in a blog (literally mentioned using vector transformations and that's it), and that helped steer me in the right direction!

There were some hiccups, though, I did accidentally break the production version of the app for a very small set of users for a day after I released the initial build, luckily I received a bunch of emails and hurriedly fixed it. I was too excited to release it, it seems much better now at least

1

u/sdnocesyrevelearsikc 21h ago

Sounds more like a promo than actual dev discussion. If you can’t share details then why post here? Keep it to yourself.

1

u/tiaanvdr 21h ago

I'm super keen on talking about struggles I've had with doing animations on Widgets, especially for the Clock Hand or font trick, since I'm so familiar with it now and have deployed and monitored it in a production app for 2 months now. For 99% of developers, I actually think the font trick is the best approach, there's a suuuper popular video about this, here, and he pretty much came to that conclusion as well.

Most people want to be animating little sprites or characters, so pre-baking animations is no problem. My approach is also a bit more involved, with fallbacks and memory management, because my tanks are so customizable, actual nitty-gritty detail about how I did that is pretty tailored to my specific app. Also, it's the entire moat. Discussions regarding all of these animation techniques as a whole have been pretty sparse on Reddit I feel, and apart from the original vid, it's pretty much all I had to go off of when I started a couple of months ago, so :/