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

Universal way of defining SafeArea constraints #300

Open
Tylerian opened this issue Sep 20, 2018 · 5 comments
Open

Universal way of defining SafeArea constraints #300

Tylerian opened this issue Sep 20, 2018 · 5 comments

Comments

@Tylerian
Copy link

Right now we must use the #available(iOS x, *) preprocessor to switch between pre-iOS 11.0 car_topLayoutGuide / car_bottomLayoutGuide and post-iOS 11.0 safeAreaLayoutGuide.

Isn't there any cleaner way of defining those types of constraints?

@valexa
Copy link

valexa commented Sep 21, 2018

Precisely !?

@corujautx
Copy link
Contributor

corujautx commented Sep 21, 2018

iPhone X in landscape mode has different guides for left, right, leading and trailing. Do you mean as making the old API available again and using it as a proxy to safe area's top and bottom automatically? I mean, I think it's good but it'd need quite a bit of refactoring as the logic is different.
When you pin to a safeAreaLayoutGuide, you match .top to .top, where as by using one of the UILayoutSupport guides you'd usually match the .top of a view to the .bottom of the guide, and vice-versa.

@Tylerian
Copy link
Author

Tylerian commented Sep 21, 2018

Yes, that's exactly what I meant. It would save us a lot of boilerplate code when defining UILayoutGuide related constraints.

@portellaa
Copy link

I did something like this:

extension ViewProxy {
    var safeArea: SupportsPositioningLayoutProxy {
        if #available(iOS 11.0, *) {
            return safeAreaLayoutGuide
        } else {
            return self
        }
    }
}

It's not the best solution or the most elegant one, but it's better than spreading if @available through all the code.

Just an idea 😅 😇

@portellaa
Copy link

just opened a PR 👉 #301

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

5 participants
@valexa @Tylerian @portellaa @corujautx and others