summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-09-27 18:12:49 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-09-27 18:13:20 (GMT)
commit48b91865634df4888a43ea899d107953c5aabd58 (patch)
tree3a37a4065f4499067d77a018c3ce2a60deb846a6 /Xamarin.Forms.Platform.WinRT
parent33b60324383b5424339119e432137b6d7d898fa8 (diff)
downloadxamarin-forms-48b91865634df4888a43ea899d107953c5aabd58.zip
xamarin-forms-48b91865634df4888a43ea899d107953c5aabd58.tar.gz
xamarin-forms-48b91865634df4888a43ea899d107953c5aabd58.tar.bz2
[Win] Will arrange native children of custom renderers (opt-in) (#322)
* Add repro for 42602 * [Win] Add option to arrange native children * [Win] Don't allocate arrangedChildren unless required
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT')
-rw-r--r--Xamarin.Forms.Platform.WinRT/VisualElementRenderer.cs32
1 files changed, 31 insertions, 1 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/VisualElementRenderer.cs b/Xamarin.Forms.Platform.WinRT/VisualElementRenderer.cs
index 3ad826b..b81f73e 100644
--- a/Xamarin.Forms.Platform.WinRT/VisualElementRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/VisualElementRenderer.cs
@@ -1,4 +1,5 @@
´╗┐using System;
+using System.Collections.Generic;
using System.ComponentModel;
using Windows.Foundation;
using Windows.UI.Xaml;
@@ -28,6 +29,8 @@ namespace Xamarin.Forms.Platform.WinRT
protected bool AutoTrack { get; set; } = true;
+ protected bool ArrangeNativeChildren { get; set; }
+
IElementController ElementController => Element as IElementController;
protected VisualElementTracker<TElement, TNativeElement> Tracker
@@ -160,11 +163,14 @@ namespace Xamarin.Forms.Platform.WinRT
Element.IsInNativeLayout = true;
+ var myRect = new Rect(0, 0, finalSize.Width, finalSize.Height);
+
if (Control != null)
{
- Control.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height));
+ Control.Arrange(myRect);
}
+ List<UIElement> arrangedChildren = null;
for (var i = 0; i < ElementController.LogicalChildren.Count; i++)
{
var child = ElementController.LogicalChildren[i] as VisualElement;
@@ -176,6 +182,30 @@ namespace Xamarin.Forms.Platform.WinRT
Rectangle bounds = child.Bounds;
renderer.ContainerElement.Arrange(new Rect(bounds.X, bounds.Y, Math.Max(0, bounds.Width), Math.Max(0, bounds.Height)));
+
+ if (ArrangeNativeChildren)
+ {
+ if (arrangedChildren == null)
+ arrangedChildren = new List<UIElement>();
+ arrangedChildren.Add(renderer.ContainerElement);
+ }
+ }
+
+ if (ArrangeNativeChildren)
+ {
+ // in the event that a custom renderer has added native controls,
+ // we need to be sure to arrange them so that they are laid out.
+ var nativeChildren = Children;
+ for (int i = 0; i < nativeChildren.Count; i++)
+ {
+ var nativeChild = nativeChildren[i];
+ if (arrangedChildren?.Contains(nativeChild) == true)
+ // don't try to rearrange renderers that were just arranged,
+ // lest you suffer a layout cycle
+ continue;
+ else
+ nativeChild.Arrange(myRect);
+ }
}
Element.IsInNativeLayout = false;