Skip to content

Instantly share code, notes, and snippets.

@atakane
Created December 20, 2016 15:52
Show Gist options
  • Save atakane/3c4ebf9ace4e9086a3b5fbc679db2aee to your computer and use it in GitHub Desktop.
Save atakane/3c4ebf9ace4e9086a3b5fbc679db2aee to your computer and use it in GitHub Desktop.
getUnit to convert given value to iOS or Android specific metrics.
/*
Sample 1
getUnit({iOS:'35%',Android:'37%'})
returns 35% for iOS, 37% for Android
Sample 2
getUnit(80);
returns 80 for iOS, 80dp for Android
*/
var getUnit = function(value) {
if (typeof value === "object")
return getUnit(value[Device.deviceOS]);
if (value.toString() === "%")
return value;
if (Device.deviceOS === "Android")
return value + "dp";
else
return value;
}
module.exports = getUnit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment