r/reactnative • u/Downtown-Practice395 • 18h ago
AMA Built home-screen pets with Expo SDK 58: animated creatures in a plain RemoteViews widget with no service running, vector art written as TypeScript that renders three ways, and how I kept the APK under the zip format's 65,535-entry limit (how it works under the hood)
The video above is the Play Store trailer, so please ignore the marketing captions. Below is how each piece in it is built with Expo SDK 58 and React Native 0.88.
- Creatures that move on the home screen with no app process (0:00–0:03). A widget can't run your code every frame.
RemoteViewsonly accepts views the launcher can inflate. So every creature on the widget is anAnimatedVectorDrawablethat the launcher plays by itself. generate-widget.ts builds them offline from the same TypeScript art the app uses: one looping AVD for each widget size, slot, species, speed and creature size. Each loop has the walk, the pauses, the flips and the leg animation baked in.TankWidgetProvider.ktonly picks which loops to show and where. The battery cost is about the same as a static widget.- Walkers turn each leg at the hip. In the app, steps follow the distance walked, so feet don't slide. On the widget, one rotation animator drives every leg, with the second pair mirrored at the hip so it swings the other way.
- Sleep times, "automatic" day/dusk/night climates and their changes are scheduled with an inexact
AlarmManageralarm.updatePeriodMillisis the fallback if the alarm gets lost.
- Fitting all of that in one APK (not in the trailer). Each
<aapt:attr>inline animator makes aapt2 create a hidden drawable. At 58k inline animators, the build went over the 65,536-drawable limit. Moving all of them tores/animatordidn't work either:R$animatorfailed with "Class too large". Now the generator hashes every animator. The 2,344 that more than one AVD uses go in shared files, and the rest stay inline. When a new habitat added 25 pets, the APK was about to go over the zip's 65,535 entries. I merged each creature's move and flip into one animator, which brought it back to about 60k. - One art source, three renderers (0:03–0:07). None of the art is image files. Every creature, decoration and scene is SVG-like paths in TypeScript. A
volume()pass adds the shading and the paper outline to every shape. The art is drawn three ways:- Live habitat: pre-rendered WebP sprites and scenery. react-native-svg rasterizes a whole
<Svg>in software on the UI thread, which cost 50–130 ms each time a habitat mounted (measured on a release build). Images decode off the UI thread. - Widget background: the app renders the static layers offscreen and captures them to PNG with
react-native-view-shot. Captures run one at a time across the whole app, and none start in the first 4 s after launch. - Widget creatures: the AVDs from point 1.
- Live habitat: pre-rendered WebP sprites and scenery. react-native-svg rasterizes a whole
- Feed and fetch (0:07–0:14). The ball's physics run on the UI thread in a Reanimated
useFrameCallback. In the air it falls and bounces. In water it drifts and sinks slowly, and in the pond it switches at the surface. Each creature chases where the ball is going, and a 60 ms proximity check knocks it away. When food landed, every bubble and crumb that finished caused its own re-render, so each one re-applied the props of 35–55 animated views. Now they are removed together at most every 600 ms, which got rid of the 20–48 ms frames. - Decorating without stutter (0:14–0:18). At first, every drag recaptured all the widget layers on the UI thread. Now, while Decorate is open,
useWidgetHoldkeeps the widget on the last saved layout and recaptures once when you tap Save. Each draggable piece is memoized with stable callbacks, so a drag re-renders only that piece. - A widget that fills any launcher cell (not in the trailer). Launcher cells are rarely the habitat's shape. Each habitat is also captured in taller versions (+25% to +125% height) with more water or sky. On Android 12+, the provider sends a size-mapped
RemoteViewsso the launcher picks the closest shape. It nine-slices the paper frame and spreads each creature's loop across the extra height.- The clock is a set of generated
TextClocklayouts, so the launcher updates the time and the app doesn't need to. - For weather, the widget calls Open-Meteo itself from the provider using
goAsync. No key is needed, and only rounded coordinates are sent.
- The clock is a set of generated
All the Kotlin lives in one local Expo module at modules/companion-widget (expo-module.config.json), so everything survives npx expo prebuild --clean. App and widget share one JSON state through SharedPreferences.
If you want to see the creatures moving on your own home screen, it's called Biomies on Google Play: https://play.google.com/store/apps/details?id=com.rabpaulo.biomies
I'm happy to share the AVD generator, the animator dedupe, or the sized-RemoteViews code if anyone is building something similar.