Skip to content

Instantly share code, notes, and snippets.

@woshi82
Created November 30, 2016 06:19
Show Gist options
  • Save woshi82/30b3ae2d8f7264ee67283f64151a8b12 to your computer and use it in GitHub Desktop.
Save woshi82/30b3ae2d8f7264ee67283f64151a8b12 to your computer and use it in GitHub Desktop.
RN Platform.select()
/**
* @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