- Notifications
You must be signed in to change notification settings - Fork22
Shows how to organize your code to reuse it as much as possible between Web, iOS and Android
License
ihor/ReactNativeCodeReuseExample
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
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.
- Installnpm
- From the root directory of the repository execute
npm i
From the root directory of the repository executegulp serve
From the root directory executereact-native run-ios or openios/ReactNativeCodeReuse.xcodeproj with XCode and run the project.
From the root directory executereact-native run-android
About
Shows how to organize your code to reuse it as much as possible between Web, iOS and Android
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.

