Created
September 23, 2016 14:47
-
-
Save alanmcgovern/7a0f2424eb0612f54013e6b1fd497783 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Xamarin.Designer.iOS/MonoTouch.Design.Server/TypeSystem/Loader.cs b/Xamarin.Designer.iOS/MonoTouch.Design.Server/TypeSystem/Loader.cs | |
index c3671e0..4320f7f 100644 | |
--- a/Xamarin.Designer.iOS/MonoTouch.Design.Server/TypeSystem/Loader.cs | |
+++ b/Xamarin.Designer.iOS/MonoTouch.Design.Server/TypeSystem/Loader.cs | |
@@ -422,6 +422,7 @@ namespace MonoTouch.Design | |
} | |
CreateConstraintsForFrame (view); | |
+ AttachConstraints (view, context, false); | |
// Yes, we call RefreshFrames twice. The first time we use this to fill in the desired values | |
// for things like UIFlexibleSpace bar items. The second time we need to do it because frames | |
@@ -432,7 +433,7 @@ namespace MonoTouch.Design | |
RecursiveRender ((UIWindow)context.Window, view); | |
RefreshFrames (view, context, false); | |
- AttachConstraints (view, context); | |
+ AttachConstraints (view, context, true); | |
//starts a constraint update phase | |
try { | |
@@ -484,26 +485,42 @@ namespace MonoTouch.Design | |
} | |
} | |
- static void AttachConstraints (Scene scene, ParseContext context) | |
+ static void AttachConstraints (Scene scene, ParseContext context, bool attachAllConstraints) | |
{ | |
if (scene != null) | |
- AttachConstraints (scene.ViewController, context); | |
+ AttachConstraints (scene.ViewController, context, attachAllConstraints); | |
} | |
- static void AttachConstraints (ProxiedViewController controller, ParseContext context) | |
+ static void AttachConstraints (ProxiedViewController controller, ParseContext context, bool attachAllConstraints) | |
{ | |
if (controller != null) | |
- AttachConstraints (controller.View, context, parentController: (UIViewController)controller.ProxiedObject); | |
+ AttachConstraints (controller.View, context, attachAllConstraints, parentController: (UIViewController)controller.ProxiedObject); | |
} | |
- static void AttachConstraints (ProxiedView view, ParseContext context, UIViewController parentController = null, NSLayoutConstraint[] parentConstraints = null) | |
+ static void AttachConstraints (ProxiedView view, ParseContext context, bool attachAllConstraints, UIViewController parentController = null, NSLayoutConstraint[] parentConstraints = null) | |
{ | |
- NSLayoutConstraint [] constraints = null; | |
+ NSLayoutConstraint [] nativeConstraints = null; | |
if (view == null) | |
return; | |
var nativeView = view.ProxiedObject as UIView; | |
if (nativeView != null) { | |
- var query = from c in view.Constraints | |
+ var constraints = view.Constraints; | |
+ if (!attachAllConstraints) { | |
+ ModelObject parentVC = view; | |
+ while (!(parentVC is ProxiedViewController)) | |
+ parentVC = parentVC.Parent; | |
+ var children = parentVC.ToLookupDictionary (); | |
+ constraints = constraints.Where (t => { | |
+ var model1 = (string.IsNullOrEmpty (t.FirstItem) ? null : children [t.FirstItem]) as ProxiedView; | |
+ var model2 = (string.IsNullOrEmpty (t.SecondItem) ? null : children [t.SecondItem]) as ProxiedView; | |
+ if (model1 != null && !model1.HasFrameElement) | |
+ return true; | |
+ if (model2 != null && !model2.HasFrameElement) | |
+ return true; | |
+ return false; | |
+ }).ToArray (); | |
+ } | |
+ var query = from c in constraints | |
where c.Installed && !IsLayoutGuideInvolvedIn (context, c) | |
let s = c.ProxiedObject as NSLayoutConstraint | |
where s != null | |
@@ -515,8 +532,8 @@ namespace MonoTouch.Design | |
select CreateLayoutGuideConstraintIfNecessary (context, parentController, c) | |
); | |
} | |
- constraints = query.ToArray (); | |
- if (!view.TranslatesAutoresizingMaskIntoConstraints && IsConstrained (nativeView, constraints, parentConstraints)) { | |
+ nativeConstraints = query.ToArray (); | |
+ if (!view.TranslatesAutoresizingMaskIntoConstraints && IsConstrained (nativeView, nativeConstraints, parentConstraints)) { | |
if (view.TemporaryConstraints != null) | |
nativeView.RemoveConstraints ((NSLayoutConstraint[]) view.TemporaryConstraints); | |
if (view.TemporarySuperviewConstraints != null) | |
@@ -524,10 +541,10 @@ namespace MonoTouch.Design | |
} | |
} | |
foreach (var subview in view.Subviews) | |
- AttachConstraints (subview, context, parentController, constraints); | |
+ AttachConstraints (subview, context, attachAllConstraints, parentController, nativeConstraints); | |
- if (constraints != null && constraints.Length != 0) | |
- nativeView.AddConstraints (constraints); | |
+ if (nativeConstraints != null && nativeConstraints.Length != 0) | |
+ nativeView.AddConstraints (nativeConstraints); | |
} | |
static void CreateConstraintsForFrame (ProxiedViewController model) | |
@@ -544,6 +561,7 @@ namespace MonoTouch.Design | |
var alignmentFrame = view.AlignmentRectForFrame (model.Frame); | |
var widthConstraint = NSLayoutConstraint.Create (view, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, alignmentFrame.Width); | |
var heightConstraint = NSLayoutConstraint.Create (view, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, alignmentFrame.Height); | |
+ | |
if (model is ProxiedStackView && model.Subviews.Length > 0) { | |
var nativeView = (UIView) model.ProxiedObject; | |
var parentView = nativeView.Superview; | |
@@ -573,6 +591,7 @@ namespace MonoTouch.Design | |
heightConstraint = null; | |
} | |
+ if (model.HasFrameElement) { | |
if (model.Parent is ProxiedStackView) { | |
// If the parent is a stackview, only attach if there is no intrinsic size. | |
model.TemporaryConstraints = new NSLayoutConstraint[] { | |
@@ -585,6 +604,7 @@ namespace MonoTouch.Design | |
heightConstraint | |
}.Where (t => t != null).ToArray (); | |
} | |
+ | |
if (model.TemporaryConstraints != null) | |
view.AddConstraints ((NSLayoutConstraint[]) model.TemporaryConstraints); | |
@@ -596,6 +616,7 @@ namespace MonoTouch.Design | |
superview.AddConstraints ((NSLayoutConstraint[]) model.TemporarySuperviewConstraints); | |
} | |
} | |
+ } | |
foreach (var child in model.Subviews) | |
CreateConstraintsForFrame (child); | |
@@ -997,6 +1018,7 @@ namespace MonoTouch.Design | |
} | |
CreateConstraintsForFrame (model); | |
+ AttachConstraints (model, context, false); | |
if (viewController is UITabBarController) { | |
RefreshFrames (((ProxiedTabBarController) model).TabBar, context, false); | |
@@ -1045,7 +1067,7 @@ namespace MonoTouch.Design | |
// Refresh the 'Frame' property with the actual rendered frame | |
RefreshFrames (model, context, metrics, false); | |
- AttachConstraints (model, context); | |
+ AttachConstraints (model, context, true); | |
// Starts constraints update base | |
viewController.View.SetNeedsLayout (); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment