WhoBuilt

React Native going Native

Oct 20, 2021· 21 min· 1.2K views·Watch on YouTube

Speaker

Truls Skeie of Kvarn explains how his team moved parts of the Shift workout app from React Native to native code at React Native EU 2021, hosted by Callstack.

How Shift alternates music and podcasts

Shift is a workout app that uses a timer to alternate music during work periods with podcasts during rest periods. Users can listen to Spotify or curated mixtapes, and the app also supports podcast queues and imports. Its workout screen includes timed beeps, spoken alerts, playback controls, and a notification showing the time left and current audio.

Where bridge traffic added complexity

Skeie explains that React Native sends information between JavaScript and native code over a bridge. In Shift, changing audio sources involved several back-and-forth calls to pause one player, start another, and update the interface. Headphone controls, beeps, and notifications also relied on bridge communication.

Moving the timer to native code

Shift’s background workout timer checked its state every second, sent updates to JavaScript for the interface, and switched audio when the countdown reached zero. It also processed data every 15 seconds, including saving podcast position. The team moved the countdown and timer loop to native code, where a main counter and a Shift Master handled display events, notifications, alerts, automatic switching, and audio players.

What changed and when to consider it

Skeie says the native rewrite made the freeze and unfreeze logic simpler to read and easier to debug. The team made the change after three years of maintaining the app, when it understood where the code was hard to reason about. He cautions that native code means maintaining platform-specific features, and says Shift had performed well before the rewrite.

Starting with native development

Skeie suggests moving a small problem to native code first, then learning from the experience before expanding the approach. He also recommends reading how React Native packages structure their bridge code and using available resources to learn native interfaces and platform development. He says that understanding native platforms improved his React Native skills.

Takeaways

  • Consider moving a feature to native code when bridge traffic makes it hard to reason about, and weigh the ongoing platform-specific maintenance.
  • Measure the actual app experience before assuming frequent bridge calls are causing poor performance.
  • For background timers, keeping countdown logic native can reduce the need for per-second updates to JavaScript.
  • Start learning native development with a small, well-understood problem and inspect how existing React Native packages work.
  • Revisit architecture after gaining years of experience with the code and its recurring sources of bugs.

Mentioned in this talk

Search inside this talk

What was claimed 10

Show all 10 facts

Related talks