09 March 2019

Maximally Cross Platform with React?

Once upon a time, going cross platform meant making an application that ran on both Macs and Windows, and maybe Linux/Unix if you're into that crowd.

Now everything is fragmented and compartmentalized.  Consider what "platforms" there are now for making apps:

  1. desktop web browsers --- i.e. Chrome, Firefox, Safari, vs Edge --- further divided by Macs, Windows, and Linux (at least for browsers that are cross platform, ha!)
     
  2. mobile web browsers --- i.e. iOS vs Android --- further divided by phone vs tablet display sizes
     
  3. Electron desktop apps --- i.e. Macs, Windows, vs Linux (built with web browser technology)
     
  4. native desktop apps --- i.e. Macs, Windows, vs Linux
     
  5. native mobile apps --- i.e. iOS vs Android --- further divided by phone vs tablet display sizes
Some of the above differences are a matter of building user interfaces sized for use on that display size, while other differences are a matter of framework (e.g. Cocoa vs Android SDK).

But at worse, that's still 26 different platforms to build for!  There are technologies that help bridge the divide, and one family of such tech is called React.

Here's a survey of some React based technologies and which platforms they work well for.




React or ReactJS is the starting point, and everything else listed on this page is built on it.  It's a JavaScript library for building user interfaces for web browsers.  That'll let you build apps for desktop web browsers, mobile web browsers, and also let you build Electron desktop apps.

React Native lets you build native mobile apps using JavaScript and React.

React is not a "write once, run anywhere" solution though: it's "learn once, write anywhere".  Your React Native apps cannot simply be recompiled for the web; and your React apps cannot simply be recompiled into native mobile apps.  Although, that'd be nice?

The above two are strong production ready projects driven by Facebook.

React Native for Web allows you to write React Native components and APIs to run on web browsers.  It's not write once, run anywhere, but this will get you closer to writing once to run on desktop and mobile web browsers, as Electron desktop apps, and compiled to native mobile apps.  The only thing missing is compiling into native desktop apps.

Well, not the only thing missing, as it's documentation shows a Compatibility with React Native chart showing some things are missing.  This project looks pretty active (12000+ stars) and I heard (here) it was started by Twitter, and it's used in production by Twitter and Uber, amongst others, apparently.

Microsoft/react-native-windows lets you write React Native and compile into native desktop apps with UWP and WPF, which includes all modern Windows environments (Windows 10, Xbox One, Windows Mixed Reality).  It's a Microsoft project, and they're known for being developer friendly.  Looks solid.

ptmt/react-native-macos lets you write native desktop apps for Mac OS X Cocoa.  It's an experimental fork of React Native for iOS.  So on the one hand, it's experimental, and on the other, it's based on React Native for iOS so should be okay.  Pretty active project (10000+ stars).  I don't see any corporate backing, for better or worse.

status-im/react-native-desktop lets you write React Native and compile into native desktop apps driven by Qt.  If you must get a native app on Linux, this might be something.  Project isn't very active in comparison to the above (600+ stars), but it was forked from Canonical (what happened to Canonical's though?) for better or worse.  Anyone know if the licensing issues with Qt is an issue here?

Too bad there's no React Native for GTK though.

Microsoft ReactXP finally lets you "share most of your code between the web, iOS, Android, and Windows".  It supports React Native, letting you deploy native mobile apps for iOS and Android.  It supports React, making apps for desktop and mobile web browsers, and also Electron desktop apps.

So far it's support is like that of React Native for Web above.  But ReactXP does one better by providing React Native support for Windows 10 / UWP, which includes all modern Windows environments (Windows 10, Xbox One, Windows Mixed Reality).  It's a Microsoft project, and they're known for being developer friendly.  Looks solid.

The only thing missing is compiling into native desktop apps for Macs and Linux.  Lack of Linux support is a known issue, and will probably never occur until a React Native for GTK appears somewhere (so probably not ever likely), but at least you can build native desktop apps for Linux via Electron.

Lack of Mac OS support is also a known issue.  Oddly, apparently ReactXP does have Mac OS X support experimentally, as reportedly the core is there and is apparently close to being production ready.  In fact that issue was closed in 2018 February because they said "MacOS support is now (mostly) implemented".  If that's true, that would be amazing.

No comments: