React Native cross-platform codebase

Facebook said that React Native is based on learning once, writes everywhere, and that its goal is not to write cross-platform code.

NativeScript, which is very similar to ReactNative in the sense that they both use Node.js, offer the ability to share the same code across multiple platforms by writing platform specific code in files that use native components that cannot be shared. , This is done using a simple naming convention, such as foo.ios.js .

Since Facebook has yet to release its React Native code for platforms other than iOS. Is this something they are likely to support in the future?

+3


source to share


1 answer


I think there are too many differences between Android, iOS and the Web, so it doesn't make sense to create a common codebase for all projects. The Android version will not only have its own components, but the logic of the application screens and navigation will be different (iOS / Android / Web all have quite different navigation patterns). Also, iOS / Android projects have a lot of built-in components and they affect how the app is launched / debugged, etc., so it is probably much better to keep the Android and IOS parts as separate projects.

As I understand (and sympathize with) the Facebok model:

Whenever there is a common functionality (in javascript) that you can share without depending on react-native views, they will do it as a separate component that can be reused through the web / iOS / Android interface. For example, they have a relay library built for the web Facebook. It abstracts access to open data on Facebook's servers - the exact same relay library can be used in any environment as it has no view dependency, no application logic and reacts as such.



I very much agree with this approach - the best way to make it cross platform is to follow the same practice:

  • make something work in one of the environments.
  • make it a standalone, single-purpose library with no dependencies to react, view, navigate logic.
  • use the library elsewhere

So an Android and iOS app and web react for the same "project" will always have three different codes, but they can have quite a lot of common javascript in the form of reusable libraries.

+3


source







All Articles