Skip to content

Space constraints - #119

Open
bridger wants to merge 5 commits into
PureLayout:masterfrom
WeTransferArchive:spaceConstraints
Open

bridger wants to merge 5 commits into
PureLayout:masterfrom
WeTransferArchive:spaceConstraints

Conversation

@bridger

@bridger bridger commented Jan 9, 2016

Copy link
Copy Markdown

This adds convenience methods for the common case of two child views separated by some space. They are common enough that the Auto Format Format Language was specially suited to them, with the format "[red]-[blue]".

These are a little tricky to create by hand if you want the constant space to be positive. For example, [orange]-5-[black] is black.leading = orange.trailing + 5. The black view comes first in the equation. This requires a moment of pause every time I write the constraint by hand. [orange autoPinHorizontalSpace:5 followedByView:black] is more natural.

This PR also fixes a bug in autoPinEdgeToSuperviewEdge: withInset: relation: so the constant is always positive and it prints in the debugger using the Auto Layout Format Language. If it is too risky I can remove it from this PR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing wrong with using negative constants in constraints. The original implementation seems cleaner to me.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original implementation is cleaner, but it is a leaky abstraction. Users that want to adjust the constant on the constraint need to know when PureLayout decided to make the constraint negative or not. Given that the user passed in a positive constant it seems wrong to make that negative.

That said, users of PureLayout may already have workarounds for using negative constants in certain cases. If we fix this bug it might trip them up.

Also, keeping the constant positive makes debugging easier. The constraint prints to the debugger in an easier format (I wrote that code when I worked on Auto Layout at Apple. Sorry I didn't just detect this other case...)

screen shot 2016-01-10 at 10 21 52 am

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A positive inset does not imply that the constant on the underlying constraint will be positive. It's deterministic when the constant will be positive and when it will be negative. And the important point is that this change would be breaking for all existing users because it will cause the constant to flip signs as well as the first and second items on the constraint to swap half the time.

As far as debugging, shouldn't we file a radar so Apple improves this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants