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

Better API for using safe area #28

Closed
abekert opened this issue Oct 3, 2019 · 1 comment · Fixed by #29
Closed

Better API for using safe area #28

abekert opened this issue Oct 3, 2019 · 1 comment · Fixed by #29

Comments

@abekert
Copy link

abekert commented Oct 3, 2019

This is a very handy framework!

Currently keyboardLayoutGuide automatically pins to safeAreaLayoutGuide.bottom.
There is a way to disable it getting a pointer to keyboardLayoutGuide and setting its usesSafeArea property to usesSafeArea.

Issue

There are two cases:

  1. Currently you can't pin two existing views to the keyboardLayoutGuide, one taking safeArea into account, the second doesn't — keyboardLayoutGuide is a single instance property.
  2. It's not very comfy. You should write something like:
let keyboardLayoutGuide = view.keyboardLayoutGuide // we don't know about the implementation, so we're holding a reference here
keyboardLayoutGuide.usesSafeArea = false
pinnedView.bottomAnchor.constraint(equalTo: keyboardLayoutGuide.topAnchor).isActive = true

Solution

I prefer one from the following:

  1. having a separate property for keyboardLayoutGuide with usesSafeArea = false
pinnedView.bottomAnchor.constraint(equalTo: keyboardLayoutGuide.topAnchor).isActive = true
pinnedView.bottomAnchor.constraint(equalTo: keyboardLayoutGuideNoSafeArea.topAnchor).isActive = true
  1. having a computed property returning KeyboardLayoutGuide with usesSafeArea turned off
pinnedView.bottomAnchor.constraint(equalTo: keyboardLayoutGuide.topAnchor).isActive = true
pinnedView.bottomAnchor.constraint(equalTo: keyboardLayoutGuide.topAnchor).isActive = true
pinnedView.bottomAnchor.constraint(equalTo: keyboardLayoutGuide.noSafeArea.topAnchor).isActive = true

Achievable via extension like:

public extension KeyboardLayoutGuide {
    var noSafeArea: KeyboardLayoutGuide {
        self.usesSafeArea = false
        return self
    }
}
@s4cha
Copy link
Member

s4cha commented Dec 16, 2019

Hi @abekert, first of all massive thanks for taking the time to report this and document it very clearly. This is very appreciated. This is a limitation indeed, I had not thought of this but this is a perfectly valid use case.
As you noted in your PR, to support this we need the distinct layout guides. The PR looks very good. I'm going to review it right now

PS: please excuse the late reply 🙏

@s4cha s4cha closed this as completed in #29 Dec 16, 2019
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 a pull request may close this issue.

2 participants