This starter template allows for the effortless integration of Nim code into React Native apps, featuring automatic binding generation. Designed for both iOS and Android, it eliminates the need for manual bridge code while ensuring full TypeScript support. Perfect for developers looking to streamline their app development process with minimal overhead.
React Native + Nim Integration
This project presents a robust starter template designed for integrating Nim backend logic into React Native applications. Utilizing automatic binding generation, it simplifies the development process by allowing developers to focus on business logic in Nim while seamlessly connecting to the React Native interface.
| iOS | Android | |
|---|---|---|
![]() | ![]() | ![]() |
This template clearly distinguishes between business logic implemented in Nim and the user interface created with React Native, mirroring architectural principles from the status-go backend service.
react-native-nim/
├── nim-core/ # Business Logic (Nim)
├── bindings/ # Generated C Bindings
├── mobile-app/ # React Native App with Auto-Generation
│ ├── nim/ # Nim source code
│ ├── tools/ # Automatic binding generator
│ └── modules/nim-bridge/ # Generated bridge code
├── tools/ # Build Automation
Define business logic in the Nim source files, which will be exposed to React Native as callable functions:
# mobile-app/nim/nimbridge.nim
proc calculateTax*(income: cint, rate: cint): cint {.exportc.} =
return (income * rate) div 100
proc validateCreditCard*(cardNumber: cstring): cint {.exportc.} =
if len($cardNumber) == 16: return 1
return 0
Execute the following command to generate bindings automatically:
cd mobile-app
yarn build:nim
This process creates:
Utilize the generated bindings within the React Native application as follows:
import { NimCore } from './modules/nim-bridge/src/index';
const tax = NimCore.calculateTax(50000, 20); // Returns 10000
const isValid = NimCore.validateCreditCard("1234567890123456"); // Returns true
This project serves as a powerful foundation for developers looking to incorporate Nim's efficient business logic into their React Native applications, facilitating a clean separation of concerns while enhancing productivity. By utilizing modern tooling and an organized project structure, developers can work more effectively across platforms.
No comments yet.
Sign in to be the first to comment.