A high-performance React Native Turbo Module that leverages C++ shared libraries for cross-platform native functionality. This package demonstrates how to integrate C++ code with React Native's new architecture for optimal performance on both iOS and Android.
- ⚡ Turbo Module Architecture - Built on React Native's new architecture for better performance
- 🔧 C++ Shared Library - Single C++ codebase compiled for both platforms
- 📱 Cross-Platform - Works seamlessly on iOS (.dylib) and Android (.so)
- 🎯 Type Safety - Full TypeScript support with auto-generated types
- 🚀 Synchronous Calls - Direct synchronous native method invocation
- 📦 Easy Integration - Simple npm package installation
- React Native 0.79.0 or higher
- iOS 13.0 or higher
- Android minSdkVersion 21 or higher
- CMake 3.13 or higher
- Android NDK (installed with React Native)
npm install react-native-cpp-turbo
# or
yarn add react-native-cpp-turbo
cd ios && pod install
For iOS, the native module will be automatically linked via CocoaPods.
Android configuration is automatically handled by the native module's build.gradle. Ensure you have:
- CMake installed (comes with Android Studio)
- NDK configured in your project
import { add, multiply, power } from 'react-native-cpp-turbo';
// Basic math operations
const sum = add(10, 20); // Returns: 30
const product = multiply(5, 6); // Returns: 30
const result = power(2, 8); // Returns: 256
// Example in a React component
import React from 'react';
import { View, Text } from 'react-native';
import { add, multiply, power } from 'react-native-cpp-turbo';
function Calculator() {
return (
<View>
<Text>5 + 3 = {add(5, 3)}</Text>
<Text>4 × 7 = {multiply(4, 7)}</Text>
<Text>2^10 = {power(2, 10)}</Text>
</View>
);
}
Adds two numbers and returns the sum.
Multiplies two numbers and returns the product.
Calculates base raised to the power of exponent.
-
Development Environment
- Node.js 16 or higher
- React Native development environment
- Xcode (for iOS)
- Android Studio (for Android)
-
Build Tools
- CMake 3.13+
- Android NDK
- CocoaPods
- Clone the repository:
git clone https://github.com/jahskee/react-native-cpp-turbo.git
cd react-native-cpp-turbo
- Install dependencies:
npm install
- Build TypeScript:
npm run prepare
- Link the package:
npm link
- In your test app:
npm link react-native-cpp-turbo
cd ios && pod install
- Rebuild your app:
# iOS
npx react-native run-ios
# Android
npx react-native run-android
react-native-cpp-turbo/
├── cpp/ # Shared C++ source code
│ ├── MathOperations.cpp
│ └── MathOperations.h
├── android/ # Android-specific implementation
│ ├── src/main/cpp/ # JNI adapter
│ └── src/main/java/ # Java/Kotlin bridge
├── ios/ # iOS-specific implementation
│ ├── CppTurbo.mm # Objective-C++ bridge
│ └── CppTurbo.h
└── src/ # TypeScript interface
├── index.tsx
└── NativeCppTurbo.ts
To add new C++ functions:
- Add function declaration in
cpp/MathOperations.h
- Implement in
cpp/MathOperations.cpp
- Add JNI wrapper in
android/src/main/cpp/cpp-adapter.cpp
- Add Java method in
CppTurboModule.java
- Add Objective-C method in
ios/CppTurbo.mm
- Update TypeScript interface in
src/NativeCppTurbo.ts
- Export from
src/index.tsx
- C++ Standard: C++17
- Supported ABIs: arm64-v8a, armeabi-v7a, x86, x86_64
- CMake flags:
-O2 -frtti -fexceptions
- C++ Standard: C++17
- C++ Library: libc++
- Deployment Target: iOS 13.0
Module not found error
# Clear caches and rebuild
cd ios && pod deintegrate && pod install
cd android && ./gradlew clean
npx react-native start --reset-cache
Android build failures
- Verify NDK is installed: Android Studio → SDK Manager → SDK Tools → NDK
- Check CMake version:
cmake --version
- Ensure
local.properties
containsndk.dir
iOS build failures
- Update pods:
cd ios && pod update
- Clean build: Xcode → Product → Clean Build Folder
- Check minimum iOS version in Podfile
TypeScript errors
# Regenerate types
npm run prepare
- Android Logs
adb logcat | grep -i cppturbo
- iOS Logs
- Use Xcode console
- Add
NSLog
statements in.mm
files
- C++ Debugging
- Add logging with
__android_log_print
(Android) - Use
NSLog
wrapper (iOS)
- All operations run synchronously on the JS thread
- For heavy computations, consider using async wrappers
- C++ operations are faster than JS equivalents for complex math
- Minimize data marshaling between JS and native
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit changes (
git commit -m 'Add amazing feature'
) - Push to branch (
git push origin feature/amazing-feature
) - Open a Pull Request
To publish a new version:
# Update version in package.json
npm version patch|minor|major
# Build and test
npm run prepare
npm test
# Publish
npm publish
MIT License - see LICENSE file for details
- 🐛 Report Issues
- 💬 Discussions
- 📧 Contact: jahskee@gmail.com
Built with React Native's Turbo Module architecture and inspired by the React Native community's need for high-performance native modules.