diff --git a/docs/apis/Platform.md b/docs/apis/Platform.md index 25aa3d6c..69ac893c 100644 --- a/docs/apis/Platform.md +++ b/docs/apis/Platform.md @@ -10,19 +10,36 @@ specific. `Platform.OS` will be `web` when running in a Web browser. -**userAgent**: string - -On Web, the `Platform` module can be also be used to detect the browser -`userAgent`. - -## Examples - ```js +import { Platform } from 'react-native'; + const styles = StyleSheet.create({ height: (Platform.OS === 'web') ? 200 : 100, }); - -if (Platform.userAgent.includes('Android')) { - console.log('Running on Android!'); -} +``` + +## Methods + +**select**: any + +`Platform.select` takes an object containing `Platform.OS` as keys and returns +the value for the platform you are currently running on. + +```js +import { Platform } from 'react-native'; + +const containerStyles = { + flex: 1, + ...Platform.select({ + android: { + backgroundColor: 'blue' + }, + ios: { + backgroundColor: 'red' + }, + web: { + backgroundColor: 'green' + } + }) +}); ``` diff --git a/src/apis/Platform/index.js b/src/apis/Platform/index.js index 8073e5f7..bdb5b2e6 100644 --- a/src/apis/Platform/index.js +++ b/src/apis/Platform/index.js @@ -1,8 +1,6 @@ -import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment' - const Platform = { OS: 'web', - userAgent: canUseDOM ? window.navigator.userAgent : '' + select: (obj: Object) => obj.web } module.exports = Platform