LayoutTest-iOS icon indicating copy to clipboard operation
LayoutTest-iOS copied to clipboard

Investigate why everything returns false for hasAmbiguousLayout

Open plivesey opened this issue 9 years ago • 2 comments

See UnitTestViews.m

For unit testing, the test has yet to come up with a view which actually has ambiguous layout according to the OS. It always seems to return true.

Maybe looking up some examples from WWDC videos would give some good examples.

plivesey avatar Jan 14 '16 16:01 plivesey

Here is some code which I think should produce an ambiguous layout:

NSDictionary *viewsDictionary = @{
                                  @"view1": view1,
                                  @"view2": view2
                                  };
[superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[view1]-|" options:0 metrics:nil views:viewsDictionary]];
[superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[view2]-|" options:0 metrics:nil views:viewsDictionary]];
[superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[view1]-[view2]-|" options:0 metrics:nil views:viewsDictionary]];
[superview addConstraint:[NSLayoutConstraint constraintWithItem:superview
                                                      attribute:NSLayoutAttributeWidth
                                                      relatedBy:NSLayoutRelationEqual
                                                         toItem:nil
                                                      attribute:NSLayoutAttributeNotAnAttribute
                                                     multiplier:1
                                                       constant:100]];
[superview addConstraint:[NSLayoutConstraint constraintWithItem:superview
                                                      attribute:NSLayoutAttributeHeight
                                                      relatedBy:NSLayoutRelationEqual
                                                         toItem:nil
                                                      attribute:NSLayoutAttributeNotAnAttribute
                                                     multiplier:1
                                                       constant:100]];

plivesey avatar Jan 14 '16 16:01 plivesey

For others looking at this ticket, I have managed to reproduce ambiguous layout errors in another project. I haven't updated the unit tests in the library yet, but the check is still valid and useful.

plivesey avatar Feb 24 '16 01:02 plivesey