Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
[Tizen] Support to Layout Compression (#13218)
Browse files Browse the repository at this point in the history
  • Loading branch information
rookiejava committed Dec 23, 2020
1 parent 060a322 commit 124efe1
Showing 1 changed file with 58 additions and 8 deletions.
66 changes: 58 additions & 8 deletions Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,12 +701,36 @@ public virtual ERect GetNativeContentGeometry()

static double ComputeAbsoluteX(VisualElement e)
{
return e.X + ((e.RealParent is VisualElement) ? Forms.ConvertToScaledDP(Platform.GetRenderer(e.RealParent).GetNativeContentGeometry().X) : 0.0);
var parentX = 0.0;
if (e.RealParent is VisualElement ve)
{
if (CompressedLayout.GetIsHeadless(e.RealParent))
{
parentX = ComputeAbsoluteX(ve);
}
else
{
parentX = Forms.ConvertToScaledDP(Platform.GetRenderer(e.RealParent).GetNativeContentGeometry().X);
}
}
return e.X + parentX;
}

static double ComputeAbsoluteY(VisualElement e)
{
return e.Y + ((e.RealParent is VisualElement) ? Forms.ConvertToScaledDP(Platform.GetRenderer(e.RealParent).GetNativeContentGeometry().Y) : 0.0);
var parentY = 0.0;
if (e.RealParent is VisualElement ve)
{
if (CompressedLayout.GetIsHeadless(e.RealParent))
{
parentY = ComputeAbsoluteY(ve);
}
else
{
parentY = Forms.ConvertToScaledDP(Platform.GetRenderer(e.RealParent).GetNativeContentGeometry().Y);
}
}
return e.Y + parentY;
}

static Point ComputeAbsolutePoint(VisualElement e)
Expand Down Expand Up @@ -742,15 +766,41 @@ protected virtual void OnUnfocused(object sender, EventArgs e)
/// <param name="child">Child to be added.</param>
protected virtual void AddChild(Element child)
{
VisualElement vElement = child as VisualElement;
if (vElement != null)
if (child is VisualElement ve)
{
var childRenderer = Platform.GetOrCreateRenderer(vElement);
if (CompressedLayout.GetIsHeadless(ve) && NativeView is IContainable<EvasObject> containerNativeView)
{
AddHeadlessChild(ve, containerNativeView);
ve.IsPlatformEnabled = true;
}
else
{
var childRenderer = Platform.GetOrCreateRenderer(ve);
// if the native view can have children, attach the new child
if (NativeView is IContainable<EvasObject> containerView)
{
containerView.Children.Add(childRenderer.NativeView);
}
}
}
}

// if the native view can have children, attach the new child
if (NativeView is Native.IContainable<EvasObject>)
protected virtual void AddHeadlessChild(VisualElement element, IContainable<EvasObject> parent)
{
foreach (var child in element.LogicalChildren)
{
if (child is VisualElement visualChild)
{
(NativeView as Native.IContainable<EvasObject>).Children.Add(childRenderer.NativeView);
if (CompressedLayout.GetIsHeadless(visualChild))
{
AddHeadlessChild(visualChild, parent);
visualChild.IsPlatformEnabled = true;
}
else
{
var childRenderer = Platform.GetOrCreateRenderer(visualChild);
parent.Children.Add(childRenderer.NativeView);
}
}
}
}
Expand Down

0 comments on commit 124efe1

Please sign in to comment.