From 10abe47e500f7215e6a4c2ef394c5a6b9d8fee42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=BC/Common=20Platform=20Lab=28SR?= =?UTF-8?q?=29/Staff=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Fri, 13 Aug 2021 13:16:27 +0900 Subject: [PATCH] Fix layout measure issue (#100) --- src/Compatibility/Core/src/Tizen/Forms.cs | 4 ++++ .../src/Tizen/Native/CollectionView/GridLayoutManager.cs | 5 +++-- .../Tizen/Native/CollectionView/LinearLayoutManager.cs | 5 +++-- src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs | 6 +++++- src/Core/src/Platform/Tizen/LayoutCanvas.cs | 8 ++++---- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Compatibility/Core/src/Tizen/Forms.cs b/src/Compatibility/Core/src/Tizen/Forms.cs index ad45610862d3..cf9828be6cf8 100644 --- a/src/Compatibility/Core/src/Tizen/Forms.cs +++ b/src/Compatibility/Core/src/Tizen/Forms.cs @@ -622,6 +622,8 @@ public static int ConvertToScaledPixel(double dp) /// public static double ConvertToScaledDP(int pixel) { + if (pixel == int.MaxValue) + return double.PositiveInfinity; return pixel / Device.Info.ScalingFactor; } @@ -635,6 +637,8 @@ public static double ConvertToScaledDP(int pixel) /// public static double ConvertToScaledDP(double pixel) { + if (pixel == double.PositiveInfinity) + return double.PositiveInfinity; return pixel / Device.Info.ScalingFactor; } diff --git a/src/Compatibility/Core/src/Tizen/Native/CollectionView/GridLayoutManager.cs b/src/Compatibility/Core/src/Tizen/Native/CollectionView/GridLayoutManager.cs index 096465ef514d..595b532a4585 100644 --- a/src/Compatibility/Core/src/Tizen/Native/CollectionView/GridLayoutManager.cs +++ b/src/Compatibility/Core/src/Tizen/Native/CollectionView/GridLayoutManager.cs @@ -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 { diff --git a/src/Compatibility/Core/src/Tizen/Native/CollectionView/LinearLayoutManager.cs b/src/Compatibility/Core/src/Tizen/Native/CollectionView/LinearLayoutManager.cs index 414cf3b8ea3f..d5e32d2b9bb4 100644 --- a/src/Compatibility/Core/src/Tizen/Native/CollectionView/LinearLayoutManager.cs +++ b/src/Compatibility/Core/src/Tizen/Native/CollectionView/LinearLayoutManager.cs @@ -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; diff --git a/src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs b/src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs index b3451d2fb674..9ce5a1aecd30 100644 --- a/src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs +++ b/src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs @@ -1,6 +1,5 @@ using System; using ElmSharp; -using Tizen.UIExtensions.Common; namespace Microsoft.Maui.Handlers { @@ -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); diff --git a/src/Core/src/Platform/Tizen/LayoutCanvas.cs b/src/Core/src/Platform/Tizen/LayoutCanvas.cs index 7b7d25cf76a7..edb4aeea3f04 100644 --- a/src/Core/src/Platform/Tizen/LayoutCanvas.cs +++ b/src/Core/src/Platform/Tizen/LayoutCanvas.cs @@ -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 { @@ -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); }