app.unit
Unit conversion utility. This help us convert unit (as example dp
to px
) easily.
#
ConstantsName | Type | Description |
---|---|---|
Types | object | Unit constants. We use this for parameters of app.unit.convert |
#
MethodsName | Return Type | Description |
---|---|---|
convert | number | Scale a number based on two units. |
resolve | number | Resolve unit suffix of a string then convert it to px. |
#
convertScale a number based on two units. If toUnit
ignored, then destination unit assumed as px
.
Parameters:
- value: (number type) a Number to be converted
- fromUnit: (number type) Unit of value. Use
app.unit.Types.*
for this parameter. - toUnit: (number type, Optional) Unit of result. Use
app.unit.Types.*
for this parameter.
Return: number
#
resolveResolve unit suffix of a string then convert it to px. However, if the value is number then returns that value.
Parameters:
- value: (string or number type) a String that contains number with unit or just a plain number.
- percentFactor: (number type, Optional) This parameter tells
"100%"
is equals what pixels. If ignored, then"100%" == "100px"
.
Return: number