Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make LayoutProxy functions not internal? #277

Open
ninjudd opened this issue Nov 21, 2017 · 4 comments
Open

Make LayoutProxy functions not internal? #277

ninjudd opened this issue Nov 21, 2017 · 4 comments

Comments

@ninjudd
Copy link

ninjudd commented Nov 21, 2017

Hey there. I love Cartography!

But, I'm trying to add some extensions to LayoutProxy, and I'm running into trouble because all the functions are internal.

Any chance you'd be open to making them public?

@corujautx
Copy link
Contributor

corujautx commented Nov 22, 2017

Which functions are you thinking of making public and what extension are you thinking of adding to LayoutProxy? I'm think of refactoring it a bit to add type safety (aka Edge will be turned into a protocol instead, and we will have TopEdge, BottomEdge... as type-safe edges to make sure Edges, Point and Size are initialized with the correct types).

I did not expose those functions because it means that people would have access to an API that would not be meaningful to them externally.

PS: if you are thinking of being capable of constraining view controllers, I've been thinking of a similar idea, creating a layout proxy that would not be positionable but would instead offer properties as view, topLayoutGuide and bottomLayoutGuide so we could ditch car_topLayoutGuide and car_bottomLayoutGuide type erasures.

@ninjudd
Copy link
Author

ninjudd commented Nov 22, 2017

We have a two extensions that I added in my fork that we use extensively throughout our code. Here is an example of the usage:

    constrain(statusView) { statusView in
      statusView.edges(.bottom, .left, .right) == statusView.superview!.edges(.top, .left, right).inset(-4, 0, 0)
      statusView.width == 70
      statusView.height == 30
    }

The edges function takes a variable number of LayoutAttributes and returns an Edges object. Inset is an extension to Edges since the built-in inset function requires an Edges object with exactly 4 edges.

@corujautx
Copy link
Contributor

Hmm, I'm thinking of avoiding this in Edges because it semantically represents the edges of a certain layout element (its top, leading, bottom and trailing edges respectively).

What you do basically exposes to runtime errors, as the edges on each side have to match the edges on the other side otherwise we would have a fatal error. I kinda wanna avoid this type of things, plus I feel it's not semantically representative.

One option maybe is creating an == operator for arrays of Property? e.g. [statusView.bottom, statusView.left, statusView.right] == [statusView.superview!.bottom, statusView.superview!.left, statusView.superview!.right] but that still is prone to runtime errors and I have no clue what is the proper behavior to be applied to operators like + and * in an expression like that.

@ninjudd
Copy link
Author

ninjudd commented Nov 22, 2017

Yeah. Type safety is a good thing. I'd love a way to use the shortened syntax for anchoring multiple edges while still having it be type safe. But there will be a lot of permutations if there is a separate type for top, bottom, leading, trailing, etc.

Are you sure you need that many types? Wouldn't just two types (HorizontalEdge and VerticalEdge) be sufficient?

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

No branches or pull requests

2 participants