提交 9947a97e 编写于 作者: fxy060608's avatar fxy060608

fix: upx 负数转换和正数不一致的问题

上级 31bcff7f
...@@ -16,7 +16,7 @@ export function checkDeviceWidth () { ...@@ -16,7 +16,7 @@ export function checkDeviceWidth () {
isIOS = platform === 'ios' isIOS = platform === 'ios'
} }
export function upx2px (number, newDeviceWidth) { export function upx2px (number, newDeviceWidth) {
if (deviceWidth === 0) { if (deviceWidth === 0) {
checkDeviceWidth() checkDeviceWidth()
} }
...@@ -25,14 +25,17 @@ export function upx2px (number, newDeviceWidth) { ...@@ -25,14 +25,17 @@ export function upx2px (number, newDeviceWidth) {
if (number === 0) { if (number === 0) {
return 0 return 0
} }
number = (number / BASE_DEVICE_WIDTH) * (newDeviceWidth || deviceWidth) let result = (number / BASE_DEVICE_WIDTH) * (newDeviceWidth || deviceWidth)
number = Math.floor(number + EPS) if (result < 0) {
if (number === 0) { result = -result
}
result = Math.floor(result + EPS)
if (result === 0) {
if (deviceDPR === 1 || !isIOS) { if (deviceDPR === 1 || !isIOS) {
return 1 return 1
} else { } else {
return 0.5 return 0.5
} }
} }
return number return number < 0 ? -result : result
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册