Summary:
This diff fixes the Android View dimensions in VR

PixelUtil.toSPFromPixel and PixelUtil.getDisplayMetricDensity() are both using getScreenDisplayMetrics() to perform conversion of dimensions. This is not correct because we should take into consideration the density of the Context / Activity instead of the Screen. This problem didn't raise before in Fabric Android because it seems that android OS on phones usually share the scale between the screen and the Activity?

These two methods are only used in Fabric and they were introduced by D9583972 (5c0da011cb) and D9173758 (8b5e3fc16b)

As part of this diff I'm also deleting the method toSPFromPixel in favor of toDIPFromPixel because I noticed the usages of these methods are meant to use toDIPFromPixel()

changelog: [Internal] internal

Reviewed By: JoshuaGross

Differential Revision: D29864944

fbshipit-source-id: a0a093c120bde21a6cf9e1043a83c31e870d4368
This commit is contained in:
David Vacca 2021-07-28 09:07:57 -07:00 коммит произвёл Facebook GitHub Bot
Родитель eb38543ef2
Коммит 6d4fff2e5c
3 изменённых файлов: 9 добавлений и 14 удалений

Просмотреть файл

@ -24,11 +24,6 @@ public class PixelUtil {
return toPixelFromDIP((float) value);
}
/** Convert from PX to SP */
public static float toSPFromPixel(float value) {
return value / DisplayMetricsHolder.getScreenDisplayMetrics().scaledDensity;
}
/** Convert from SP to PX */
public static float toPixelFromSP(float value) {
return toPixelFromSP(value, Float.NaN);
@ -58,6 +53,6 @@ public class PixelUtil {
/** @return {@link float} that represents the density of the display metrics for device screen. */
public static float getDisplayMetricDensity() {
return DisplayMetricsHolder.getScreenDisplayMetrics().density;
return DisplayMetricsHolder.getWindowDisplayMetrics().density;
}
}

Просмотреть файл

@ -493,16 +493,16 @@ public class TextLayoutManager {
// The attachment array returns the positions of each of the attachments as
attachmentsPositions[attachmentPosition] =
PixelUtil.toSPFromPixel(placeholderTopPosition);
PixelUtil.toDIPFromPixel(placeholderTopPosition);
attachmentsPositions[attachmentPosition + 1] =
PixelUtil.toSPFromPixel(placeholderLeftPosition);
PixelUtil.toDIPFromPixel(placeholderLeftPosition);
attachmentIndex++;
}
}
}
float widthInSP = PixelUtil.toSPFromPixel(calculatedWidth);
float heightInSP = PixelUtil.toSPFromPixel(calculatedHeight);
float widthInSP = PixelUtil.toDIPFromPixel(calculatedWidth);
float heightInSP = PixelUtil.toDIPFromPixel(calculatedHeight);
if (ENABLE_MEASURE_LOGGING) {
FLog.e(

Просмотреть файл

@ -514,16 +514,16 @@ public class TextLayoutManagerMapBuffer {
// The attachment array returns the positions of each of the attachments as
attachmentsPositions[attachmentPosition] =
PixelUtil.toSPFromPixel(placeholderTopPosition);
PixelUtil.toDIPFromPixel(placeholderTopPosition);
attachmentsPositions[attachmentPosition + 1] =
PixelUtil.toSPFromPixel(placeholderLeftPosition);
PixelUtil.toDIPFromPixel(placeholderLeftPosition);
attachmentIndex++;
}
}
}
float widthInSP = PixelUtil.toSPFromPixel(calculatedWidth);
float heightInSP = PixelUtil.toSPFromPixel(calculatedHeight);
float widthInSP = PixelUtil.toDIPFromPixel(calculatedWidth);
float heightInSP = PixelUtil.toDIPFromPixel(calculatedHeight);
if (ENABLE_MEASURE_LOGGING) {
FLog.e(