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

feat(windows): let a parent resolve its children's percentage sizes by triniwiz · Pull Request #11468 · NativeScript/NativeScript · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 6 additions & 0 deletions packages/core/ui/core/view/index.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,12 @@ export abstract class View extends ViewCommon {
*/
hasGestureObservers?(): boolean;

/**
* Windows only. A parent that lays out its children itself can take over a child's percentage
* width or height (`fraction` 0-1, `null` once it is no longer a percentage) by returning `true`.
*/
_setChildPercentSize?(child: View, horizontal: boolean, fraction: number | null): boolean;

/**
* Android only to set the touch listener
*/
Expand Down
21 changes: 21 additions & 0 deletions packages/core/ui/core/view/index.windows.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,15 @@ export class View extends ViewCommon {
} catch (_e) { }
}

/**
* A parent that lays out its children itself can take over a child's percentage width or height
* (`fraction` 0-1, `null` once it is no longer a percentage) by returning `true`: the child then
* leaves its XAML size unset and skips its own percent sizing.
*/
_setChildPercentSize(child: View, horizontal: boolean, fraction: number | null): boolean {
return false;
}

private _applyPercentSizing(): void {
const nativeView = this.nativeViewProtected as any;
if (!nativeView) {
Expand Down Expand Up @@ -1521,6 +1530,11 @@ export class View extends ViewCommon {

if (value && typeof value === 'object' && (value as any).unit === '%') {
const pct = (value as any).value;
if (this.parent instanceof View && this.parent._setChildPercentSize(this, true, pct)) {
this._percentWidth = null;
this.nativeViewProtected.Width = NaN;
return;
}
this._percentWidth = pct;
this._ensureSizeWatch(); // re-apply percent when the parent resizes
this.nativeViewProtected.Width = NaN;
Expand All @@ -1543,6 +1557,7 @@ export class View extends ViewCommon {
}

this._percentWidth = null;
if (this.parent instanceof View) this.parent._setChildPercentSize(this, true, null);
// Clear any previously set flex-basis so the C++ widget falls back to DesiredSize.
try {
(NativeScript as any).Widgets.FlexboxLayout.SetFlexBasisPercent(
Expand All @@ -1560,6 +1575,11 @@ export class View extends ViewCommon {

if (value && typeof value === 'object' && (value as any).unit === '%') {
const pct = (value as any).value;
if (this.parent instanceof View && this.parent._setChildPercentSize(this, false, pct)) {
this._percentHeight = null;
this.nativeViewProtected.Height = NaN;
return;
}
this._percentHeight = pct;
this._ensureSizeWatch(); // re-apply percent when the parent resizes
this.nativeViewProtected.Height = NaN;
Expand All @@ -1577,6 +1597,7 @@ export class View extends ViewCommon {
}

this._percentHeight = null;
if (this.parent instanceof View) this.parent._setChildPercentSize(this, false, null);
this.nativeViewProtected.Height = toXamlLength(value);
}

Expand Down
Loading

Back | FazBrowse Home | New Git URL