summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2017-09-13 09:18:59 (GMT)
committerKangho Hur <kangho.hur@samsung.com>2017-10-23 04:30:51 (GMT)
commit1cacb2a4bcb238e8eb534a26ce39b86cbaa75161 (patch)
tree4e14f93aa1a98d53f817f97aa06b51a0e54b4b11 /Xamarin.Forms.Platform.Android
parent1aefef5d2f0c61b57ab4dbe0c109f559d762fef9 (diff)
downloadxamarin-forms-1cacb2a4bcb238e8eb534a26ce39b86cbaa75161.zip
xamarin-forms-1cacb2a4bcb238e8eb534a26ce39b86cbaa75161.tar.gz
xamarin-forms-1cacb2a4bcb238e8eb534a26ce39b86cbaa75161.tar.bz2
[C, iOS, Android] LayoutCompression (#1136)
* [C, iOS, Android] LayoutCompression * fix docs * minor fixups
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/VisualElementPackager.cs73
-rw-r--r--Xamarin.Forms.Platform.Android/VisualElementRenderer.cs11
-rw-r--r--Xamarin.Forms.Platform.Android/VisualElementTracker.cs5
3 files changed, 53 insertions, 36 deletions
diff --git a/Xamarin.Forms.Platform.Android/VisualElementPackager.cs b/Xamarin.Forms.Platform.Android/VisualElementPackager.cs
index 1d88662..e31de7f 100644
--- a/Xamarin.Forms.Platform.Android/VisualElementPackager.cs
+++ b/Xamarin.Forms.Platform.Android/VisualElementPackager.cs
@@ -18,11 +18,16 @@ namespace Xamarin.Forms.Platform.Android
IVisualElementRenderer _renderer;
- public VisualElementPackager(IVisualElementRenderer renderer)
+ VisualElement _element;
+
+ IElementController ElementController => _element;
+
+ public VisualElementPackager(IVisualElementRenderer renderer, VisualElement element = null)
{
if (renderer == null)
- throw new ArgumentNullException("renderer");
+ throw new ArgumentNullException(nameof(renderer));
+ _element = element ?? renderer.Element;
_childAddedHandler = OnChildAdded;
_childRemovedHandler = OnChildRemoved;
_childReorderedHandler = OnChildrenReordered;
@@ -31,8 +36,6 @@ namespace Xamarin.Forms.Platform.Android
_renderer.ElementChanged += (sender, args) => SetElement(args.OldElement, args.NewElement);
}
- IElementController ElementController => _renderer.Element as IElementController;
-
public void Dispose()
{
Dispose(true);
@@ -67,44 +70,49 @@ namespace Xamarin.Forms.Platform.Android
public void Load()
{
- SetElement(null, _renderer.Element);
+ SetElement(null, _element);
}
void AddChild(VisualElement view, IVisualElementRenderer oldRenderer = null, RendererPool pool = null, bool sameChildren = false)
{
Performance.Start();
- if (_childViews == null)
- _childViews = new List<IVisualElementRenderer>();
+ if (CompressedLayout.GetIsHeadless(view)) {
+ var packager = new VisualElementPackager(_renderer, view);
+ view.IsPlatformEnabled = true;
+ packager.Load();
+ } else {
+ if (_childViews == null)
+ _childViews = new List<IVisualElementRenderer>();
- IVisualElementRenderer renderer = oldRenderer;
- if (pool != null)
- renderer = pool.GetFreeRenderer(view);
- if (renderer == null)
- {
- Performance.Start("New renderer");
- renderer = Platform.CreateRenderer(view);
- Performance.Stop("New renderer");
- }
+ IVisualElementRenderer renderer = oldRenderer;
+ if (pool != null)
+ renderer = pool.GetFreeRenderer(view);
+ if (renderer == null)
+ {
+ Performance.Start("New renderer");
+ renderer = Platform.CreateRenderer(view);
+ Performance.Stop("New renderer");
+ }
- if (renderer == oldRenderer)
- {
- Platform.SetRenderer(renderer.Element, null);
- renderer.SetElement(view);
- }
+ if (renderer == oldRenderer)
+ {
+ Platform.SetRenderer(renderer.Element, null);
+ renderer.SetElement(view);
+ }
- Performance.Start("Set renderer");
- Platform.SetRenderer(view, renderer);
- Performance.Stop("Set renderer");
+ Performance.Start("Set renderer");
+ Platform.SetRenderer(view, renderer);
+ Performance.Stop("Set renderer");
- Performance.Start("Add view");
- if (!sameChildren)
- {
- (_renderer.View as ViewGroup)?.AddView(renderer.View);
- _childViews.Add(renderer);
+ Performance.Start("Add view");
+ if (!sameChildren)
+ {
+ (_renderer.View as ViewGroup)?.AddView(renderer.View);
+ _childViews.Add(renderer);
+ }
+ Performance.Stop("Add view");
}
- Performance.Stop("Add view");
-
Performance.Stop();
}
@@ -117,7 +125,8 @@ namespace Xamarin.Forms.Platform.Android
if (element != null)
{
IVisualElementRenderer r = Platform.GetRenderer(element);
- (_renderer.View as ViewGroup)?.BringChildToFront(r.View);
+ if (r != null)
+ (_renderer.View as ViewGroup)?.BringChildToFront(r.View);
}
}
}
diff --git a/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs b/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs
index 098e85f..d580a0b 100644
--- a/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs
@@ -283,13 +283,20 @@ namespace Xamarin.Forms.Platform.Android
return;
ReadOnlyCollection<Element> children = ((IElementController)Element).LogicalChildren;
- foreach (Element element in children)
- {
+ UpdateLayout(((IElementController)Element).LogicalChildren);
+ }
+
+ static void UpdateLayout(IEnumerable<Element> children)
+ {
+ foreach (Element element in children) {
var visualElement = element as VisualElement;
if (visualElement == null)
continue;
IVisualElementRenderer renderer = Platform.GetRenderer(visualElement);
+ if (renderer == null && CompressedLayout.GetIsHeadless(visualElement))
+ UpdateLayout(visualElement.LogicalChildren);
+
renderer?.UpdateLayout();
}
}
diff --git a/Xamarin.Forms.Platform.Android/VisualElementTracker.cs b/Xamarin.Forms.Platform.Android/VisualElementTracker.cs
index f443620..7653300 100644
--- a/Xamarin.Forms.Platform.Android/VisualElementTracker.cs
+++ b/Xamarin.Forms.Platform.Android/VisualElementTracker.cs
@@ -78,8 +78,9 @@ namespace Xamarin.Forms.Platform.Android
VisualElement view = _renderer.Element;
AView aview = _renderer.View;
- var x = (int)_context.ToPixels(view.X);
- var y = (int)_context.ToPixels(view.Y);
+ var headlessOffset = CompressedLayout.GetHeadlessOffset(view);
+ var x = (int)_context.ToPixels(view.X + headlessOffset.X);
+ var y = (int)_context.ToPixels(view.Y + headlessOffset.Y);
var width = Math.Max(0, (int)_context.ToPixels(view.Width));
var height = Math.Max(0, (int)_context.ToPixels(view.Height));