mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-26 13:25:51 +08:00
replace require with es6 import in docs
Reviewed By: svcscm Differential Revision: D2936839 fb-gh-sync-id: 7a921709a37de5e9aadf324d5438d51851326348 shipit-source-id: 7a921709a37de5e9aadf324d5438d51851326348
This commit is contained in:
committed by
facebook-github-bot-7
parent
2260d900d4
commit
3ae99d0fea
@@ -7,11 +7,11 @@ permalink: docs/platform-specific-code.html
|
||||
next: native-modules-ios
|
||||
---
|
||||
|
||||
When building a cross-platform app, the need to write different code for different platforms may arise. This can always be achieved by organizing the various components in different folders:
|
||||
When building a cross-platform app, the need to write different code for different platforms may arise. This can always be achieved by organizing the various components in different folders:
|
||||
|
||||
```sh
|
||||
/common/components/
|
||||
/android/components/
|
||||
/common/components/
|
||||
/android/components/
|
||||
/ios/components/
|
||||
```
|
||||
|
||||
@@ -25,7 +25,7 @@ BigButtonAndroid.js
|
||||
But React Native provides two alternatives to easily organize your code separating it by platform:
|
||||
|
||||
## Platform specific extensions
|
||||
React Native will detect when a file has a `.ios.` or `.android.` extension and load the right file for each platform when requiring them from other components.
|
||||
React Native will detect when a file has a `.ios.` or `.android.` extension and load the right file for each platform when requiring them from other components.
|
||||
|
||||
For example, you can have these files in your project:
|
||||
|
||||
@@ -37,7 +37,7 @@ BigButton.android.js
|
||||
With this setup, you can just require the files from a different component without paying attention to the platform in which the app will run.
|
||||
|
||||
```javascript
|
||||
var BigButton = require('./components/BigButton');
|
||||
import BigButton from './components/BigButton';
|
||||
```
|
||||
|
||||
React Native will import the correct component for the running platform.
|
||||
@@ -46,7 +46,7 @@ React Native will import the correct component for the running platform.
|
||||
A module is provided by React Native to detect what is the platform in which the app is running. This piece of functionality can be useful when only small parts of a component are platform specific.
|
||||
|
||||
```javascript
|
||||
var {Platform} = React;
|
||||
var { Platform } = React;
|
||||
|
||||
var styles = StyleSheet.create({
|
||||
height: (Platform.OS === 'ios') ? 200 : 100,
|
||||
|
||||
Reference in New Issue
Block a user