Native Platform
Your app may need features of the operating system that React Native and the community libraries do not provide: a file dialog, the system keychain, a Rust crate, a C++ library you already have. React Native for desktop connects native code to your JavaScript with the same building blocks as React Native, and adds Rust as the default language.
This section introduces:
- Native modules: native code with no user interface, such as storage, networking or an operating-system service. JavaScript calls them as functions and objects.
- Native components: native views that React renders. Either a view drawn with GPUI (a host component), or a view that belongs to the operating system itself (a native view).
Choosing how to write native code
| You have | Use |
|---|---|
| New code that calls the operating system | A Rust module. It is the default for new desktop code, with the Rust ecosystem's crates for most operating-system APIs. |
| Existing C++ code, or C++ shared with iOS and Android | A C++ module. |
An npm package that already ships a .node binary | A Node addon, which loads unchanged. |
| A React Native library that already supports iOS and Android | Port the library to desktop by supplying its native side. |
| A custom view drawn by GPUI | A host component. |
| A view from AppKit, Win32 or X11 | A native view. |
Where to start
- Native modules
- Introduction: the spec, Codegen and the implementation, in Rust or C++.
- Rust modules: types, threads, errors and events.
- C++ modules
- Node addons
- Native components
- Libraries
- The platform
note
Native modules and components use React Native's new architecture: TurboModules and Fabric. The legacy native module and component APIs of React Native are not available on desktop.