<?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"><channel><title><![CDATA[From Expo TSX to Native Metal]]></title><description><![CDATA[From Expo TSX to Native Metal]]></description><link>https://from-expo-tsx-to-native-metal.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 28 Nov 2026 20:54:23 GMT</lastBuildDate><atom:link href="https://from-expo-tsx-to-native-metal.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[From Expo TSX to Native Metal]]></title><description><![CDATA[TL;DR: An Expo app is a real native iOS and Android application. Your TypeScript/TSX code runs inside a native container via the Hermes JavaScript engine…]]></description><link>https://from-expo-tsx-to-native-metal.hashnode.dev/from-expo-tsx-to-native-metal</link><guid isPermaLink="true">https://from-expo-tsx-to-native-metal.hashnode.dev/from-expo-tsx-to-native-metal</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[React Native]]></category><category><![CDATA[JSI]]></category><category><![CDATA[iOS]]></category><category><![CDATA[Android]]></category><dc:creator><![CDATA[ThamizhElango Natarajan]]></dc:creator><pubDate>Thu, 15 Jan 2026 15:02:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1768489457336/a3409115-14e5-4004-b6e6-2cc90222cdc0.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-a-deep-dive-into-react-native-hermes-jsi-and-expo-native-modules">A Deep Dive into React Native, Hermes, JSI, and Expo Native Modules</h2>
<blockquote>
<p><strong>TL;DR</strong>: An Expo app is a <em>real</em> native iOS and Android application. Your TypeScript/TSX code runs inside a native container via the <strong>Hermes JavaScript engine</strong>, talks to native APIs through <strong>JSI (C++ bindings)</strong>, and renders <strong>actual UIKit / Android Views</strong>—not HTML, not WebView, not Blink.</p>
</blockquote>
<hr />
<h2 id="heading-1-the-big-misconception">1. The Big Misconception</h2>
<blockquote>
<p>“React Native converts React into mobile HTML and CSS.” ❌</p>
</blockquote>
<p>This is <strong>wrong</strong>.</p>
<p>React Native is <strong>not</strong> a web renderer.</p>
<ul>
<li><p>❌ No DOM</p>
</li>
<li><p>❌ No HTML</p>
</li>
<li><p>❌ No CSSOM</p>
</li>
<li><p>❌ No Blink/WebKit</p>
</li>
</ul>
<p>Instead:</p>
<ul>
<li><p>React Native renders <strong>native UI widgets</strong></p>
</li>
<li><p>JavaScript runs inside an embedded JS engine (<strong>Hermes</strong>)</p>
</li>
<li><p>Native APIs are accessed via <strong>C++ bindings (JSI)</strong></p>
</li>
</ul>
<p>Expo simply <strong>streamlines</strong> this pipeline.</p>
<hr />
<h2 id="heading-2-what-expo-prebuild-really-does">2. What <code>expo prebuild</code> <em>Really</em> Does</h2>
<p>When you run:</p>
<pre><code class="lang-bash">npx expo prebuild
</code></pre>
<p>Expo generates a <strong>real native app</strong>.</p>
<h3 id="heading-ios-output">iOS Output</h3>
<pre><code class="lang-plaintext">ios/
├── AppDelegate.swift
├── DoubleEntry.xcworkspace
├── Info.plist
└── Pods/
</code></pre>
<h3 id="heading-android-output">Android Output</h3>
<pre><code class="lang-plaintext">android/
├── MainActivity.kt
├── build.gradle
├── settings.gradle
└── app/src/main/
</code></pre>
<h3 id="heading-languages-used">Languages Used</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Platform</td><td>Language</td></tr>
</thead>
<tbody>
<tr>
<td>iOS</td><td>Swift + Objective-C++</td></tr>
<tr>
<td>Android</td><td>Kotlin + Java</td></tr>
</tbody>
</table>
</div><p>➡️ At this point, <strong>you already have a native app</strong>.</p>
<hr />
<h2 id="heading-3-native-app-entry-points">3. Native App Entry Points</h2>
<h3 id="heading-ios-appdelegateswift">iOS: <code>AppDelegate.swift</code></h3>
<p>This is a standard UIKit application entry point.</p>
<p>Key responsibilities:</p>
<ul>
<li><p>Creates <code>UIWindow</code></p>
</li>
<li><p>Boots React Native runtime</p>
</li>
<li><p>Loads JS bundle / Hermes bytecode</p>
</li>
<li><p>Handles deep links &amp; universal links</p>
</li>
</ul>
<p>React Native is started like <em>any other SDK</em>.</p>
<hr />
<h3 id="heading-android-mainactivitykt">Android: <code>MainActivity.kt</code></h3>
<p>This is a standard Android <code>Activity</code>.</p>
<p>Key responsibilities:</p>
<ul>
<li><p>Sets theme</p>
</li>
<li><p>Creates React Root View</p>
</li>
<li><p>Enables Fabric (New Architecture)</p>
</li>
<li><p>Hosts native UI views</p>
</li>
</ul>
<p>Again — <strong>100% native Android</strong>.</p>
<hr />
<h2 id="heading-4-where-your-javascript-actually-runs">4. Where Your JavaScript Actually Runs</h2>
<h3 id="heading-hermes-javascript-engine">Hermes JavaScript Engine</h3>
<p>Hermes is a <strong>C++ JavaScript engine embedded inside your app</strong>.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td>Hermes</td></tr>
</thead>
<tbody>
<tr>
<td>Written in</td><td>C++</td></tr>
<tr>
<td>Bytecode</td><td><code>.hbc</code></td></tr>
<tr>
<td>Startup</td><td>Extremely fast</td></tr>
<tr>
<td>Memory</td><td>Optimized for mobile</td></tr>
</tbody>
</table>
</div><h3 id="heading-production-build-flow">Production Build Flow</h3>
<pre><code class="lang-plaintext">TSX → JS → bundle.js → Hermes Compiler → bundle.hbc
</code></pre>
<p>Hermes executes <code>.hbc</code> <strong>directly inside your native app</strong>.</p>
<p>➡️ No browser involved.</p>
<hr />
<h2 id="heading-5-metro-babel-hermes-who-does-what">5. Metro, Babel, Hermes: Who Does What?</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Tool</td><td>Role</td></tr>
</thead>
<tbody>
<tr>
<td>Babel</td><td>TSX → JavaScript</td></tr>
<tr>
<td>Metro</td><td>Bundles all JS modules</td></tr>
<tr>
<td>Hermes Compiler</td><td>JS → Bytecode</td></tr>
<tr>
<td>Hermes Runtime</td><td>Executes bytecode</td></tr>
</tbody>
</table>
</div><p>Metro is like <strong>Webpack</strong>, Hermes is like <strong>V8</strong> (but mobile-first).</p>
<hr />
<h2 id="heading-6-react-native-rendering-pipeline-no-dom">6. React Native Rendering Pipeline (No DOM!)</h2>
<p>When you write:</p>
<pre><code class="lang-tsx">import { Text } from 'react-native';

&lt;Text&gt;Hello&lt;/Text&gt;
</code></pre>
<h3 id="heading-what-actually-happens">What Actually Happens</h3>
<ol>
<li><p>React creates a <strong>Virtual Element</strong></p>
</li>
<li><p>React Native reconciler processes it</p>
</li>
<li><p>Fabric creates a <strong>C++ Shadow Tree</strong></p>
</li>
<li><p>Platform renderer maps it to native views</p>
</li>
</ol>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Platform</td><td>Native Widget</td></tr>
</thead>
<tbody>
<tr>
<td>iOS</td><td><code>UILabel</code></td></tr>
<tr>
<td>Android</td><td><code>TextView</code></td></tr>
</tbody>
</table>
</div><p>➡️ These are <strong>real OS widgets</strong>.</p>
<hr />
<h2 id="heading-7-the-old-bridge-vs-new-architecture">7. The Old Bridge vs New Architecture</h2>
<h3 id="heading-legacy-bridge-old">Legacy Bridge (Old)</h3>
<pre><code class="lang-plaintext">JS → JSON → Native → JSON → JS
</code></pre>
<p>Problems:</p>
<ul>
<li><p>Serialization overhead</p>
</li>
<li><p>Async-only</p>
</li>
<li><p>Performance bottleneck</p>
</li>
</ul>
<hr />
<h3 id="heading-new-architecture-jsi-fabric">New Architecture (JSI + Fabric)</h3>
<pre><code class="lang-plaintext">JS ↔ C++ ↔ Native
</code></pre>
<p>Benefits:</p>
<ul>
<li><p>🚀 No JSON serialization</p>
</li>
<li><p>🚀 Sync calls possible</p>
</li>
<li><p>🚀 Shared memory (TypedArray)</p>
</li>
<li><p>🚀 Faster animations &amp; UI</p>
</li>
</ul>
<p>JS talks <strong>directly to C++ objects</strong>.</p>
<hr />
<h2 id="heading-8-jsi-the-heart-of-native-bindings">8. JSI: The Heart of Native Bindings</h2>
<p><strong>JSI (JavaScript Interface)</strong> is a C++ API that lets native code:</p>
<ul>
<li><p>Create JS objects</p>
</li>
<li><p>Expose functions</p>
</li>
<li><p>Share memory buffers</p>
</li>
</ul>
<p>It replaces the old bridge entirely.</p>
<p>Think of it as:</p>
<blockquote>
<p><code>napi-rs</code> for React Native</p>
</blockquote>
<p>But cross-platform and mobile-first.</p>
<hr />
<h2 id="heading-9-how-expo-native-modules-work">9. How Expo Native Modules Work</h2>
<p>Let’s take <code>expo-crypto</code> as a real example.</p>
<h3 id="heading-module-declaration">Module Declaration</h3>
<pre><code class="lang-json">{
  <span class="hljs-attr">"platforms"</span>: [<span class="hljs-string">"apple"</span>, <span class="hljs-string">"android"</span>],
  <span class="hljs-attr">"apple"</span>: { <span class="hljs-attr">"modules"</span>: [<span class="hljs-string">"CryptoModule"</span>] },
  <span class="hljs-attr">"android"</span>: { <span class="hljs-attr">"modules"</span>: [<span class="hljs-string">"expo.modules.crypto.CryptoModule"</span>] }
}
</code></pre>
<p>This tells Expo:</p>
<ul>
<li><p>Which native classes to load</p>
</li>
<li><p>On which platforms</p>
</li>
</ul>
<hr />
<h2 id="heading-10-ios-native-implementation-swift">10. iOS Native Implementation (Swift)</h2>
<pre><code class="lang-swift"><span class="hljs-keyword">private</span> <span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">getRandomValues</span><span class="hljs-params">(array: TypedArray)</span></span> <span class="hljs-keyword">throws</span> -&gt; <span class="hljs-type">TypedArray</span> {
  <span class="hljs-keyword">let</span> status = <span class="hljs-type">SecRandomCopyBytes</span>(
    kSecRandomDefault,
    array.byteLength,
    array.rawPointer
  )
  <span class="hljs-keyword">return</span> array
}
</code></pre>
<p>Key points:</p>
<ul>
<li><p>Calls <strong>Apple Security Framework</strong></p>
</li>
<li><p>Writes directly into shared memory</p>
</li>
<li><p>No copying, no JSON</p>
</li>
</ul>
<hr />
<h2 id="heading-11-android-native-implementation-kotlin">11. Android Native Implementation (Kotlin)</h2>
<pre><code class="lang-kotlin"><span class="hljs-keyword">private</span> <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">getRandomValues</span><span class="hljs-params">(typedArray: <span class="hljs-type">TypedArray</span>)</span></span> {
  <span class="hljs-keyword">val</span> array = ByteArray(typedArray.byteLength)
  secureRandom.nextBytes(array)
  typedArray.write(array, ...)
}
</code></pre>
<p>Key points:</p>
<ul>
<li><p>Uses <code>SecureRandom</code></p>
</li>
<li><p>Writes into JS-owned buffer</p>
</li>
<li><p>Shared memory via JSI</p>
</li>
</ul>
<hr />
<h2 id="heading-12-calling-native-code-from-typescript">12. Calling Native Code from TypeScript</h2>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> Crypto <span class="hljs-keyword">from</span> <span class="hljs-string">'expo-crypto'</span>;

<span class="hljs-keyword">const</span> bytes = Crypto.getRandomBytes(<span class="hljs-number">16</span>);
</code></pre>
<h3 id="heading-execution-flow">Execution Flow</h3>
<ol>
<li><p>JS calls <code>ExpoCrypto.getRandomBytes</code></p>
</li>
<li><p>JSI resolves native module</p>
</li>
<li><p>Swift/Kotlin function executes</p>
</li>
<li><p>Result written into shared buffer</p>
</li>
<li><p>JS receives data synchronously</p>
</li>
</ol>
<p>➡️ This is <strong>not RPC</strong>. It’s <strong>in-process execution</strong>.</p>
<hr />
<h2 id="heading-13-complete-runtime-architecture">13. Complete Runtime Architecture</h2>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768489508925/08f7f5d2-8af8-4e24-88c2-8f9f27ad8c07.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-14-build-process-expo-runios">14. Build Process: <code>expo run:ios</code></h2>
<p>What <em>actually</em> happens:</p>
<ol>
<li><p>Metro bundles JS</p>
</li>
<li><p>Hermes compiles to bytecode</p>
</li>
<li><p>Xcode / Gradle compiles native code</p>
</li>
<li><p>JS bytecode embedded into app</p>
</li>
<li><p>App installed on device</p>
</li>
</ol>
<p>At runtime:</p>
<blockquote>
<p><strong>Hermes boots → loads bytecode → JS runs → native UI renders</strong></p>
</blockquote>
<hr />
<h2 id="heading-15-key-takeaways">15. Key Takeaways</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Concept</td><td>Reality</td></tr>
</thead>
<tbody>
<tr>
<td>Expo</td><td>Native app generator</td></tr>
<tr>
<td>React Native</td><td>Native UI renderer</td></tr>
<tr>
<td>Hermes</td><td>Embedded JS engine</td></tr>
<tr>
<td>JSI</td><td>Zero-copy native bridge</td></tr>
<tr>
<td>Fabric</td><td>New renderer</td></tr>
<tr>
<td>TurboModules</td><td>New native module system</td></tr>
<tr>
<td><code>.hbc</code></td><td>JS bytecode</td></tr>
</tbody>
</table>
</div><p>➡️ <strong>Your JavaScript runs <em>inside</em> a native app, not on top of it.</strong></p>
<hr />
<h2 id="heading-16-final-mental-model">16. Final Mental Model</h2>
<blockquote>
<p>React Native is <strong>not a web abstraction</strong>.</p>
<p>It is a <strong>native runtime that happens to be programmable in JavaScript</strong>.</p>
</blockquote>
<p>Once this clicks, React Native suddenly feels:</p>
<ul>
<li><p>Predictable</p>
</li>
<li><p>Performant</p>
</li>
<li><p>Architecturally elegant</p>
</li>
</ul>
<hr />
]]></content:encoded></item></channel></rss>