NitroTest is an example nitro module we use for testing various Nitro features.
NitroTest is installed in the example/ app.
The main C++ testing hybrid object is exported;
import { HybridTestObjectCpp } from 'react-native-nitro-test'
const result = HybridTestObjectCpp.addNumbers(5, 7)NitroTest also contains a platform specific hybrid test object (HybridTestObjectSwiftKotlin), and a platform specific hybrid view (HybridTestView).
When any of the HybridObjects specs (*.nitro.ts) change, you must re-run nitrogen:
npx nitrogenandroid/: All yourandroid-specific implementations. (HybridTestObjectSwiftKotlin.kt)build.gradle: The gradle build file. This contains four important pieces:- Standard react-native library boilerplate code
- Configures Kotlin (
apply plugin: 'org.jetbrains.kotlin.android') - Adds all Nitrogen files (
apply from: '.../NitroTest+autolinking.gradle') - Triggers the native C++ build (via CMake/
externalNativeBuild)
CMakeLists.txt: The CMake build file to build C++ code. This contains four important pieces:- Creates a library called
NitroTest(same as innitro.json) - Adds all Nitrogen files (
include(.../NitroTest+autolinking.cmake)) - Adds all custom C++ files (only
HybridTestObjectCpp.cpp) - Adds a
cpp-adapter.cppfile, which autolinks all C++ HybridObjects (onlyHybridTestObjectCpp)
- Creates a library called
src/main/java/com/margelo/nitro/test/: All Kotlin implementations.NitroTestPackage.kt: The react-native package. You need this because the react-native CLI only adds libraries if they have a*Package.ktfile. In here, you can autolink all Kotlin HybridObjects (TestObjectSwiftKotlin)
cpp/: All your cross-platform implementations. (onlyHybridTestObjectCpp.cpp)ios/: All your iOS-specific implementations. (HybridTestObjectSwiftKotlin.swiftandHybridTestView.swift)nitrogen/: All files generated by nitrogen. You should commit this folder to git.src/: The TypeScript codebase. This defines all HybridObjects and loads them at runtime.specs/: All HybridObject types. Nitrogen will run on all*.nitro.tsfiles.
nitro.json: The configuration file for nitrogen. This will define all native namespaces, as well as the library name.NitroTest.podspec: The iOS podspec build file to build the iOS code. This contains three important pieces:- Specifies the Pod's name. This must be identical to the name specified in
nitro.json. - Adds all of your
.swiftor.cppfiles (implementations). - Adds all Nitrogen files (
add_nitrogen_files(s))
- Specifies the Pod's name. This must be identical to the name specified in
package.json: The npm package.json file.react-native-nitro-modulesshould be apeerDependency.