Don't Be Afraid To Write Native Code

Sep 9, 2024

Don't Be Afraid To Write Native Code

Join Lukash from Software Mansion as he walks through the challenges of building native modules using React Native, sharing insights on simplifying development with Expo Modules API, and breaking down complex tasks like accessing native toolkits for Android and iOS.

Author

Aditi Dixit
Aditi DixitContent Writer

Dave is a software engineer working on mobile apps using React Native. Heโ€™s great at it, but hereโ€™s the catchโ€”he doesnโ€™t have any experience with native mobile development. One day, his boss sent him a list of new requirements for the app, and let me tell you, that list was impossible to fulfill! Dave felt like he was up against a mountain.

Daveโ€™s Impossible Challenge and the Search for Help

But Dave, like many of us, needed to figure it out. He had to satisfy his boss and not lose his job. So, Dave did what anyone would do: he started searching for help. The React Native ecosystem is thriving, and there are so many modules available, like Expo Video or React Native Video for handling media, or libraries for charts and 3D graphics. But hereโ€™s the kickerโ€”every project is unique. Sometimes, what sets your project apart is doing what others wonโ€™t. Thatโ€™s where Dave found himself stuck, staring at a blank search result screen.

When Panic Hits, Is Native Code the Enemy?

Itโ€™s in these moments that most developers start to panic. Native tooling and unfamiliar workflows can be intimidating. But hereโ€™s the real question: is there anything to be afraid of? The truth is, writing native code isnโ€™t as scary as it seems. Itโ€™s just like everything else. And today, Iโ€™m here to show you that even if youโ€™re new to native mobile development, itโ€™s not the challenge you think it is. You can build your first native moduleโ€”today.

Hi, Iโ€™m Lukash, and I work at Software Mansion on Expo. So letโ€™s get started. The best advice for diving into native module development? Start by searching for help. Youโ€™ll quickly learn that there are three key parts that make up a native module: a static specification defined with TypeScript or Flow, a conversion layer between JavaScript and native code, and the module implementation itself. Sounds complex? Let me break it down. On the slide, you can see a simple spec for a module with one methodโ€”add. We use a tool called CodeGen, which takes this spec and creates a bridge between JavaScript and native code. Once thatโ€™s done, the final piece of the puzzle is implementing the native code, which could be in Objective-C for iOS or Kotlin for Android.

TurboModules Sound Scary? Letโ€™s Simplify It

Now, I know what youโ€™re thinkingโ€”does this mean youโ€™ll have to deal with all that C layer complexity? What if the APIs differ across platforms? These are all valid questions. But if you still think native development sounds too complex, donโ€™t worryโ€”thereโ€™s a simpler way. Meet the Expo Modules API. This API was built on top of JSI, which means itโ€™s as fast as TurboModules, but with modern languages like Swift and Kotlin. You wonโ€™t need additional tools like CodeGen, and itโ€™s optimized to speed up your development process.

No Live Demo? No Problem! Letโ€™s Build a Clipboard Module

Normally, this is where Iโ€™d do a live demo, but you know how things go with live demosโ€”something always blows up. So today, weโ€™ll stick with slides, and Iโ€™ll walk you through building a simple Clipboard module on Android. First, we define a class. The name isnโ€™t critical, but itโ€™s always a good idea to choose something meaningful. This class extends the Module class, which gives us access to helpful features like sending events. We need to override the definition function, which describes the module and its components. Hereโ€™s where we export our first function to JavaScript, using async syntax. From here, we can access the native clipboard through Androidโ€™s Context.

Context Is King in Native Modules

Now, whatโ€™s Context, you ask? Think of it as a big toolbox with everything your app needsโ€”services, hardware sensors, you name it. But context isnโ€™t always available, so we handle that by throwing exceptions that promise rejection instead of crashing the app.

When Errors Donโ€™t Mean the End of the Road

Error handling is crucial, and at Software Mansion, weโ€™ve created common exception patterns to make things easier. So when something goes wrong, we can simply throw an exception without crashing the app. Itโ€™s all about graceful error handling.

Building Native Modules Is Easier Than You Think. Now, back to our module. After retrieving the clipboard data and converting it to a string, we handle different data types like plain text and HTML. And guess what? You can switch between asynchronous and synchronous functions easily.

Expo Modules API: Whatโ€™s Next?

We did it! Weโ€™ve built our first native module. And it wasnโ€™t as daunting as it seemed, right? But thereโ€™s more! The Expo Modules API has a lot more to offerโ€”like TypeArrays for video or audio processing and even JavaScript prototypes for creating object-oriented APIs. Want to define native views? Expo makes that easy, too, allowing you to reuse definitions across platforms without changing a thing. Talk about efficiency!

Create Your Own Expo Module Today

If youโ€™re ready to dive into native development, itโ€™s simple to get started. Run the command npx create-expo-module, and youโ€™ll have a fresh project set up and ready to go. Already working on a project? Use the local flag to add native functionality.

The Expo Modules API isnโ€™t just for us at Software Mansion. Developers from all over the world are building fantastic packages with it. Be sure to check them out, contribute, and share your ideas!

Letโ€™s Keep Coding Together! Thank you so much for listening today! If you have any questions, feel free to reach out on GitHub or Twitter. And rememberโ€”native development is within your reach.

Subscribe to Our Newsletter

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.
Insight
Building Production-Grade Video Thumbnail Scrubbing in the Browser: HLS, Frame Extraction, Caching, and Performance Trade-offs
Sep 7, 2026

Building Production-Grade Video Thumbnail Scrubbing in the Browser: HLS, Frame Extraction, Caching, and Performance Trade-offs

This blog explains how to build responsive video thumbnail scrubbing in the browser for local files and HLS streams, covering frame extraction, caching, and performance trade-offs.

Insight
No More Prompt-and-Wait: Building Autonomous Agents That Act | Kamal Shree
Sep 4, 2026

No More Prompt-and-Wait: Building Autonomous Agents That Act | Kamal Shree

Kamal Shreeโ€™s Geekconf miniโ€™s talk explores the shift to autonomous agents, from what separates agents from chatbots, the anatomy and grounding behind them, and how to choose between no-code, low-code, and pro-code build paths.

Insight
From UX to AX: Designing Applications for a World of AI Agents
Sep 4, 2026

From UX to AX: Designing Applications for a World of AI Agents

Learn how Ashita Prasadโ€™s thegeekconf mini 2026 session explores agentic experience and three approaches to building agent-ready applications: Web MCP, MCP Apps, and A2UI.

Insight
Agentic AI: From Copilot to Autopilot | Naveen Kumar Bhansali
Sep 4, 2026

Agentic AI: From Copilot to Autopilot | Naveen Kumar Bhansali

Learn how Naveen Kumar Bhansaliโ€™s thegeekconf mini 2026 session explores AI-driven software development, context engineering, enterprise adoption, agentic workflows, and the shift toward building products for AI agents.

Insight
Agentic Commerce: What Happens When Your Agent Tries to Spend Money? | Roopasree Ranganna
Sep 4, 2026

Agentic Commerce: What Happens When Your Agent Tries to Spend Money? | Roopasree Ranganna

Learn how Roopasree Rangannaโ€™s thegeekconf mini 2026 session explores agentic commerce, delegated payments, trust, identity, mandates, and the systems needed to enable AI agents to transact.

Insight
The Agent Can See Your App. How Often Can It Look?
Sep 4, 2026

The Agent Can See Your App. How Often Can It Look?

AI coding agents can now interact with mobile apps, but their effectiveness depends on iteration speed. This blog explores how React Native architecture influences feedback loops and AI-driven developer productivity.

Insight
Building Interactive Cards from Design JSON Without Killing Your Feed: Overlays, Video, Mute/Unmute, and Lag-Free Lists
Sep 1, 2026

Building Interactive Cards from Design JSON Without Killing Your Feed: Overlays, Video, Mute/Unmute, and Lag-Free Lists

Learn how to turn design JSON into interactive, video-enabled cards using overlays, smart media controls, caching, and virtualization without slowing down high-cardinality feeds.

The Right Conversation Can

Save You Six Months.

Book a call