WhoBuilt

The great Divide: Bridging Native Modules And React Native

Oct 22, 2020· 22 min· 890 views·Watch on YouTube

Speaker

Monica Restrepo, a software engineer at Major League Soccer, computer science student, and Great Helper open source contributor, explains native modules and React Native at React Native EU 2020 for Callstack.

What the bridge does

Restrepo describes the bridge as the part of React Native that sends messages between JavaScript and native code. In the older architecture, those messages are asynchronous JSON payloads sent in batches, letting JavaScript use platform APIs and native modules.

The new architecture and the bridge

Restrepo outlines TurboModules and JSI as parts of React Native's planned new architecture. TurboModules are intended to load modules lazily, improve type safety, reduce call overhead, and start faster. JSI provides an interface for C++ and JavaScript to interact, addressing limits she associates with the bridge, such as batching and bottlenecks.

How the bridge works under the hood

On the native side, events such as timers, network activity, touch gestures, and Bluetooth are collected and serialized before reaching JavaScript; calls back to native code also pass through the bridge. Restrepo traces module registration, method configuration, JavaScript execution, and callbacks, describing how exported modules and methods become available to the app.

Bridging MLS's identity login

At Major League Soccer, the login flow used a web view connected to a web login page and Gigya, which handles registration, social login, profiles, and preferences. The team replaced that flow with a native module using Gigya's SDK, implementing the login screen in Kotlin and Swift and exposing native methods and events to React Native.

Takeaways

  • Map the native APIs your app needs before deciding whether to build a module or rely on a web view.
  • Expect older React Native apps and libraries to keep using the bridge during migrations.
  • Lazy module initialization can avoid setting up native modules and view managers the app does not use.
  • For a native module, register the package and explicitly expose the methods and events JavaScript needs.
  • Replacing an embedded web login with a provider's native SDK can provide access to its native capabilities.

Mentioned in this talk

Search inside this talk

What was claimed 9

Related talks