Nitro Modules
A Nitro Module is a library built with Nitro. It may contain one or more Hybrid Objects.
Structure
A Nitro Module is just like a regular native module, a nitro.json configuration file, and required autolinking hooks.
Creating a Nitro Module
1. Initialize the template
To create a new Nitro Module, simply run nitrogen init <moduleName>:
npx nitrogen@alpha init react-native-math
2. Implement your Hybrid Objects
Once you set up the library, you can start implementing your Hybrid Objects!
- With Nitrogen ✨
- Manually
With Nitrogen you can ✨ automagically ✨ generate all native interfaces from your TypeScript definitions.
The generated iOS initialization code registers the classes with HybridClassRegistry when the library loads. Include it through the SwiftPM setup.
See Hybrid Objects (Implementation) for more information.
If you don't want to use Nitrogen, simply create your native C++ classes that inherit from HybridObject and register a HybridClass - then register them using the HybridClassRegistry.
See Hybrid Objects (Implementation) for more information.
3. Set up an example app
After creating a Nitro Module, it's time to set up an example app to test your library!
- Expo
- Bare RN
npx create-expo-app@latest
npx @react-native-community/cli@latest init NitroMathExample
The Hybrid Objects from your Nitro Module will be registered in the HybridClassRegistry. This registration process needs to be called from somewhere:
- In React Native, this happens in the
*Package.ktfile which calls.initializeNative(). - If you are not using React Native, you need to manually call
.initializeNative()in your library's entry point.