Created
November 30, 2016 06:19
-
-
Save woshi82/30b3ae2d8f7264ee67283f64151a8b12 to your computer and use it in GitHub Desktop.
RN Platform.select()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @flow | |
*/ | |
'use strict'; | |
import {StyleSheet, Platform} from 'react-native'; | |
function create(styles: Object): {[name: string]: number} { | |
const platformStyles = {}; | |
Object.keys(styles).forEach((name) => { | |
let {ios, android, ...style} = {...styles[name]}; | |
if (ios && Platform.OS === 'ios') { | |
style = {...style, ...ios}; | |
} | |
if (android && Platform.OS === 'android') { | |
style = {...style, ...android}; | |
} | |
platformStyles[name] = style; | |
}); | |
return StyleSheet.create(platformStyles); | |
} | |
module.exports = { | |
'create': create | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment