[TIMOB-25386] Android: Alloy/Measurement pxToDP returns wrong result
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | n/a |
| Status | Open |
| Resolution | Unresolved |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | Android |
| Labels | n/a |
| Reporter | Zakhar Zhuravlev |
| Assignee | Unknown |
| Created | 2017-09-26T08:12:01.000+0000 |
| Updated | 2018-02-28T19:55:27.000+0000 |
Description
Ti.Platform.displayCaps.density: xhigh
Ti.Platform.displayCaps.dpi: 320
Ti.Platform.displayCaps.platformHeight: 1200
require("alloy/measurement").pxToDP(Ti.Platform.displayCaps.platformHeight) // 400 wrong
Ti.Platform.displayCaps.platformHeight / (Ti.Platform.displayCaps.dpi / 160) // 600 right
Here is the method implementation:
Looks like it's missing the newer densities? A simple PR against [this file](https://github.com/appcelerator/alloy/blob/master/Alloy/builtins/measurement.js) should fix it./** * @method pxToDP * Converts a screen pixel value to density-independent pixels. * @param {Number} val Value in screen pixels. * @return {Number} Converted value in density-independent pixels. */ exports.pxToDP = function (val) { if (OS_ANDROID) { return val / dpi * 160; } else if (OS_IOS) { switch (density) { case 'xhigh': return val / 3; case 'high': return val / 2; default: return val; } } else { return val; } };