Shopify Apr 16, 2021

Management of Native Code and React Native at Shopify

Article Summary

Shopify went all-in on React Native, but quickly learned that sometimes you need to break the rules. Here's when they write native code anyway.

A year after betting on React Native, Shopify's mobile team shares hard-won lessons about when JavaScript isn't enough. They tackled complex UI performance and background job issues in their Point of Sale app.

Key Takeaways

Critical Insight

Shopify keeps UI in React Native even for complex views, but moved heavy background processing to Kotlin Multiplatform for massive performance gains.

The article includes detailed setup instructions for adding Kotlin Multiplatform to your React Native project without starting from scratch.

About This Article

Problem

Shopify's React Native app would freeze during background sync. The issue was that JavaScript runs on a single thread, and when native libraries tried to handle network requests and database work through the bridge, it blocked the UI.

Solution

Colin Gray's team built a job manager using Kotlin Multiplatform Module (KMM). This gave them access to native threading on both platforms and let them share 95% of the code between Android and iOS.

Impact

The new sync manager cut initial synchronization time from over 30 seconds down to 2-3 seconds for medium-sized stores. They kept the architecture clean with just 348 lines of platform-specific code.