Skip to content

Commit

Permalink
fix(layout): prevent negative width/height values (NativeScript#10616)
Browse files Browse the repository at this point in the history
  • Loading branch information
rigor789 authored Sep 3, 2024
1 parent 7b4cb84 commit 0506012
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/core/ui/core/view/view-helper/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,14 @@ export class IOSHelper {

const left = layout.toDeviceIndependentPixels(position.left + insets.left);
const top = layout.toDeviceIndependentPixels(position.top + insets.top);
const width = layout.toDeviceIndependentPixels(position.right - position.left - insets.left - insets.right);
const height = layout.toDeviceIndependentPixels(position.bottom - position.top - insets.top - insets.bottom);

let width = layout.toDeviceIndependentPixels(position.right - position.left - insets.left - insets.right);
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);
}

Expand Down
6 changes: 6 additions & 0 deletions packages/core/ui/core/view/view-helper/view-helper-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export class ViewHelper {
default:
childTop = top + effectiveMarginTop;
childHeight = bottom - top - (effectiveMarginTop + effectiveMarginBottom);
if (childHeight < 0) {
childHeight = 0;
}
break;
}

Expand Down Expand Up @@ -112,6 +115,9 @@ export class ViewHelper {
default:
childLeft = left + effectiveMarginLeft;
childWidth = right - left - (effectiveMarginLeft + effectiveMarginRight);
if (childWidth < 0) {
childWidth = 0;
}
break;
}

Expand Down

0 comments on commit 0506012

Please sign in to comment.