FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(windows): let a parent resolve its children's percentage sizes · NativeScript/NativeScript@e1bd329 · GitHub

Repository navigation

Commit e1bd329

Browse files
committed
feat(windows): let a parent resolve its children's percentage sizes
A percentage width or height is handed to the parent's _setChildPercentSize(child, horizontal, fraction) when it has one and returns true; core then leaves the XAML Width/Height unset and skips its own percent sizing. Setting a length clears it (fraction null).
1 parent 54125e1 commit e1bd329

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎packages/core/ui/core/view/index.windows.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,12 @@ export class View extends ViewCommon {
15211521

15221522
if (value && typeof value === 'object' && (value as any).unit === '%') {
15231523
const pct = (value as any).value;
1524+
// A parent that lays out its children itself resolves the percentage.
1525+
if ((this.parent as any)?._setChildPercentSize?.(this, true, pct)) {
1526+
this._percentWidth = null;
1527+
this.nativeViewProtected.Width = NaN;
1528+
return;
1529+
}
15241530
this._percentWidth = pct;
15251531
this._ensureSizeWatch(); // re-apply percent when the parent resizes
15261532
this.nativeViewProtected.Width = NaN;
@@ -1543,6 +1549,7 @@ export class View extends ViewCommon {
15431549
}
15441550

15451551
this._percentWidth = null;
1552+
(this.parent as any)?._setChildPercentSize?.(this, true, null);
15461553
// Clear any previously set flex-basis so the C++ widget falls back to DesiredSize.
15471554
try {
15481555
(NativeScript as any).Widgets.FlexboxLayout.SetFlexBasisPercent(
@@ -1560,6 +1567,11 @@ export class View extends ViewCommon {
15601567

15611568
if (value && typeof value === 'object' && (value as any).unit === '%') {
15621569
const pct = (value as any).value;
1570+
if ((this.parent as any)?._setChildPercentSize?.(this, false, pct)) {
1571+
this._percentHeight = null;
1572+
this.nativeViewProtected.Height = NaN;
1573+
return;
1574+
}
15631575
this._percentHeight = pct;
15641576
this._ensureSizeWatch(); // re-apply percent when the parent resizes
15651577
this.nativeViewProtected.Height = NaN;
@@ -1577,6 +1589,7 @@ export class View extends ViewCommon {
15771589
}
15781590

15791591
this._percentHeight = null;
1592+
(this.parent as any)?._setChildPercentSize?.(this, false, null);
15801593
this.nativeViewProtected.Height = toXamlLength(value);
15811594
}
15821595

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL