Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

ihor/ReactNativeCodeReuseExample

Repository files navigation

I created this application as an example for my articleCode 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 (seePlatform-specific extensions).

Each platform uses the correspondingindex.js file as an entry point. All other code resides in theapp 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 theTitle 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 theAboutButton 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 theHelpButton component.

Installation

  1. Installnpm
  2. From the root directory of the repository executenpm i

Run

Web

From the root directory of the repository executegulp serve

iOS

From the root directory executereact-native run-ios or openios/ReactNativeCodeReuse.xcodeproj with XCode and run the project.

Android

From the root directory executereact-native run-android

Screenshots

Screenshot 1Screenshot 2

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp