summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.MacOS/Renderers/LayoutRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.MacOS/Renderers/LayoutRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.MacOS/Renderers/LayoutRenderer.cs39
1 files changed, 39 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.MacOS/Renderers/LayoutRenderer.cs b/Xamarin.Forms.Platform.MacOS/Renderers/LayoutRenderer.cs
new file mode 100644
index 0000000..1be5a1a
--- /dev/null
+++ b/Xamarin.Forms.Platform.MacOS/Renderers/LayoutRenderer.cs
@@ -0,0 +1,39 @@
+´╗┐using System;
+using CoreGraphics;
+
+namespace Xamarin.Forms.Platform.MacOS
+{
+ internal class LayoutRenderer : DefaultRenderer
+ {
+ CGRect _bounds;
+
+ public override void Layout()
+ {
+ base.Layout();
+
+ if (_bounds == Bounds)
+ return;
+
+ _bounds = Bounds;
+
+ //when the layout changes we might need to update the children position based in our new size,
+ //this is only needed in MacOS because of the inversion of the Y coordinate.
+ //Forms layout system doesn't know we need to relayout the other items ,(first ones for example)
+ //so we do it here
+ for (int i = 0; i < Subviews.Length; i++)
+ {
+ var item = Subviews[i] as IVisualElementRenderer;
+ if (item == null)
+ continue;
+ var oldFrame = item.NativeView.Frame;
+
+ var newY = Math.Max(0, (float)(Element.Height - item.Element.Height - item.Element.Y));
+ if (oldFrame.Y == newY)
+ continue;
+ var newPosition = new CGPoint(oldFrame.X, newY);
+ item.NativeView.Frame = new CGRect(newPosition, oldFrame.Size);
+ Console.WriteLine($"New Frame - {item.NativeView.Frame}");
+ }
+ }
+ }
+} \ No newline at end of file