Why iOS developers should try React Native

Web developers are dinosaurs!
— my girlfriend, an iOS developer

Even having spent significant time in Swift and Cocoa, I preferred writing web apps with JavaScript and React. But the future is native and JavaScript is the worst! She told me that React Native feels like an effort from JavaScript devs (i.e. the dinosaurs) to stay alive and relevant.

It's easy to see why React Native feels like an unnecessary abstraction for iOS developers. JavaScript is no Objective-C or Swift. Browsers and websites have never been known for performance. Abandoning Auto Layout and Cocoa for inline styles, Swift for a scripting language, and Cocoapods for NPM?

Give it five minutes

When Facebook released React, it was controversial. XML in your JavaScript? Combining business and view logic?! Years of best practices undone. Yet today, Hacker News can seem full of self-congratulatory React developers. React must have gotten something right.

Now is a great time to give React Native 5 minutes (or more honestly, several hours). Let's dig in why.

React's UI paradigm

The declarative way React makes you think about UI is different and arguably better. You get a taste of this when you use UICollectionViews and data sources. Instead of rendering and laying each cell manually, you declare how each cell should render given its data. The underlying views are handled by the library.

React takes this paradigm to the next level by applying this to every piece of UI code. You write your UI by mapping application state to view components and React takes care of keeping the view in sync.

Even if you end up not using React Native, you’ll be exposed to ideas that may change how you structure your code and inspire you to look at other frameworks like ReactiveCocoa and ComponentKit.

JavaScript

I love Swift. Its design is beautiful and it’s a joy to use. Objective C is fine.

However, JavaScript today is very different than it was 5 years ago. ES6 makes the language a lot more expressive. Flow and TypeScript give you much desired typing. The native APIs (with features like promises and fetch) along with access to NPM make tasks easy.

There is a cost to learning JavaScript and the different APIs but I think you’ll discover a practical language for building UIs. Even if JavaScript is not the best language, no other language lets you learn once and write iOS, Android, and web apps! The potential for code sharing is huge. Work without a compilation step. Push updates to users without waiting for app store approval! The list goes on.

Open source

Have you tried putting an image to the right of the title in a UIButton? It might be obvious to you now but good thing StackOverflow exists. Want to really customize a UINavigationBar? Phew, Google + StackOverflow.

In React Native, nothing is magic.

Wonder how ListViews determine which cells to render? Check out the source. Wonder how views are laid out? Check out the source.

Magic is bad.

Layout and styling

While higher-level components like UICollectionView and UIStackView make it easier, using Auto Layout or manually laying out views can be tedious. With React Native, you’ll find most layouts require a lot less work with flexbox. No longer worry about debugging Auto Layout constraints.

The React Native inline style language unifies APIs and the component nature of React makes building composable UIs the standard. Quickly style text without NSAttributedString. Instead of using UIButton configurators or button factory methods, you create a <Button> component that can be used everywhere in your app. And again, all this knowledge carries to web and Android!

The community

The JavaScript and React community are really alive. A new framework or library comes out everyday. Although it can be overwhelming, there are gems out there that make development significantly better. Similar to how pods like SwiftyJSON and Alamofire make development more enjoyable, the JavaScript community is buzzing with an even larger number of open-source goodies.

Native is not lost

In a React Native world, understanding the underlying systems and patterns is very important. React makes it easy to seamlessly combine JavaScript and native components. In a React Native environment, the most valuable engineers will understand iOS patterns, the underlying systems, and are willing to drop down to native code.

A big hack?

Using React Native for the first time, I couldn’t help but feel I was playing with one big experimental hack. There must be a deal-breaker that makes React Native annoying or unusable.

In many ways, React Native is a hack. Using JavaScriptCore to run all your code. Reimplementing UITableView and UINavigationController in JavaScript. Using Chrome to debug your iOS app.

However, if you approach React Native with an open and curious mindset, you’ll find interesting problems instead of framework failures. You might find that you need to jump into the React Native source for answers. You might even need to make a change to the library. But you'll also feel the power you have and find that everything has an answer.

At first, I was dismissive of React Native. Now, I’m a little too excited and looking for others to join the cult.

I hope you give it a shot. My better half is thinking about it.

_
Read Another

React Tutorial

Curious about React? Try this short and interactive tutorial to learn the high-level concepts of React.

Liked this?

Subscribe

Subscribe for a range of articles from React basics to advanced topics such as performance optimization and deep dives in the React source code.