Developing Our First iOS App with React Native
code.hireart.com
code.hireart.com
Objective-c is quirkier than most, swift is nice but still baking, but it really all boils down to the platform APIs. And you're gonna have to get wet at a platform level if you want to provide functionality beyond a mobile web page. (Albeit one with improved load times since it's coming from disk, at the cost of dynamic updates since it's coming from the app store.)
Like how do I open a file? Ok cool. How do I close it? Do I need to explicitly close it? Ok.
Also, learning APIs for other peoples codebases/software is task of learning that isn't trivial too
These abstractions on top of the platform might make it easier for quick prototypes if you don't have time to learn the language. But you'll lose some flexibility, power, visibility and community. After a while the initial speed benefits wear off since the language is a small part of the things you have to stay on top of, especially if the app takes off.
We should graph every programming language on a radar chart using those axes.
Except Haskell. I can do the trivial stuff, but anything non-trivial is a chore to learn. It is not as if it has a learning curve, it has a learning brick wall that hits you very early on.
C# has had Linq for lazy evaluation of data collections for many years.
Javascript supports observables now and ot's only a matter of time before they're included in the official spec.
Reactive Extensions has been extended to many different languages now.
Lisp macros are essentially higher order function definitions. They can be trivially applied using decorators in Python and closures in Javascript (JS decorators will be supported in ES7).
Definitely not. Lisp already has higher order functions. Macros are something entirely different.
> They can be trivially applied using decorators in Python and closures in Javascript (JS decorators will be supported in ES7).
Of course not. Decorators and closures are in no way related to Lisp macros.
There is enough literature about Lisp macros... For example a certain Paul Graham wrote a book explaining them in detail:
> C# has had Linq for lazy evaluation of data collections for many years.
> Javascript supports observables now and ot's only a matter of time before they're included in the official spec.
> Reactive Extensions has been extended to many different languages now.
These things are quite different from having pervasive laziness, though.
Of course you can mitigate that with RxSwift, but it only goes so far.
if you can use react native and avoid learning a lot of this it is a big win - I havnt used it yet, and I have a hard time believing it a mobile only company would use it to build their mobile app, but i am excited where it is going.
Delegation has been a standard feature of desktop APIs for decades. Not just on things like Smalltalk and ObjC -- it has been the standard .NET model for UI events since C# 1.0.
The delegate thing is an iOS thing. Android uses a totally different pattern. I mean, there are delegates, to be sure, but android loves their anonymous inner classes in many of those cases. (Which is closer to idiomatic js IMHO.)
So on a language level sure, easy peasy, you could delegate in javascript all day long (and you do). But on a platform level, nuh-uh. One is going left and the other is going right. How do you meet in the middle? What fine line gets scrubbed in between?
Except Objective-C (and Swift) had protocol conformance. Though come to think of it TypeScript allows you define an interface for a Component, one of those attributes could be a function.
Not really getting away from it. ;-)
As far as React Native, I can't see it being used seriously. I think teams are going to have to know native iOS and/or Android programming anyway.
But seeing the mass of apps that never live beyond a year, maybe React Native is just the thing.
A 4th category is probably needed for statically compiled, garbage collected, OOP languages.
The reality is, most/all of the most popular languages blur the lines.
Javascript is getting official support for OOP as well as better support for functional programming.
C# has good support for dynamic typing as well as many functional characteristics.
High performance Python has always had the ability to delegate to C extensions.
Etc
Obj-C, Obj-C++, C++, and C can all co-exist in the same codebase and be complied into 1 output (if you are insane enough to try), similar to CUDA or Fortran with C/C++. That's not really possible with JVM or CLR languages, but not impossible either. Which makes them more like 3GL/OOP while sharing more similarities with smalltalk than 2GL/C.
Py, Lua, GLSL/HLSL, and many others can "mix" or be called by C/C++ similar to CUDA, and Lua is definitely in the interpreted "script stuff" bucket, not statically compiled like Java, C#.
The shader languages like GLSL/HLSL are really confusing to categorize, especially when used with C#, because they can exhibit characteristics of 1GL thru 4GL.
XLST and other template syntaxes are another interesting case. They look mysteriously like a declarative context-free language but have imperative characteristics of a turing complete syntax.
JVM may not be able to be combined with compiled languages but there are a number of languages that, at a bytecode level are compatible with Java. For example IronPython, Rhino, etc. The same can be said for the .NET environment and languages like VB.NET, managed C++, C#, F#, etc.
Don't even get me started on languages that can output output Javascript. Last I heard, there's over 100 of them now and the list keeps growing.
I'm not sure about GLSL/HLSL because I haven't used them but they sound like they're declarative DSLs (Domain Specific Languages).
Maybe it's about time somebody created an update to the Chomsky hierarchy. Instead of the traditional subset-superset classifications, some other system is used to compose the characteristics of languages.
In the bigger picture of things, it's all very incestuous. Like every language is trying to be like every other language. The winners of the pack are those that everything else compiles/transpiles down to.
Our general product iteration strategy involves building it on the web version and then porting it to iOS fairly quickly. For a chat application, our stores handle a lot of data, so it's been awesome to have that code shared.
React Native's bridge is also alright. We bridge with Component Kit for the chat messages view & WebRTC for the voice side of things fairly easy from JS.
Also, being able to update the bundle w/o doing an App Store update is pretty big too.
Here's the app if anyone wants to try it: https://itunes.apple.com/us/app/discord-chat-for-gamers/id98...
I didn't play on-line for years, last time I did regularly, the standard for voice communication was Ventrilo/Teamspeak. When I first used Discord a couple of months ago, I was just shocked. It has a decent webapp. I can create my own server for free. It takes less than a minute to get going. It just works.
Truly amazing work, keep up
Did you encounter any such problems?
This write once, use everywhere is such a strange desire.
If you're a serious company, develop on iOS/Android first, then hire a dev or two to make an exact copy for the remaining platform. It's really not that hard.
The hard part is doing something the first time and iterating. Copying is not rocket science - look at the Russian facebook clone - it's actually better because of copyright laws, you can do more on their version.
Duplicate effort does incur a real cost in terms of time to delivery. Duplication is a clear sign of inefficiency. A platform that provides native support for multiple platforms reduces such duplication.
The maintainance cost of providing multiple platform-specific implementations compounds over time. For every feature added there's a chance that subtle differences will be introduced. In a perfect world one platform developer will have an equal level of skill and understanding as a developer for another platform. In practice, there's no guarantees that both versions will be kept in sync. The differences and abstraction leaks become technical debt and accumulate as the platform grows/changes over time.
Now, lets say you want to provide a web, iOS, Android, and Desktop interface for a platform. Would you choose to do 4 independent implementations in 4 different languages. Or 1 in a single language with platform-soecific differences?
Platform duplication is a violation of DRY at the system level and incurs the same problems of diplicating code, at a much larger scale.
The Russian Facebook is basically a independent fork. It's not required to remain feature-complete and in sync with the official Facebook platform.
I am saying that trying to re-write the layout engine, data layer and all the rest to make it work the same on both platforms is not only a massive undertaking - it is ignoring the reason the platforms diverge to begin with.
iOS has features Android doesn't and vice versa. Something that works on both platforms is always going to be a second-class citizen - it's the lowest common denominator.
I don't want the lowest common denominator because it's 'easier for developers'. I want the best stuff.
The theoretical technical debt due to writing on different platforms is why we have software architects and senior developers.
Really, I've been part of a dev shop that does ios/android - the biggest hurdle is people problems, not code. People who don't know what a good app is or have any taste so they say first show me, then I will start asking for changes at random while insisting on a tight deadline.
As for web/ios/android/desktop - this is a rare bird, if you need to support that many platforms, you can afford an architect and some smart people.
The view rendering layer is the part that is specific to each platform and the React community provides web components that work natively on each platform making the development process between mobile/web more consistent. Mobile provides an escape hatch to write platform specific code in the native language.
"As for web/ios/android/desktop - this is a rare bird"
Targeting all, will remain very unlikely. Targeting more than one is pretty common. React and Angular2 are pushing hard to enter the mobile development ecosystem. Microsoft has been pushing for Typescript usage on the desktop and just picked up Xamarin so we'll likely see desktop or web or mobile hybrid applications at some point in the future.
If the barrier-of-entry to support another platform is low enough, it'll make sense to do so. In the current ecosystem, supporting even 2 platforms is a massive undertaking.
I am so flabbergasted that I took the idea seriously, looking at what it actually is, it is so clear to me that this is not going anywhere.
For starters - using Javascript when you could be using Swift/Objective-C is laughable. That's a non-starter. Then, there is no real data layer at all! You have to interface with Objective-C!
So what is the point of using this at all? To have shared view layer logic? Facepalms
Facebook is using RN in production. So I doubt it.
> Then, there is no real data layer at all! You have to interface with Objective-C!
I don't get what you mean. You don't have to interface with any native code if you don't have a very specific need to use a platform specific feature which is not available in RN.
> I just spent 5 minutes looking at React Native and my first and final impression is that this is a complete waste of time.
If you spent just 5 minutes, it clearly means that you don't have enough experience with React Native, and I don't think you should give opinion on anything without at least being familiar with it. I've been working with React Native for months, and yeah, there are technical hurdles. But I'd say the same for Android, or web (I don't have any experience with iOS dev).
There are parts of React Native that suck. But there parts which are amazing. Amazing enough that I'll choose React Native over Java/Obj-C any day. The development speed with React Native is much faster than native Android dev. The DX is getting better day by day.
I get to share code isn't the primary reason why I love React Native, but it's an important thing for companies which want to support multiple platforms.
I'd say let's focus on fixing the parts that suck in React Native, rather than discarding a new tech without even trying it.
Please tell me you're not using a library that's at 0.20 for production.
So you're using ReactNative for pet projects right?
As soon as you get to writing a real app that's beyond a to-do list, you'll be in a world of pain. Just start with having no support for a sqlite/database or an orm layer on top of it, only a key-value store as your first massive and insurmountable stumbling block.
I'm using it in production. And so is Facebook.
No, it's not a pet project, and much more than a TODO list app.
I think it's important to understand that React Native is not an attempt to replicate the entire iOS native framework - it's a set of UI components that aim to provide a better developer experience for the common app development challenges we face at FB, combined with a framework for building new components.
When we encounter an uncommon challenge (i.e. something that we haven't already had to solve and build a reusable JS component for), we simply drop down to the layer underneath and create a new native component.
That's why I struggle to understand the argument that "React Native doesn't do this one thing I need, so I can't use it" - we put a lot of thought into the plugin architecture of RN, and making native plugins is trivial for anyone familiar with iOS or Android development.
If there is something you already know how to do natively, you can leverage that knowledge to build an RN plugin and then get the best of both worlds. If you don't already know how to do it natively, there's a good chance that someone else already made a plugin that will do what you want.
What's most amazing to me about React Native was how quickly we were able to go from idea to product (~3 months working only part-time) using our existing knowledge as web developers. We did have to write a few lines of Objective-C here and there, but for the most part all of the views and interactions fell together the same way a webapp would.
I've seen the Facebook post about developing Ads Manager (though it glosses over some details), but it would be interesting to hear other people's experiences.
https://code.facebook.com/posts/1189117404435352/react-nativ...
Hard to say how much of it was platform-specific, since we only targeted 1 platform (for now). But the large majority of the code we wrote exists in React components or in related JS files, so porting it over to Android should be a matter of decoupling the parts of the code that rely on native features (i.e. camera, navigation, etc).
A lot of that work is already happening in the React Native community so I expect the cross-platform support will keep getting easier.
In my experience they all fall short when you try to get the last 20% of your app written. Because you're not writing in the native language, directly accessing native API's, you're always going to be limited to the abstractions that the hybrid framework has (or hasn't) defined.
I much prefer either going full native or full HTML5 because I never hit a wall when I try to do something that hasn't been covered well by the hybrid framework yet.
I did a little reading and it appears that React Native, Appcelerator, and Xamarin are pretty close to feature parity.
I don't feel like I'm unique in this.
I think this "synthesis of both approaches" has merits.
I wish Android would make something granular (and understandable) or at least let me disable permissions after the fact.
I think that webviews get a bad rap because you only notice then when they're done badly.
Still have the icon on my homescreen, still get the same notifications -- the main difference is how much better my battery life is now!
Every cross platform mobile framework in a nutshell.
Something is broken
I think this is a key phrase here. I'm writing a RN Android app without knowing much about Java.
There is also a lot of react-native npm packages that abstract away the hardware issues, quality & completeness varies however.
To quote the author: "We're web developers, not iOS developers." EXACTLY, don't bring your web tech into native platforms, learn to do it the right way or just hire someone who knows how to do it.
Seeing things like that creeping into becoming a norm makes me cringe
By the "right way" I mean use every language for its intended purpose, you can't build desktop apps in browsers, that's why we have Javascript. and i'm saying we should keep it that way
Railing against React Native seems like railing against Unity3d, or saying that abstracting the common parts of mobile development (while leaving the non-common parts 100% available) is a bad thing.
By the "right way" I mean use every language for its intended purpose, you can't build desktop apps in browsers
You can build desktop apps in browsers (ie emscripten). Additionally, can you explain why a "language" (as compared to platform specific APIs) has any relevance to what can or can't be built for a mobile device? For JavaScript specifically, if Apple didn't think that it was a language for building applications on iOS, then why would they ever have release JavascriptCore (which is what React Native uses)?
I think you're fundamentally not understanding how React (not just React-native) works.
This is happening.
What is the right way? Native only?
There are many apps in the appstore that uses html5 and users of the app don't care how is it build.
I got flamed for my rant.
Having built 3 non-trivial iOS apps using phonegap and JavaScript. I have come to the conclusion that I'm never going to build native apps using web stack. I have struggled with API support, DOM limitations and performance.
Disclaimer: I have not tried react native.
I think it'll fail for mission critical and non-trivial apps. If you just want an AppStore presence for your browser app or your app is trivial like one in the post. You are probably going to be fine.
p.s. I've explored JavaScriptCore the first day it was available to developers.
p.p.s. I noticed you are a "React fanboy," so that's normal.
Please don't get me wrong, I'd love to use ECMAScript(, CSS and markup) to do all web, native and server side development. Unfortunately they are marred by poor API support, performance and customization. Last two are extremely critical for non-trivial apps.
If you are building run of the mill simple apps like - news feed, photo, video and reading etc. You'll be okay with anyone of the above 'web stack'.
Here's the litmus test. Ask the Reactive Native team to port their non-trivial paper app or mission critical messenger app or main app to Reactive Native. They are using Reactive Native for a lame duck Groups and some ad manager app.
JavaScriptCore is one layer deeper than wrapping a UIWebView, but it's several layers from true native.
Facebook is rewriting the News Feed in RN. That's not a trivial example.
"Some ad manager app" which happens to be the ad manager for one of the largest advertising platforms on the planet right now. It's also composed of non-trivial UI, you should try it before blindly bashing it. I've used both Cordova, and Titanium, too, by the way - Cordova was relatively painless but lacked the native feel. Titanium sort of had the native feel but it was slow. The Titanium community also felt very hostile towards competition and they didn't promote FOSS. Maybe you're a Titanium developer?
> Unfortunately they are marred by poor API support, performance and customization.
Web apps can hit 60fps these days (again, using React (Canvas)).
> Here's the litmus test. Ask the Reactive Native team to port their non-trivial paper app or mission critical messenger app or main app to Reactive Native.
That's a really lame litmus test considering they've got a massive code base in native languages with no reason to throw them away since they're working perfectly and they have a ton of developers to throw at the problem.
> They are using Reactive Native for a lame duck Groups and some ad manager app.
They appear to be using React Native for most new apps that they develop. I would assume it would be up to the discretion of the team to choose whether or not to use React Native. Most do because React Native is way better than plain old native. Even the author of UIKit thinks so.[0]
I'd be interested if you could provide a common real world example where React Native wouldn't be a good fit.
Furthermore, React Native never claims to be a total replacement for native. We openly acknowledge that some problems are best solved in native code. That's why React Native has excellent support for 3rd party modules.
[0] https://twitter.com/andy_matuschak/status/560511204867575808
Let's say I don't have any real world examples. I'm not seeing any engineering marvel in React Showcase. https://facebook.github.io/react-native/showcase.html pales in comparison to http://phonegap.com/app/
Bonus if they are free.
I used this in the 90s, and it was ridiculously easy to get write an application. You visually designed your UI, generated code, and then added your actions/event code. It was straight forward. I haven't seen anything come close. Sure it was limited, but for the small apps I want to write for Mac and iOS, it would be perfect.
Boy are you in for a treat!
Sure, what kind of app are you writing ? games ? a video player ? a messaging app like Telegram ? a background activity on Android ? of course if it's a basic CRUD app, you're not going to notice the difference. try to make a 2D or 3D game with Cordova and see how it runs. The question you should ask yourself is, do you need a webpage in a native-shell at first place when you could just develop a website.
We did not have chump change for developers either - I've numerous contributions to Angular and Ionic, and one of my former co-workers when I was there is now on the Angular team.
React Native is a superior abstraction, since it allows you to hook directly into native components very easily (try writing custom Cordova plugins), and keeps high level logic in JS.