fix(layout): prevent negative width/height values (#10616)

This commit is contained in:
Igor Randjelovic
2024-09-03 17:59:03 +02:00
committed by GitHub
parent 7b4cb8419c
commit 050601232a
2 changed files with 14 additions and 3 deletions

View File

@ -261,9 +261,14 @@ export class IOSHelper {
const left = layout.toDeviceIndependentPixels(position.left + insets.left); const left = layout.toDeviceIndependentPixels(position.left + insets.left);
const top = layout.toDeviceIndependentPixels(position.top + insets.top); const top = layout.toDeviceIndependentPixels(position.top + insets.top);
const width = layout.toDeviceIndependentPixels(position.right - position.left - insets.left - insets.right); let width = layout.toDeviceIndependentPixels(position.right - position.left - insets.left - insets.right);
const height = layout.toDeviceIndependentPixels(position.bottom - position.top - insets.top - insets.bottom); let height = layout.toDeviceIndependentPixels(position.bottom - position.top - insets.top - insets.bottom);
if (width < 0) {
width = 0;
}
if (height < 0) {
height = 0;
}
return CGRectMake(left, top, width, height); return CGRectMake(left, top, width, height);
} }

View File

@ -82,6 +82,9 @@ export class ViewHelper {
default: default:
childTop = top + effectiveMarginTop; childTop = top + effectiveMarginTop;
childHeight = bottom - top - (effectiveMarginTop + effectiveMarginBottom); childHeight = bottom - top - (effectiveMarginTop + effectiveMarginBottom);
if (childHeight < 0) {
childHeight = 0;
}
break; break;
} }
@ -112,6 +115,9 @@ export class ViewHelper {
default: default:
childLeft = left + effectiveMarginLeft; childLeft = left + effectiveMarginLeft;
childWidth = right - left - (effectiveMarginLeft + effectiveMarginRight); childWidth = right - left - (effectiveMarginLeft + effectiveMarginRight);
if (childWidth < 0) {
childWidth = 0;
}
break; break;
} }