Giter Site home page Giter Site logo

andrewhenderson / react-native-web-hello-world Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kauffecup/react-native-web-hello-world

0.0 1.0 0.0 113 KB

An example HelloWorld app that shares code between React Web and React Native

Home Page: http://jkaufman.io/react-web-native-codesharing/

Java 2.09% JavaScript 69.87% CSS 3.23% Objective-C 23.61% HTML 1.21%

react-native-web-hello-world's Introduction

ReactNativeWebHelloWorld

A way to share application logic between a React Web app and a React Native app, while keeping the individual component rendering unique to each platform.

For a thorough discussion of this project, please read my Blog Post about it.

The app

React Native React Web
native web

The app itself is a very simple Hello World (ish) app. Not only does it show "Hello World"... but when you click (or tap) it... it changes from red to blue! woah!

Technologies Used

Directory Structure

android houses the Android project files, ios houses the iOS project files, and web houses the webpack configs and index.html (it is also the destination of our minified bundle).

The app itself is primarily based on my React/Webpack/Redux Boilerplate, for more info on that head over there. The only key difference can be found in app/native, and app/web. What's going on here is both the native app and web app are sharing their core application logic, while keeping the individual rendering separate.

The reasoning for this is twofold - for one, React Native/React wasn't designed to be a "write once, run everywhere" framework. Facebook constantly calls it a "learn once, write everywhere" framework - the idea being that you tailor your implementation to the platform you're writing for. The second is that React Native and React are ultimately... different and the code wouldn't be reusable without some crazy aliases.

Entry Points

The entry point for the iOS app is index.ios.js, for android is index.android.js, and for the web app is app/web/index.js.

Configured Scripts

Running in dev/production

There are 8 defined scripts in [package.json][pg]:

  1. start
  2. ios-bundle
  3. ios-dev-bundle
  4. android-bundle
  5. android-dev-bundle
  6. web-bundle
  7. web-dev

start

start is used when running/bundling the native application. When you open either the xcode project or the android studio project and hit "run", it kicks off a node server via the start command. Every time you make a JavaScript change, instead of needing to rebuild and recompile your application, you simply refresh the app and the changes are magically there. As this is not a React Native guide I will not be going into more detail than that - further information can be found on Facebook's React Native Getting Started guide.

bundlin

For ios-bundle, ios-dev-bundle, android-bundle, and android-dev-bundle, the script builds the JavaScript bundle (either minified or not-minified depending on the presence of dev or not), and places it where the corresponding project expects it to be for running locally on your device. Again, you can find more info on running on your device on Facebook's React Native Getting Started.

web town

web-dev kicks off a webpack server on port 3001, it utilizes hot reloading with some redux-time-machine-magic to have a crazy awesome dev experience where you can rewind and revert actions in your application.

web-bundle creates a minified JavaScript bundle (that also houses the minified css) and places it next to the index.html in web/public that you can serve with any static file server.

clear-cache

Every now and then, when React Native is doing it's thing, you'll swear that you've changed something, but alas it is still causing your app to break! oh noes! what do we do!

I'm glad you asked! Just run npm run clear-cache!

Further Configuration

Webpack sets the PLATFORM_ENV environment variable to be web. You can use this check to conditionally load different files depending on if you're building your native or web app. For example - you can abstract out the difference between local storage mechanisms.

react-native-web-hello-world's People

Contributors

andrewhenderson avatar kauffecup avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.