• Stars
    star
    5,213
  • Rank 7,946 (Top 0.2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Mobile, desktop and website Apps with the same code

Mobile, desktop and website Apps with the same code

Build Status Dependency Status devDependency Status

This project shows how the source code can be architectured to run on multiple devices. As of now, it is able to run as:

  • iOS & Android Apps (based on react-native)
  • a Desktop App based on NW or based on Electron
  • a Website App in any browser (based on react)

A demo for the Website App is available here.

Screenshots

Mobile Apps (iOS & Android)

Mobile Apps

Desktop Apps (NW & Electron)

Desktop App

Website App

Website App

Libraries/tools

This project uses libraries and tools like:

  • es6 syntax and babel
  • react for the Website App and Desktop App,
  • react-native for the iOS & Android Apps
  • NW to package the Desktop App
  • Electron to package the Desktop App
  • flux to organize the data flow management
  • css-loader to integrate the styles in the builds
  • grunt to create the builds
  • webpack to help during the development phase with hot reloading

Basic philosophy

All the code is contained in the src directory, especially the 3 main entry files that are used for the builds:

  • index.ios.js & index.android.js are the ones used to build the iOS & Android Apps
  • index.js is the one used to build the Website App and Desktop App as the code is strictly the same.

Flux architecture actions/stores

All the flux architecture is share to 100% to all the different builds. This means that all the logic and data management code is done only once and reuse everywhere. This allows us to have an easy tests suite as well and to ensure that our code is working properly on all the devices.

Components

The real interest of the project is in how the components have been structured to shared most of their logic and only redefined what is specific to every device.

Basically, every component has a main Class which inherits a base Class containing all the logic. Then, the main component import a different Render function which has been selected during the build. The file extension .ios.js, .android.js or .js is used by the build tool to import only the right file.

The .native.js files contain code that is shared between both mobile platforms (iOS & Android). Currently, the .ios.js and .android.js files compose this .native.js file since all code is shared right now. However, if a component needed to be different for platform specific reasons, that code would be included in the corresponding platform specific files.

At the end, every component is defined by 6 files. If we look at the screen component, here is its structure.

Screen.js
β”œβ”€β”€ ScreenBase.js
β”œβ”€β”€ ScreenRender.ios.js (specific to iOS build
β”œβ”€β”€ ScreenRender.android.js (specific to Android build)
β”œβ”€β”€ ScreenRender.native.js (shared mobile app code - iOS & Android)
└── ScreenRender.js (used during Website and Desktop build)

And here is the main Class file which composes the files.

'use strict';

import Base from './ScreenBase';
import Render from './ScreenRender';

export default class Screen extends Base {
  constructor (props) {
    super(props);
  }

  render () {
    return Render.call(this, this.props, this.state);
  }
}

What's next

Here are some thoughts about what can come next:

  • Make the Website App Isomorphic/Universal

Thank you Robert for your awesome design

I want to thank Robert O'Dowd who kindly authorized me the reuse his very beautiful design. The original design made by Robert was part of his project called "Simplifycation" visible here.

How to build/run the projects

General requirements before running any specific project

  • npm install to install all the dependencies, React and React Native among others.

With some versions of npm (>=v3.3.10 <=v3.6.0)

Some builds from npm included bugs while npm install. So if you are using a npm version within the range form 3.3.10 to 3.6.0 included, you must run npm install twice. Those versions including npm v3.3.12 are the ones bundled by default with node from version v5.1.0 to v5.5.0.

  • npm install npm
  • npm install npm run it twice, because of the packages won't be installed after the first run #10985

The Mobile Apps (iOS & Android)

Requirements for React Native

iOS

  • OS X
  • Xcode 6.3 or higher is recommended (Xcode only runs on Mac).
  • Homebrew is the recommended way to install node, watchman, and flow.
  • brew install node
  • brew install watchman. We recommend installing watchman, otherwise you might hit a node file watching bug.
  • brew install flow. If you want to use flow.

Android

Running the Mobile Apps

iOS

  • Open iosApp.xcodeproj and hit run in Xcode.
  • Hit cmd+R in your iOS simulator to reload the app and see your change!

Android

Congratulations! You've just successfully run the project as an iOS or Android App.

The Website App

Requirements for React

There isn't any additional requirements since you already installed the deps with npm install.

Quick start

Congratulations! You've just successfully run the project as a Website App.

The Desktop App

You can either run the project with NW or electron.

Requirements for NW

To run the project, you are supposed to run something like:

/path/to/nw .

On OSX, the executable binary is in a hidden directory within the .app file. The easier solution to install it is to download the app on http://nwjs.io/ then copying it to your application folder. You will now be able to run:

/Applications/nwjs.app/Contents/MacOS/nwjs .

You can also setup an alias to call the binary.

alias nw="/Applications/nwjs.app/Contents/MacOS/nwjs"

Quick start with NW

  • npm run build to build the project (at least the first time)
  • npm run serve-nw to launch the desktop app and enable livereload

Congratulations! You've just successfully run the project as a Desktop App.

Quick start with Electron

  • npm run build to build the project (at least the first time)
  • npm run serve-electron to launch the desktop app and enable livereload

Congratulations! You've just successfully run the project as a Desktop App.

Run the tests

To run the tests, simply run:

npm test

Tests

More Repositories

1

computer-science-in-javascript

Computer science reimplemented in JavaScript
JavaScript
2,604
star
2

coursera-machine-learning

MATLAB
95
star
3

100-best-books

An website to play with the 100 best classical books of all time http://www.100bestbooks.xyz
CSS
75
star
4

hit-100-pagespeed-insights

Let's try to hit the 100 score on PageSpeed Insights
JavaScript
15
star
5

titlecase-french

"Capital and Lowercase Letters in French Title" using capital letters for the principal words
JavaScript
13
star
6

a-tour-of-go

Exercises of the "A tour of Go" website https://tour.golang.org/list
Go
11
star
7

react-native-redux-app-100-10-1

React Native App with redux for the 100-10-1 method
JavaScript
9
star
8

whack-a-mole-game

Very simple whack a mole game in JavaScript
JavaScript
7
star
9

benoitvallon.github.io

My personal blog https://blog.benoitvallon.com
SCSS
4
star
10

basic-react-redux

A basic boilerplate repo for a react and redux app
CSS
4
star
11

dotfiles

My dotfiles based on holman/dotfiles repo https://github.com/holman/dotfiles
Shell
3
star
12

rails-sample-app

Based on the Ruby on Rails tutorial (3rd Ed.) https://www.railstutorial.org/book
Ruby
2
star
13

jekyll-github-pages-presentation

A basic Jekyll and Github pages presentation based on the spectacle library
JavaScript
2
star
14

getting-started-with-jupyter

A few tips to work with jupyter
Jupyter Notebook
2
star
15

phonebook-cli

Command line tool that manages phone books
Python
2
star
16

do-it-every-day

Todolist mixed with a calendar website http://www.do-it-every-day.com
Ruby
2
star
17

rails-toy-app

Based on the Ruby on Rails tutorial (3rd Ed.) https://www.railstutorial.org/book
Ruby
1
star
18

machine-learning-with-words

Some tests on machine learning with words
JavaScript
1
star
19

learn-c-the-hard-way

Exercices based on Learn C The Hard Way book (http://c.learncodethehardway.org/book)
C
1
star
20

spring-contacts

Project to test Spring Boot
Shell
1
star
21

various-scripts

Various unrelated scripts
Python
1
star
22

spring-playground

Spring MVC playground
Java
1
star
23

scala-play-intro

Scala Play framework tutorial project
Shell
1
star
24

udacity-deep-learning-tensorflow

Jupyter Notebook
1
star
25

postgresql-and-node

Code sample based on web article example (PostgreSQL + Node)
JavaScript
1
star