summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-03-22 13:02:25 -0700
committerJason Smith <jason.smith@xamarin.com>2016-03-22 16:13:41 -0700
commit17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch)
treeb5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs
downloadxamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip
Initial import
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs72
1 files changed, 72 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs b/Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs
new file mode 100644
index 00000000..3d3e6868
--- /dev/null
+++ b/Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs
@@ -0,0 +1,72 @@
+´╗┐using System.Collections.Generic;
+#if __UNIFIED__
+using CoreGraphics;
+using UIKit;
+
+#else
+using MonoTouch.UIKit;
+#endif
+
+#if !__UNIFIED__
+ // Save ourselves a ton of ugly ifdefs below
+using CGSize = System.Drawing.SizeF;
+#endif
+
+namespace Xamarin.Forms.Platform.iOS
+{
+ public class NativeViewWrapperRenderer : ViewRenderer<NativeViewWrapper, UIView>
+ {
+ public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
+ {
+ if (Element?.GetDesiredSizeDelegate == null)
+ return base.GetDesiredSize(widthConstraint, heightConstraint);
+
+ // The user has specified a different implementation of GetDesiredSize
+ var result = Element.GetDesiredSizeDelegate(this, widthConstraint, heightConstraint);
+
+ // If the GetDesiredSize delegate returns a SizeRequest, we use it; if it returns null,
+ // fall back to the default implementation
+ return result ?? base.GetDesiredSize(widthConstraint, heightConstraint);
+ }
+
+ public override void LayoutSubviews()
+ {
+ if (Element?.LayoutSubViews == null)
+ {
+ Element?.InvalidateMeasure(InvalidationTrigger.MeasureChanged);
+ base.LayoutSubviews();
+ return;
+ }
+
+ // The user has specified a different implementation of LayoutSubviews
+ var handled = Element.LayoutSubViews();
+
+ if (!handled)
+ {
+ // If the delegate wasn't able to handle the request, fall back to the default implementation
+ base.LayoutSubviews();
+ }
+ }
+
+ public override CGSize SizeThatFits(CGSize size)
+ {
+ if (Element?.SizeThatFitsDelegate == null)
+ return base.SizeThatFits(size);
+
+ // The user has specified a different implementation of SizeThatFits
+ var result = Element.SizeThatFitsDelegate(size);
+
+ // If the delegate returns a value, we use it;
+ // if it returns null, fall back to the default implementation
+ return result ?? base.SizeThatFits(size);
+ }
+
+ protected override void OnElementChanged(ElementChangedEventArgs<NativeViewWrapper> e)
+ {
+ base.OnElementChanged(e);
+
+ if (e.OldElement == null)
+ SetNativeControl(Element.NativeView);
+ }
+ }
+} \ No newline at end of file