If you’re into mobile app development, the name of React Native mustn’t be new for you. The term has been trending in the world of technology for quite some time now. Since Facebook formally launched it as an open-source platform, a lot of businesses have already incorporated it into their process.
Just like any other origination, React Native comes with its own pros and cons. Despite the fact that professional web developers still prefer working with the native tools, there are a thriving number of budding developers who’re considering React Native for their projects.
This post is targeted to highlight the theoretical as well as practical aspects of using React Native in comparison with the Swift. To make this comparison, we have two almost identical apps in both frameworks (please check out details at https://github.com/weblab-technology/swift-honors-app
My objective was to keep these apps as simple as possible so that it would be easier make a fair comparison in between important aspects of both the platforms. Below you will find a detailed analysis of the apps developed in Swift as well as in React Native in terms of CPU, GPU, and memory consumption. So let’s explore!
Swift vs React Native
Okay, so this app involves Facebook login, Facebook profile recovery, Database recovery, and Tab Bar Controller. I’ve codified the similar app in Swift as well as in React Native and will be using a real device to assess the performance of these apps . My objective is to equate them against each other to observe which one platform performs better.
Unlike other languages, Swift is comparatively easy to work with, especially if you compare it to what we had before with Objective C. The XCode is surely a state-of-the-art application and it makes developing a whole lot easier when combined with the Swift.
The React Native
It’s time now to stack these apps against each other to conclude which one’s a better option. As mentioned earlier, I’ll be using a real device coupled with an XCode to test these apps. The three categories I’ll be focusing on would be CPU, GPU, and Memory consumption.
React Native app were lagging more than swift when I was resizing and dragging map.
Swift application used less energy in total during the same testing than React Native app according to the Energy Usage Log.
All in all, there are 4 tabs in my app — Facebook login, To-do list, Page view controller, and Maps.
Swift vs React Native — CPU Usage
Let’s review each category individually…
- Facebook Profile
With 1.21% difference in CPU measurement, React Native is slightly more efficient than Swift in terms of CPU usage.
2. To-do List
For the second tab, React Native with 0.66% efficiency is a winner again. While doing the task, spikes in CPU consumption were recorded at the exact time I included/deleted an item to/from the list.
3. Page View
Swift is a definite winner for this tab with 5.55% greater efficiency than React Native. While doing this task and noting down measurements, spikes in CPU consumption were recorded at the time I jumped to another page on Page view.
With 9.7% more efficient usage of CPU, Swift wins this category again. Noticeably, while doing this task, a spike in CPU consumption was recorded at the exact time I hit the Maps button.
So we have 50–50 result for Swift and React Native here. All in all, Swift was slightly more efficient than React Native in terms of CPU usage. The outcomes may have been otherwise if I granted myself enough time to test each app. interestingly, the CPU wasn’t used at any moment when moving from tab to tab.
Okay, so the next analysis we will be doing would be of the GPU measurement. I will do one task per button for each paradigm and note down the results. The vertical axis goes up to 60 frames/second and I’ll be using ‘Core Animation’ tool to assess the results.
Let’s go over each category to check the results
- Facebook Profile
With 1.08 frames/sec measurement difference, Swift marginally wins this tab. The results were observed exactly at the time when I pressed the ‘Log in with Facebook’ tab.
2. To-do List
React Native barely wins this tab by running at 6 frames/sec higher than Swift. The measurements were observed exactly at the moment of adding/deleting items to/from the list.
3. Page View
Swift outperform React Native with 1.37% frames/sec for a Page view tab. While performing the task and noting down measurements, I noticed that the frames/sec elevated up to the 50s when I try to speedily move through the pages.
Swift is a winner here since it runs at 3.6 frames/sec higher than React Native. The measurements were recorded at the exact time when I pressed the ‘Maps’ button.
With 3–1 result, Swift is clearly a winner here.
It’s time now to compare Swift and React Native in terms of memory measurements. I’ve done single task per tab and plotted the graph with memory (MiB) on the y-axis. The sample interval for CPU consumption is 1ms.
- Facebook Profile
Swift is the winner of this category with 0.07% MiB less memory consumption. A spike in memory was recorded at the moment I hit the ‘Log in to Facebook’ button.
2. To-do List
React Native outperform Swift in this category with 0.35% less memory usage. The spikes in memory consumption were recorded at the time when I included an item to the list. There was a decline in memory usage when I deleted an item from the list.
3. Page View
Once again React Native surpasses Swift this time by showing 0.07%MiB less memory usage. There was no memory spikes observed while toggling between the pages.
React Native again is a winner here by beating out Swift with massive 36.02 memory usage for this category. While doing this task, a spike in memory was recorded at the exact moment I pressed ‘Maps’ button.
I would say here that even if Swift is using more memory on average, which is true, memory would be managed better when the app grows. In addition to that, the results may have been entirely different if I granted myself sufficient time in each app instead of just concentrating on a single task at a time.
My Preferred Platform
Well, the apps I developed for React Native and Swift are nearly similar in their physical presentation. Moreover, it’s clearly evident that both of these apps somewhat function in an identical manner. I can conclude from this experiment that although React Native performed better in the memory category, Swift employs the CPU and GPU of the iPhone quite effectively. In conclusion, we can say that React Native is quite close to Swift, which is great. However, with 2–1 win ratio along with a high potential for memory, Swift is a definite winner here.
What Makes React Native So Popular?
React Native — Pros & Cons
Shared Core Advantage
While talking about the web apps, React manages to set up a React paradigm along with refreshing the Browser’s DOM. However, when it comes to mobile applications, things get demanding when it’s inescapable to manage a number of tree models over diversified platforms. Well, if you keep on adding more and more responsibilities on React’s shoulders, you could not expect anything but a disaster in the end.
An All-Inclusive Platform
Have you ever thought of preparing a whole recipe with a single ingredient? Similar to that, it’s not possible to build an entire application with just React alone. Definitely, you’d require webpack for devising the code, CSS to do styling, a Firebase for data maintenance and plenty of other things.
Well, if your scope of work is limited to web development only, React alone can be sufficient to meet the purpose. However, if you also deal with mobile app designing, it becomes insignificant to add a complete bundle of tools that can be employed to work in the similar way as the React. That’s why React is a library and React Native is a framework.
What React Native Offers?
- The New React
- Contributors for Android and iOS
- Flexbox for styling the user interface
- Different widgets and animations
- And much more
Thus, React Native is an exhaustive platform as it incorporates all you require to create a fully functional app. While the original React only takes care of web UI and you’ll require adding other relevant parts yourself to build a full web app.
Have you ever thought why React Native is called ‘Native’? That’s because the user interface constructed with React Native comprises of native widgets that not only functions flawlessly but also feel consistent.
React Native offers a number of integrated components that enable developers to carry out basic tasks quickly and effectively. Some of them include:
Text: Used to show text
View: Used for designing a user interface
Text Input: Enables users to enter text
For example, you can create a basic button in Native base by using the following source code.
Although React Native supports a vast variety of APIs, there’s still a requirement to use other APIs through native modules. These modules are basically segments of the codes penned in the native language and then included into the remaining code. Undoubtedly, it’s a great way of resolving the issue, but it needs you to have sufficient proficiency about the native language and its tools.
Android and iOS make use of different design guidelines, which apparently means that by using React Native you have to include plenty of if-statements along with separate coding to stack up against the placement of graphical elements. In addition to that, creating high-quality custom UI is also exhausting in the React paradigm and I was compelled to write and include swift libraries while developing this app.
This is the biggest setback for me. If you’re planning to develop a complicated app such as an image/video editor, React Native isn’t a good option for you. However, if your project is relatively small, you could save some time by sharing parts of your code (Yes, parts only! Code isn’t completely reusable and you could only use 60% of code for Android. It works better with iOS though….)
Native — Pros & Cons
No APIs Limitations
What makes native truly functional is the fact that you can access all of the APIs via native environment. You don’t require an additional layer mapping either that needs to be updated.
Variety of Resources to Choose From
Development in a native environment gives you an opportunity to access a lot of third party libraries. By doing so will help you create more functional apps with improved development experience.
While working with React paradigm, the factor of uncertainty is always there. Real Native, on the other hand, is the safest possible choice for developers in the long run.
The Requirement to Develop Two Separate Applications
Platform specificity is certainly the biggest disadvantage offered by the native platform. You have to develop separate codes for Android and iOS and no code can be shared between them.
Comparing React Native with Real Native Apps
How to Create a React Native App
Whether you’re building an app for iOS or Android, you need insight of three important things
- The preferred programming language
- Suitable tools
- The Application Programming Interface (API’s)
Building a Native Android/iOS App
Objective-C and Swift are required languages to build a native app in iOS. For Android, you need to acquire proficiency in Java though. In terms of tooling, you’ll require to employ individual platform’s IDE as well as take in how that IDE and the relevant debugger can help you build the system.
Although web development forms a basis for React Native, there’s no specific reference frame in Android or iOS development. Not to forget these are genuine native platforms and you must have the knowledge of the prerequisites associated with these platforms.
Frameworks on the other hand aren’t an exception either. You require to become versed about how everything can be accomplished programmatically. In short you need to be a real programming freak to work with a native environment for building apps.
Which One’s Easier to Learn?
All the other languages, on the other hand, come with a concept of compile time analysis which wipes out many possible errors.
React Native vs Real Native Apps — Conclusion
Great! We’ve reviewed quite a few important things until now. Choosing React Native over Swift depends on your personal preferences and requirements. I’d say if your app isn’t complicated and doesn’t need to include comparatively latest features like, complex animations or iMessage, you should opt for React Native initially.
And even if your requirements are complex, but you’re an iOS or Android expert and also acquire some web development exposure, React Native can make a good choice as you’ll possibly fix everything you need to.
However, if you’re an entrant in the world of development, I’d recommend launch on a single platform employing its native language in the beginning. Observe how it works. Then approach to the other platforms.
Do you really think React Native is the future of hybrid app development? Which platform do you think is more practical? Please drop your feedback in the comments section below and let’s discuss!
by Oleksandr Knyga, Software Engineer
Sharmeen Hayat, author & Data Specialist
with help of Andrey Gorobets, Front-end Developer
✉️ Subscribe to Codeburst’s once-weekly Email Blast, Follow Codeburst on Twitter, and ️ Learn Full Stack Web Development.
This content was originally published here.