GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ihor/ReactNativeCodeReuseExample: Shows how to organize your code to reuse it as much as possible between Web, iOS and Android

BranchesTags
Open more actions menu

Latest commit

 

History

19 Commits
19 Commits

Folders and files

NameName
Last commit message
Last commit date
__tests__
__tests__
 
 
android
android
 
 
app
app
 
 
ios
ios
 
 
screenshots
screenshots
 
 
web
web
 
 
.babelrc
.babelrc
 
 
.buckconfig
.buckconfig
 
 
.flowconfig
.flowconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.watchmanconfig
.watchmanconfig
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
app.json
app.json
 
 
gulpfile.js
gulpfile.js
 
 
index.android.js
index.android.js
 
 
index.ios.js
index.ios.js
 
 
index.web.js
index.web.js
 
 
package.json
package.json
 
 
webpack.config.js
webpack.config.js
 
 

Repository files navigation

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

About

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

ihor.burlachenko.com/code-sharing-between-react-and-react-native-applications/

Topics

androidcode-reusecode-sharingcross-platformexamplehowtoiosmobilereactreact-nativereduxtutorialweb

Resources

Readme
MIT license
Activity

Stars

44 stars

Watchers

7 watching

Forks

22 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.