Skip to content

Commit

Permalink
Fix layout measure issue (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
myroot authored and rookiejava committed Feb 4, 2022
1 parent 33b2119 commit 2d7d661
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/Compatibility/Core/src/Tizen/Forms.cs
Expand Up @@ -622,6 +622,8 @@ public static int ConvertToScaledPixel(double dp)
/// <returns></returns>
public static double ConvertToScaledDP(int pixel)
{
if (pixel == int.MaxValue)
return double.PositiveInfinity;
return pixel / Device.Info.ScalingFactor;
}

Expand All @@ -635,6 +637,8 @@ public static double ConvertToScaledDP(int pixel)
/// <returns></returns>
public static double ConvertToScaledDP(double pixel)
{
if (pixel == double.PositiveInfinity)
return double.PositiveInfinity;
return pixel / Device.Info.ScalingFactor;
}

Expand Down
Expand Up @@ -111,8 +111,9 @@ int BaseItemSize

int ItemSpacing => IsHorizontal ? HorizontalItemSpacing : VerticalItemSpacing;

int ItemWidthConstraint => IsHorizontal ? _allocatedSize.Width * 100 : ColumnSize;
int ItemHeightConstraint => IsHorizontal ? ColumnSize : _allocatedSize.Height * 100;
// It is a rule, if you want to fit with a content natural size, constraint should be infinity
int ItemWidthConstraint => IsHorizontal ? int.MaxValue : ColumnSize;
int ItemHeightConstraint => IsHorizontal ? ColumnSize : int.MaxValue;

int ColumnSize
{
Expand Down
Expand Up @@ -100,8 +100,9 @@ int BaseItemSize
}
}

int ItemWidthConstraint => IsHorizontal ? _allocatedSize.Width * 100 : _allocatedSize.Width;
int ItemHeightConstraint => IsHorizontal ? _allocatedSize.Height : _allocatedSize.Height * 100;
// It is a rule, if you want to fit with a content natural size, constraint should be infinity
int ItemWidthConstraint => IsHorizontal ? int.MaxValue : _allocatedSize.Width;
int ItemHeightConstraint => IsHorizontal ? _allocatedSize.Height : int.MaxValue;

int FooterSize => IsHorizontal ? _footerSize.Width : _footerSize.Height;
int HeaderSize => IsHorizontal ? _headerSize.Width : _headerSize.Height;
Expand Down
6 changes: 5 additions & 1 deletion src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs
@@ -1,6 +1,5 @@
using System;
using ElmSharp;
using Tizen.UIExtensions.Common;

namespace Microsoft.Maui.Handlers
{
Expand Down Expand Up @@ -39,6 +38,11 @@ protected override LayoutCanvas CreateNativeView()
return view;
}

public override Graphics.Size GetDesiredSize(double widthConstraint, double heightConstraint)
{
return VirtualView.LayoutManager.Measure(widthConstraint, heightConstraint);
}

public override void SetVirtualView(IView view)
{
base.SetVirtualView(view);
Expand Down
8 changes: 4 additions & 4 deletions src/Core/src/Platform/Tizen/LayoutCanvas.cs
Expand Up @@ -2,9 +2,9 @@
using ElmSharp;
using Tizen.UIExtensions.Common;
using Tizen.UIExtensions.ElmSharp;
using TSize = Tizen.UIExtensions.Common.Size;
using Size = Microsoft.Maui.Graphics.Size;
using Rectangle = Microsoft.Maui.Graphics.Rectangle;
using Size = Microsoft.Maui.Graphics.Size;
using TSize = Tizen.UIExtensions.Common.Size;

namespace Microsoft.Maui
{
Expand Down Expand Up @@ -37,8 +37,8 @@ protected void OnLayoutUpdated(object? sender, LayoutEventArgs e)

if (nativeGeometry.Width > 0 && nativeGeometry.Height > 0)
{
nativeGeometry.X = _virtualView.Frame.X;
nativeGeometry.Y = _virtualView.Frame.Y;
nativeGeometry.X = 0;
nativeGeometry.Y = 0;
CrossPlatformMeasure!(nativeGeometry.Width, nativeGeometry.Height);
CrossPlatformArrange!(nativeGeometry);
}
Expand Down

0 comments on commit 2d7d661

Please sign in to comment.