Coder Social home page Coder Social logo

julian-becker / discovering-turbomodules Goto Github PK

View Code? Open in Web Editor NEW

This project forked from barthap/discovering-turbomodules

0.0 0.0 0.0 419 KB

A step by step example of creating your own React Native TurboModule.

License: MIT License

CMake 4.43% C++ 37.62% Kotlin 4.76% Java 18.22% JavaScript 3.66% C 1.20% TypeScript 7.44% Swift 1.07% Objective-C 10.68% Ruby 6.33% Objective-C++ 4.57%

discovering-turbomodules's Introduction

Discovering Turbo Modules

A journey to discover React Native TurboModules. Alghough TurboModules aren't officially released yet and there is almost no documentation, there are already some libraries based on new infrastructure, including awesome Reanimated 2 by SWM. I digged through React Native source code and various Github repositories to learn how it is done. I managed to get it working, so I share my step-by-step journey here.

Each commit is a different stage towards a fully featured Turbo Module.

  1. see commit - Basic initialization and boilerplate (use npx create-react-native-library with C++ template)
  2. see commit - Adding fbjni for Android - it greatly improves Java - C++ interop.
  3. see commit - Migrating from legacy RN bridge to JSI.
  4. see commit - Implementing the "Real" Turbo Module.
  5. see commit - Calling Kotlin/Swift code from C++ module.
  6. TODO: Multithreading / asynchronous operations

I'm not so creative in examples, I ended up with something simple, but demonstrating: The module consists of two methods:

  • sumSquares(a: number, b: number): number - calculates a^2 + b^2 - this method has C++ only implementation
  • makeGreetingFor(name: string): string - returns [Tag] Hello, {name}! - we want this method to be implemented for each platform separately in Kotlin/Swift.

Useful repositories and articles about Turbo Modules:

Known issues

  • In iOS project, after each pod install you have to manually add GreetingManager.swift to project in Xcode. Adding *.swift to podfile sources causes conflicts with React dependencies, because they're not modularized. You could also try with use_frameworks!.

Below is a react-native-builder-bob generated readme:

Installation

npm install my-turbo-utils

Usage

import MyTurboUtils from 'my-turbo-utils';

// 3*3 + 4*4 = 25
const result = await MyTurboUtils.sumSquares(3, 7);

const greeting = await MyTurboUtils.makeGreetingFor('TurboModules');

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

discovering-turbomodules's People

Contributors

barthap avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.