summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS/VisualElementTracker.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/VisualElementTracker.cs')
-rw-r--r--Xamarin.Forms.Platform.iOS/VisualElementTracker.cs61
1 files changed, 54 insertions, 7 deletions
diff --git a/Xamarin.Forms.Platform.iOS/VisualElementTracker.cs b/Xamarin.Forms.Platform.iOS/VisualElementTracker.cs
index 5b41ca8..29840e2 100644
--- a/Xamarin.Forms.Platform.iOS/VisualElementTracker.cs
+++ b/Xamarin.Forms.Platform.iOS/VisualElementTracker.cs
@@ -3,8 +3,13 @@ using System.ComponentModel;
using System.Drawing;
using System.Threading;
using CoreAnimation;
+#if __MOBILE__
namespace Xamarin.Forms.Platform.iOS
+#else
+
+namespace Xamarin.Forms.Platform.MacOS
+#endif
{
public class VisualElementTracker : IDisposable
{
@@ -18,7 +23,9 @@ namespace Xamarin.Forms.Platform.iOS
// Track these by hand because the calls down into iOS are too expensive
bool _isInteractive;
Rectangle _lastBounds;
-
+#if !__MOBILE__
+ Rectangle _lastParentBounds;
+#endif
CALayer _layer;
int _updateCount;
@@ -107,12 +114,17 @@ namespace Xamarin.Forms.Platform.iOS
var shouldInteract = !view.InputTransparent && view.IsEnabled;
if (_isInteractive != shouldInteract)
{
+#if __MOBILE__
uiview.UserInteractionEnabled = shouldInteract;
+#endif
_isInteractive = shouldInteract;
}
var boundsChanged = _lastBounds != view.Bounds;
-
+#if !__MOBILE__
+ var viewParent = view.RealParent as VisualElement;
+ var parentBoundsChanged = _lastParentBounds != (viewParent == null ? Rectangle.Zero : viewParent.Bounds);
+#endif
var thread = !boundsChanged && !caLayer.Frame.IsEmpty;
var anchorX = (float)view.AnchorX;
@@ -136,13 +148,17 @@ namespace Xamarin.Forms.Platform.iOS
{
if (updateTarget != _updateCount)
return;
-
+#if __MOBILE__
var visualElement = view;
+#endif
var parent = view.RealParent;
var shouldRelayoutSublayers = false;
if (isVisible && caLayer.Hidden)
{
+#if !__MOBILE__
+ uiview.Hidden = false;
+#endif
caLayer.Hidden = false;
if (!caLayer.Frame.IsEmpty)
shouldRelayoutSublayers = true;
@@ -150,6 +166,9 @@ namespace Xamarin.Forms.Platform.iOS
if (!isVisible && !caLayer.Hidden)
{
+#if !__MOBILE__
+ uiview.Hidden = true;
+#endif
caLayer.Hidden = true;
shouldRelayoutSublayers = true;
}
@@ -157,11 +176,26 @@ namespace Xamarin.Forms.Platform.iOS
// ripe for optimization
var transform = CATransform3D.Identity;
+#if __MOBILE__
+ bool shouldUpdate = (!(visualElement is Page) || visualElement is ContentPage) && width > 0 && height > 0 && parent != null && boundsChanged;
+#else
+ // We don't care if it's a page or not since bounds of the window can change
+ // TODO: Find why it doesn't work to check if the parentsBounds changed and remove true;
+ parentBoundsChanged = true;
+ bool shouldUpdate = width > 0 && height > 0 && parent != null && (boundsChanged || parentBoundsChanged);
+#endif
// Dont ever attempt to actually change the layout of a Page unless it is a ContentPage
// iOS is a really big fan of you not actually modifying the View's of the UIViewControllers
- if ((!(visualElement is Page) || visualElement is ContentPage) && width > 0 && height > 0 && parent != null && boundsChanged)
+ if (shouldUpdate)
{
+#if __MOBILE__
var target = new RectangleF(x, y, width, height);
+#else
+ var visualParent = parent as VisualElement;
+ float newY = visualParent == null ? y : Math.Max(0, (float)(visualParent.Height - y - view.Height));
+ var target = new RectangleF(x, newY, width, height);
+#endif
+
// must reset transform prior to setting frame...
caLayer.Transform = transform;
uiview.Frame = target;
@@ -170,11 +204,17 @@ namespace Xamarin.Forms.Platform.iOS
}
else if (width <= 0 || height <= 0)
{
+ //TODO: FInd why it doesn't work
+#if __MOBILE__
caLayer.Hidden = true;
+#endif
return;
}
-
+#if __MOBILE__
caLayer.AnchorPoint = new PointF(anchorX, anchorY);
+#else
+ caLayer.AnchorPoint = new PointF(anchorX - 0.5f, anchorY - 0.5f);
+#endif
caLayer.Opacity = opacity;
const double epsilon = 0.001;
@@ -209,6 +249,9 @@ namespace Xamarin.Forms.Platform.iOS
update();
_lastBounds = view.Bounds;
+#if !__MOBILE__
+ _lastParentBounds = viewParent?.Bounds ?? Rectangle.Zero;
+#endif
}
void SetElement(VisualElement oldElement, VisualElement newElement)
@@ -239,14 +282,18 @@ namespace Xamarin.Forms.Platform.iOS
if (_layer == null)
{
+#if !__MOBILE__
+ Renderer.NativeView.WantsLayer = true;
+#endif
_layer = Renderer.NativeView.Layer;
+#if __MOBILE__
_isInteractive = Renderer.NativeView.UserInteractionEnabled;
+#endif
}
OnUpdateNativeControl(_layer);
- if (NativeControlUpdated != null)
- NativeControlUpdated(this, EventArgs.Empty);
+ NativeControlUpdated?.Invoke(this, EventArgs.Empty);
}
}
} \ No newline at end of file