Created
December 20, 2016 15:52
-
-
Save atakane/3c4ebf9ace4e9086a3b5fbc679db2aee to your computer and use it in GitHub Desktop.
getUnit to convert given value to iOS or Android specific metrics.
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
/* | |
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