Coder Social home page Coder Social logo

ptzagk / reactnativecodereuseexample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ihor/reactnativecodereuseexample

0.0 0.0 0.0 1.19 MB

Shows how to organize your code to reuse it as much as possible between Web, iOS and Android

Home Page: http://ihor.burlachenko.com/code-sharing-between-react-and-react-native-applications/

License: MIT License

JavaScript 54.43% Python 9.08% Java 7.78% Objective-C 24.31% CSS 2.20% HTML 2.20%

reactnativecodereuseexample's Introduction

React Native Code Reuse

I created this application as an example for my article Code sharing between React and React Native applications. It shows how to share code between different platforms (web, iOS and Android) when using React & React Native. It is based on the fact that React Native will detect when a file has a .ios. or .android. extension and load the relevant platform file when required from other components (see Platform-specific extensions).

Each platform uses the corresponding index.js file as an entry point. All other code resides in the app directory.

For simple components which don't do any logic, we define views with .js, .ios.js and .android.js extensions each containing a platform specific code. Like in the Title component.

For components which do some logic, we add a container component to define that logic. In such case in the subpackage index, we load the container and it renders the view. For max code reuse, we can put all shared logic into the abstract container and put platform specific code into subclasses. Like in the AboutButton component.

For components which need to use Redux state and dispatch actions (connected components), we connect them once in the subpackage index and pass the received props to containers or views the same as previous components. You can check the example in the HelpButton component.

Installation

  1. Install npm
  2. From the root directory of the repository execute npm i

Run

Web

From the root directory of the repository execute gulp serve

iOS

From the root directory execute react-native run-ios or open ios/ReactNativeCodeReuse.xcodeproj with XCode and run the project.

Android

From the root directory execute react-native run-android

Screenshots

Screenshot 1 Screenshot 2

reactnativecodereuseexample's People

Contributors

ihor 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.