<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tarandeep Matharu on Medium]]></title>
        <description><![CDATA[Stories by Tarandeep Matharu on Medium]]></description>
        <link>https://medium.com/@tarandeepmatharu922?source=rss-8a826c64fa6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HqUrSti4_Kt5m-AHG12alw.jpeg</url>
            <title>Stories by Tarandeep Matharu on Medium</title>
            <link>https://medium.com/@tarandeepmatharu922?source=rss-8a826c64fa6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 20:27:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tarandeepmatharu922/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Recipe To Make React Native Apps Blazing Fast: Turbo Modules!]]></title>
            <link>https://medium.com/simform-engineering/recipe-to-make-react-native-apps-blazing-fast-turbo-modules-61d258141cdd?source=rss-8a826c64fa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/61d258141cdd</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[turbo-module]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tarandeep Matharu]]></dc:creator>
            <pubDate>Tue, 20 Sep 2022 06:41:25 GMT</pubDate>
            <atom:updated>2022-09-20T06:41:25.820Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*9O12QTISrfqObaz3C-Dw1A.gif" /></figure><p>We have a new react-native architecture in the latest release, and communication with native platforms can now happen without any bridge. Thanks to JSI, developers will be able to create turbo modules. In addition, we’ve got a new renderer named Fabric, exceptional direct communication with native, the ability to use multiple JS engines, concurrency, and many exciting features.</p><p>So let’s see what’s interesting to learn! 🤩</p><ul><li>Problem with communication between the native and javascript world</li><li>What is a turbo module and what problem does it solve?</li><li>The billion-dollar question: What is JSI?</li><li>Implementing our own: TurboModule<br>- Steps for the Android platform <br>- Steps for the iOS platform</li></ul><blockquote><strong>Problem with communication between native and javascript world</strong></blockquote><p><em>When communicating with Android/iOS native APIs, we currently pass over serialized data from the RN bridge to the respective platforms and receive data back in the same manner.</em></p><p>To be honest, it’s just slow, and we as developers want fast things, don’t we? In a real-world scenario, lots of operations are also done using the RN bridge. And so, it becomes a bottleneck, slowing communication between the native and javascript worlds.</p><p>The current implementation for communication is known as native modules. To eliminate this problem and to actually upgrade our slow car 🚙 to an F1 racing car 🏎 , the RN team introduced turbo modules in the new architecture.</p><blockquote><strong>What is a turbo module?</strong></blockquote><p><em>A turbo module is a native module created using JSI (javascript interface) technology from the new react-native architecture.</em></p><p>When using the turbo module, we no longer use the RN bridge, and it’s like calling a simple JavaScript function because the method from native gets registered on our JavaScript runtime. As a result, it’s blazing fast. And that’s why the RN team called it the turbo module, cause it’s fast, like really fast! 😎</p><p>With turbo modules, we get type safety across all platforms, support for more types and even custom ones, and a fast communication medium, which is the best of all. Of course, there are some more steps to implementing it than a native module implementation, but it’s worth it in the end.</p><blockquote><strong>The billion-dollar question: What is JSI? 🤑💰💸</strong></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5fBH6zs8OpCgL9sNdZK%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F5fBH6zs8OpCgL9sNdZK%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F5fBH6zs8OpCgL9sNdZK%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/319d7369eb5e01560864ff8544dc9bdc/href">https://medium.com/media/319d7369eb5e01560864ff8544dc9bdc/href</a></iframe><p><em>JSI is an API for virtually any JavaScript virtual machine that helps to directly and synchronously invoke methods on the native side (java or/objc).</em></p><p>Above is how the react-native team defines JSI. Pretty confusing, isn’t it? 🤨 What happens is that our native methods get registered on the currently running JavaScript engine that RN is working on so that we can just directly invoke them like this:</p><pre>MessageModule.sendMessage(‘Jimmy’, ‘Hi how are you?’);</pre><p>There is no RN bridge 🤯, which makes it blazing fast now. 🚀</p><blockquote><strong>Implementing our own: TurboModule</strong></blockquote><p>Let’s start with TurboModule. Below, we illustrate the steps to creating an RN project, which is the obvious first step 😉. And then, we install react-native-codegen, which will generate native boilerplate code for us!</p><ul><li>Step 1: Create an RN project of the latest release</li></ul><pre>npx react-native init turbocalendar</pre><pre>//also execute this in ios folder if cocoapods weren&#39;t installed properly. Make sure that cocoapods are installed in ios folder.</pre><pre>pod install</pre><ul><li>Step 2: Install react-native-codegen</li></ul><pre>npm install react-native-codegen</pre><p><strong>🔷 Steps for Android Platform:</strong></p><p>Before starting, please use Android Studio to write the turbo module and install NDK because there will be c++ involved. This version of NDK should be downloaded and installed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*0St1nEkY6oobTRHN1aksIw.png" /><figcaption>Install NDK from SDK manager</figcaption></figure><ul><li>Step 3: Enable RN new architecture from android/gradle.properties</li></ul><pre>//Look for this option and set it to true from false<br>newArchEnabled=true</pre><ul><li>Step 4: Enable Hermes JavaScript engine inside android/app/build.gradle</li></ul><pre>// change enableHermes to true from false<br>project.ext.react = [<br> enableHermes: true, // clean and rebuild if changing<br>]</pre><ul><li>Step 5: Install react-native-gradle-plugin</li></ul><pre>npm install react-native-gradle-plugin</pre><ul><li>Step 6: Build the project on android</li></ul><pre>npx react-native run-android</pre><ul><li>Step 7: Provide a Flow js Module schema in moduleschema/NativeCalendarModule.js</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad97ec99ef14564a28e3b71ddd64d304/href">https://medium.com/media/ad97ec99ef14564a28e3b71ddd64d304/href</a></iframe><ul><li>Step 8: Apply react-native-gradle-plugin in android/app/build.gradle</li></ul><pre>// paste this in top lines of the file<br>apply plugin: &quot;com.facebook.react&quot;</pre><ul><li>Step 9: Give react config object in android/app/build.gradle for react-native-gradle-plugin to use and generate necessary files.</li></ul><pre>// Paste this object after applying react-native-gradle-plugin<br>react {<br> libraryName = &quot;calendarlibrary&quot;<br> jsRootDir = rootProject.file(&quot;../moduleschema/&quot;)<br> codegenDir = rootProject.file(&quot;../node_modules/react-native-         codegen/&quot;)<br>}</pre><ul><li>Step 10: Uncomment generateCodegenArtifactsFromSchema task from afterEvaluate block of android config object in android/app/build.gradle</li></ul><pre>afterEvaluate {</pre><pre> // If you wish to add a custom TurboModule or component locally,<br> // you should uncomment this line.<br> // preBuild.dependsOn(&quot;generateCodegenArtifactsFromSchema&quot;)</pre><pre> preDebugBuild.dependsOn(packageReactNdkDebugLibs)</pre><pre> preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)</pre><pre> ...</pre><pre>}</pre><ul><li>Step 11: Inside android/app/src/main/jni/Android.mk read through the comments and uncomment the lines which are told to.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2e4a22b5f1a79f6243887b7b6a8be32/href">https://medium.com/media/e2e4a22b5f1a79f6243887b7b6a8be32/href</a></iframe><ul><li>Step 12: Add libreact_codegen_calendarlibrary to LOCAL_SHARED_LIBRARIES variable inside Android.mk the file.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f80a0f5385e182a33514f87e8722c7ca/href">https://medium.com/media/f80a0f5385e182a33514f87e8722c7ca/href</a></iframe><p><strong>⚠️ Warning:</strong> Do not remove any other library from here; these are c++ libraries.</p><ul><li>Step 13: Re-run the project on Android. You will see codegen generated files in android/app/build/generated/source/codegen a folder like this</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*G5TsWvbzgqkCkZkIp2c7og.png" /><figcaption>Code generated by react-native-codegen for turbo module</figcaption></figure><p>We’ll use NativeCalendarModuleSpec.java file to extend from it and create our NativeCalendarModule.java.</p><ul><li>Step 14: Create a NativeCalendarModule.java file inside app/src/main/java/com/turbocalendar the folder. Look at the code below, which extends NativeCalendarModuleSpec.java.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e80c43cca528b7ce3267808a49d53ff6/href">https://medium.com/media/e80c43cca528b7ce3267808a49d53ff6/href</a></iframe><p>Provide created turbo module inside MainApplicationReactNativeHost.java like below ⬇️</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/936bbaaccc9b3241c269934bd29a95cd/href">https://medium.com/media/936bbaaccc9b3241c269934bd29a95cd/href</a></iframe><ul><li>Step 15: Provide the turbo module&#39;s library inside <em>android/app/src/main/jni/MainApplicationModuleProvider.cpp</em></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1937ac0e76851fc419439bd944980882/href">https://medium.com/media/1937ac0e76851fc419439bd944980882/href</a></iframe><ul><li>Step 16: Paste the following code into App.js</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d75057b77886fe50abdd8058244705ba/href">https://medium.com/media/d75057b77886fe50abdd8058244705ba/href</a></iframe><p>In the above code, we are importing the NativeCalendarModule from the schema file we created, so we get type safety here as well 😀 also it’s essential to do this way.</p><p>Step 17: Run the project on Android; click on click me!, the button in UI; after clicking the button, you will receive a message.</p><p><strong>Here is the Android output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*wKACXpQy2VQvUY_tQfbwfg.gif" /><figcaption>Android Output</figcaption></figure><p>Finally, we created a turbo module, called a method from it, and received a response. 🎉</p><p>This is how we create a turbo module implementing generated spec files. It’s up to you which API you want to consume. It’s just like native modules.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FCgo9XkgzRcTPW%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FCgo9XkgzRcTPW%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FCgo9XkgzRcTPW%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="250" frameborder="0" scrolling="no"><a href="https://medium.com/media/add012999e57bdd3b9621504757b475d/href">https://medium.com/media/add012999e57bdd3b9621504757b475d/href</a></iframe><p>Awesome! We have implemented the turbo module for Android. Grab your cup of coffee ☕️ , and let’s move forward to the iOS steps.</p><p><strong>🔷 Steps for iOS Platform:<br></strong>As we have done with Android, the iOS one isn’t that complex. Also, ensure to use Xcode; it will give autosuggest and a lot of other stuff to make our lives easier.</p><p>📘 <strong>Note:</strong> If you have already performed steps 1 and 2, you can skip them.</p><ul><li>Step 3: Provide module schema config in the package.json file for react-native-codegen to use.</li></ul><pre>// Place this object in package.json file<br>&quot;codegenConfig&quot;: {<br>    &quot;libraries&quot;: [<br>      {<br>        &quot;name&quot;: &quot;NativeCalendarModule&quot;,<br>        &quot;type&quot;: &quot;modules&quot;,<br>        &quot;jsSrcsDir&quot;: &quot;./moduleschema&quot;<br>      }<br>    ]<br>  }</pre><ul><li>Step 4: Enable New Architecture by executing this command in the ios folder.</li></ul><pre>RCT_NEW_ARCH_ENABLED=1 bundle exec pod install</pre><pre>if above doesn&#39;t work for m1 macs use</pre><pre>arch -x86_64 RCT_NEW_ARCH_ENABLED=1 bundle exec pod install</pre><p>This will enable the new architecture, install required pods, and generate necessary files using the module schema folder’s NativeCalendarModule.</p><ul><li>Step 5: In moduleschema/NativeCalendarModule.js, include a Flow js Module schema.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad97ec99ef14564a28e3b71ddd64d304/href">https://medium.com/media/ad97ec99ef14564a28e3b71ddd64d304/href</a></iframe><ul><li>Step 6: Because there will be c++ involved, we’ll use the .mm file extension, which allows us to use objc with c++. In the turbocalendar folder, create a header file called RCTNativeCalendarModule.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*rBrvf-NYoJu94nJckn2aXw.png" /><figcaption>Xcode project files view</figcaption></figure><p>Then in that file, paste the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16eadb4ac1c6df161b688388c7e6988e/href">https://medium.com/media/16eadb4ac1c6df161b688388c7e6988e/href</a></iframe><ul><li>Step 7: Provide an implementation for this file by creating a RCTNativeCalendarModule.mm file and using this code inside that file.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a04a807818f45817d1dcc18ccec88ca9/href">https://medium.com/media/a04a807818f45817d1dcc18ccec88ca9/href</a></iframe><p>The above code provides the implementation and has a getMessage method, if you notice, which will be called from JavaScript directly without any bridge, just like calling another JavaScript method.</p><ul><li>Step 8: Inside AppDelegate.mm file’s didFinishLaunchingWithOptions method, add this statement as the first line:</li></ul><pre>RCTEnableTurboModule(YES);</pre><p>We are now good to go for iOS, too, when you run your app and click the click me! If you follow the method, you’ll receive the same message we received when running the app on Android.</p><p><strong>Here is the iOS output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*SZmx-9yeLbYm_i1x3KBLIA.gif" /><figcaption>iOS Output</figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F8UGGp7rQvfhe63HrFq%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F8UGGp7rQvfhe63HrFq%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F8UGGp7rQvfhe63HrFq%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="243" frameborder="0" scrolling="no"><a href="https://medium.com/media/696f962473fdb3c72f858bf445de0d6d/href">https://medium.com/media/696f962473fdb3c72f858bf445de0d6d/href</a></iframe><p>Hurray! We have created a turbo module for both the Android and iOS platforms. By the way, is the coffee finished yet? 😉</p><p><strong>Find the source code on GitHub:<br></strong><a href="https://github.com/tarandeep-simform/turbocalendar/tree/master">https://github.com/tarandeep-simform/turbocalendar/tree/master</a></p><h3><strong>Conclusion ⛳️</strong></h3><p>React Native’s new architecture has given us game-changing tools for cutting-edge development. The Turbo modules make our communication with the native world from the JavaScript world blazing fast.</p><p>Giving us type safety across all platforms, support for new types, support for custom types, and direct native API method calls without involving the RN bridge. So cool, right? ☃️</p><p>Using the turbo modules system, we can make our app’s communication with the native world (Android or iOS) much faster and more efficient. I hope that you use the power 🔋 of this new method; and <strong>lastly</strong></p><blockquote>May, the React Native Power be with you. Good luck!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61d258141cdd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/simform-engineering/recipe-to-make-react-native-apps-blazing-fast-turbo-modules-61d258141cdd">Recipe To Make React Native Apps Blazing Fast: Turbo Modules!</a> was originally published in <a href="https://medium.com/simform-engineering">Simform Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>