Mobile EngineeringVol. 22 · Mobile
0 / 0

Shelves / Mobile Engineering

MB·03

Cross-Platform Frameworks

Sharing code between Android and iOS without paying for it later: how React Native works (JavaScript with native views, the New Architecture's JSI, Fabric and TurboModules, Hermes, Expo), how Flutter works (Dart, its own rendering engine, widgets, platform channels and FFI), how Kotlin Multiplatform shares logic with native or Compose Multiplatform UI, where progressive web apps fit, and how to choose; with a lab measuring why the old JavaScript–native bridge was slow and how in-process calls and batching change it.

15 topics · ~8 min read · 16-question quiz
Updated Suggest a correction

Start here: one codebase, two platforms, three trade-offs

Building every feature twice (Kotlin and Swift) doubles the work, and the two apps drift apart. Cross-platform frameworks share code, but every approach chooses where the shared/native boundary sits, and crossing that boundary has costs:

Approach What's shared UI Boundary
React Native JavaScript/TypeScript app code native platform views JS ↔ native
Flutter Dart app code and the UI itself Flutter's own renderer draws every pixel Dart ↔ platform APIs
Kotlin Multiplatform (KMP) business logic, data, networking (Kotlin) native (Compose, SwiftUI) or shared Compose Multiplatform shared Kotlin ↔ Swift
PWA / web in a shell everything (web) HTML/CSS in a web view or browser web ↔ device APIs

Measured: the cost of crossing the boundary

React Native's original bridge sent every call between JavaScript and native code as a serialised JSON message across threads, asynchronously. The New Architecture replaced it with JSI: direct, in-process calls. The lab measured the same "get position" call three ways (in Node, as an analogy):

Call style Cost per call
direct in-process call (like JSI, Flutter FFI, KMP's shared code) 0.23 µs
serialise to JSON, hop to another thread, deserialise, reply (the old bridge) 34.7 µs (150×)
the same, batching 100 calls per message 1.17 µs

One frame (16.7 ms) fits ~480 unbatched bridge calls: a gesture handler or a list sending a few hundred messages per frame was enough to stutter. Direct calls and batching are why modern cross-platform apps can feel native.

How deep to go

Volume 17 defines six mastery levels. For cross-platform:

Level What you can do
L1 Describe the main approaches and their boundaries
L2 Build an app with one framework, including a native module
L3 Explain rendering pipelines, threading and boundary costs per framework
L4 Diagnose cross-boundary performance problems, memory issues and platform inconsistencies
L5 Choose an approach for a product and team, and design the native/shared split
L6 Run it for years: framework upgrades, native dependencies, OS changes

React Native

  • App code in TypeScript/JavaScript with React; the framework renders real native views.
  • New Architecture (the default in current releases): JSI lets JavaScript hold references to C++ objects and call them directly; Fabric is the new renderer (concurrent React features, synchronous layout when needed); TurboModules load native modules lazily and call them through JSI; Codegen generates typed bindings from TypeScript specs.
  • Hermes: the JavaScript engine shipped with React Native, compiling JS to bytecode ahead of time for faster startup and lower memory.
  • Expo: the recommended way to start; prebuilt native modules, cloud builds, config plugins, and over-the-air updates for JavaScript (within store rules).
  • Strengths: React skills transfer from the web (Volume 2); native look; large ecosystem. Watch: native module quality, upgrade effort, and keeping heavy work off the JS thread.

Flutter

  • App code in Dart; the UI is a tree of widgets rebuilt from state (like Compose and SwiftUI), drawn by Flutter's own engine (Impeller) onto a surface.
  • Platform channels (asynchronous messages) and FFI (direct calls into C) reach device APIs; plugins wrap them.
  • Dart compiles ahead of time to native code for release builds and supports hot reload in development.
  • Strengths: consistent pixels on every platform, smooth animations, one UI codebase also for web and desktop. Watch: app size, platform-convention fidelity, accessibility testing, and plugin maintenance.

Kotlin Multiplatform

  • Share Kotlin code (domain logic, repositories, networking with Ktor, persistence with SQLDelight, serialisation) compiled to JVM for Android and to native frameworks for iOS; use expect/actual declarations for platform-specific pieces.
  • UI stays native (Compose on Android, SwiftUI on iOS), or is shared with Compose Multiplatform, whose iOS support became stable in 2025.
  • Strengths: incremental adoption in existing native apps, native UI, one implementation of business rules. Watch: Swift interop ergonomics (improving with Swift export), build times, and iOS developers' comfort with Kotlin.

Progressive web apps and web shells

  • A PWA (Volume 2, chapter 29) can be installed to the home screen, work offline with service workers, and receive web push (on iOS since 16.4, for installed web apps). Good for content, ordering and account management.
  • Capacitor and similar shells wrap a web app in a native container with plugins for device APIs and store distribution.
  • Limits: background execution, some device APIs, and performance of complex, gesture-heavy UI.

Choosing

If… Lean towards
the team is mostly web/React developers and UI should feel native React Native (with Expo)
custom, highly animated, brand-consistent UI across platforms (and maybe web/desktop) Flutter
existing native apps; share logic without rewriting UI Kotlin Multiplatform
mostly content and forms; web reach matters most PWA
deep platform integration, top performance, separate expert teams fully native

Whatever you choose, budget for native code: payments, push, background location, camera and platform features always need some.

TiffinBox's choice

TiffinBox's customer app is forms, lists, a live map and notifications; the team has strong React and Kotlin skills. Two defensible choices: React Native with Expo (shared UI, native views, web skills), or native UI with Kotlin Multiplatform for the subscription rules, sync engine (chapter 05) and API client. The project (chapter 10) uses KMP for shared logic with native UIs, and asks you to write the ADR for the alternative.

Common traps

  • Heavy work on the JavaScript or Dart UI thread.
  • Chatty boundaries: many small cross-boundary calls per frame instead of batched or direct ones.
  • Abandoned plugins for critical features.
  • Assuming "write once": platform differences in navigation, permissions and notifications still need work.
  • Postponing upgrades until the gap is too big to cross.

Lab: crossing the boundary

Setup. Node.js 22 on the lab machine, as an analogy for a cross-platform runtime talking to native code (the mechanism, not React Native itself). A "native" function returns a position object {lat, lng, acc}. It's called 20,000 times three ways:

  • direct: an in-process function call (what JSI, Flutter's FFI and Kotlin Multiplatform's compiled code give you);
  • bridge: the request is serialised to JSON, posted to another thread (worker_threads), deserialised, executed, and the result serialised and posted back, awaited each time (what React Native's original bridge did);
  • batched bridge: the same channel, but 100 calls per message.

1,000 warm-up calls ran first.

Results

Style Per call Relative to direct
direct in-process 0.231 µs 1×
JSON + thread hop + reply 34.7 µs 150×
batched, 100 calls per message 1.17 µs 5×

At 34.7 µs per call, one 16.7 ms frame fits about 480 bridge calls, before doing any UI work.

What it shows

  • The cost is in serialisation and scheduling, not in the work. Getting a position took a fraction of a microsecond; carrying the request across the boundary took 150 times longer.
  • Chatty interfaces hurt most: gesture handlers, scroll events, animation frames and long lists can generate hundreds of calls per frame.
  • Two fixes, both used by modern frameworks: make calls direct and synchronous where it's safe (JSI, FFI), and batch or move high-frequency work to the native side (native-driven animations, Reanimated worklets in React Native, Flutter's engine-side rendering).
  • The same lesson applies everywhere: across processes (Volume 19's microservices), across the network (chapter 04), and across language runtimes.

Try it yourself

  1. Replace JSON with structured clone (postMessage of the object itself) and measure.
  2. Make each call carry a 10 KB payload and see how the gap changes.
  3. In a React Native app, implement the same call as a TurboModule and as an old-style bridge module and profile both.
  4. Measure a Flutter platform channel call versus an FFI call to a small C function.

Revision sheet: cross-platform frameworks

Key ideas

  • Every approach chooses where the shared/native boundary sits; crossing it costs time.
  • React Native: JS/TS with native views; New Architecture (JSI, Fabric, TurboModules, Codegen); Hermes; Expo.
  • Flutter: Dart widgets drawn by its own engine; platform channels and FFI.
  • Kotlin Multiplatform: shared Kotlin logic; native UI or Compose Multiplatform.
  • PWAs and web shells for content-heavy apps.
  • Choose by team skills, UI fidelity needs, device APIs, performance and upgrade cost; always budget native code.

Numbers to remember

  • Lab: direct 0.23 µs; JSON bridge 34.7 µs (150×); batched 1.17 µs; ~480 bridge calls per 16.7 ms frame.

Glossary

  • JSI: JavaScript Interface, direct JS–C++ calls in React Native.
  • Fabric: React Native's new renderer.
  • TurboModules: lazily loaded native modules called via JSI.
  • Platform channel: Flutter's messaging between Dart and platform code.
  • expect/actual: KMP's mechanism for platform-specific implementations.