Skip to content

Commit

Permalink
Fix GetDesiredSize (#87)
Browse files Browse the repository at this point in the history
* Fix GetDesiredSize

* update for readability
  • Loading branch information
myroot authored and rookiejava committed Sep 30, 2021
1 parent b530071 commit ec4937e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Core/src/Handlers/View/ViewHandlerOfT.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,9 @@ public override Size GetDesiredSize(double widthConstraint, double heightConstra
{
var nativeView = NativeView;

if (nativeView == null || VirtualView == null)
if (nativeView == null || VirtualView == null || NativeParent == null)
{
return Size.Zero;
}

if (NativeParent == null)
{
return new Size(widthConstraint, heightConstraint);
return VirtualView == null ? Size.Zero : new Size(VirtualView.Width, VirtualView.Height);
}

int availableWidth = widthConstraint.ToScaledPixel();
Expand All @@ -79,9 +74,13 @@ public override Size GetDesiredSize(double widthConstraint, double heightConstra
if (availableHeight < 0)
availableHeight = int.MaxValue;

var explicitWidth = VirtualView.Width;
var explicitHeight = VirtualView.Height;
var hasExplicitWidth = explicitWidth >= 0;
var hasExplicitHeight = explicitHeight >= 0;

Size measured;
var nativeViewMeasurable = nativeView as IMeasurable;
if (nativeViewMeasurable != null)
if (nativeView is IMeasurable nativeViewMeasurable)
{
measured = nativeViewMeasurable.Measure(availableWidth, availableHeight).ToDP();
}
Expand All @@ -90,7 +89,8 @@ public override Size GetDesiredSize(double widthConstraint, double heightConstra
measured = Measure(availableWidth, availableHeight);
}

return measured;
return new Size(hasExplicitWidth ? explicitWidth : measured.Width,
hasExplicitHeight ? explicitHeight : measured.Height);
}

public virtual ERect GetNativeContentGeometry()
Expand Down

0 comments on commit ec4937e

Please sign in to comment.