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

Support iOS 11 safe area layout guides #498

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Lock/DatabaseForgotPasswordView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ class DatabaseForgotPasswordView: UIView, View {

constraintEqual(anchor: primaryButton.leftAnchor, toAnchor: self.leftAnchor)
constraintEqual(anchor: primaryButton.rightAnchor, toAnchor: self.rightAnchor)
constraintEqual(anchor: primaryButton.bottomAnchor, toAnchor: self.bottomAnchor)
primaryButton.translatesAutoresizingMaskIntoConstraints = false

if #available(iOS 11, *) {
let guide = self.safeAreaLayoutGuide
constraintEqual(anchor: primaryButton.bottomAnchor, toAnchor: guide.bottomAnchor)
} else {
constraintEqual(anchor: primaryButton.bottomAnchor, toAnchor: self.bottomAnchor)
}

primaryButton.title = "SEND EMAIL".i18n(key: "com.auth0.lock.submit.send_email.title", comment: "Send Email button title")
forgotView.type = .email
forgotView.returnKey = .done
Expand Down
8 changes: 7 additions & 1 deletion Lock/DatabaseOnlyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ class DatabaseOnlyView: UIView, DatabaseView {

constraintEqual(anchor: primaryButton.leftAnchor, toAnchor: self.leftAnchor)
constraintEqual(anchor: primaryButton.rightAnchor, toAnchor: self.rightAnchor)
constraintEqual(anchor: primaryButton.bottomAnchor, toAnchor: self.bottomAnchor)
primaryButton.translatesAutoresizingMaskIntoConstraints = false

if #available(iOS 11, *) {
let guide = self.safeAreaLayoutGuide
constraintEqual(anchor: primaryButton.bottomAnchor, toAnchor: guide.bottomAnchor)
} else {
constraintEqual(anchor: primaryButton.bottomAnchor, toAnchor: self.bottomAnchor)
}
}

required init?(coder aDecoder: NSCoder) {
Expand Down
28 changes: 20 additions & 8 deletions Lock/HeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public class HeaderView: UIView {
private func layoutHeader() {
let titleView = UILabel()
let logoView = UIImageView()
logoView.contentMode = .scaleAspectFit
let closeButton = UIButton(type: .system)
let backButton = UIButton(type: .system)
let centerGuide = UILayoutGuide()
Expand All @@ -139,29 +140,40 @@ public class HeaderView: UIView {
constraintEqual(anchor: centerGuide.centerYAnchor, toAnchor: self.centerYAnchor, constant: 10)
constraintEqual(anchor: centerGuide.centerXAnchor, toAnchor: self.centerXAnchor)

constraintEqual(anchor: titleView.bottomAnchor, toAnchor: centerGuide.bottomAnchor)
constraintEqual(anchor: titleView.centerXAnchor, toAnchor: centerGuide.centerXAnchor)
titleView.setContentCompressionResistancePriority(UILayoutPriority.priorityRequired, for: .horizontal)
titleView.setContentHuggingPriority(UILayoutPriority.priorityRequired, for: .horizontal)
titleView.translatesAutoresizingMaskIntoConstraints = false

constraintEqual(anchor: logoView.centerXAnchor, toAnchor: self.centerXAnchor)
constraintEqual(anchor: logoView.bottomAnchor, toAnchor: titleView.topAnchor, constant: -15)
constraintEqual(anchor: logoView.topAnchor, toAnchor: centerGuide.topAnchor)
constraintEqual(anchor: logoView.bottomAnchor, toAnchor: titleView.topAnchor, constant: 0)
logoView.translatesAutoresizingMaskIntoConstraints = false

constraintEqual(anchor: closeButton.centerYAnchor, toAnchor: self.topAnchor, constant: 45)
constraintEqual(anchor: closeButton.rightAnchor, toAnchor: self.rightAnchor, constant: -10)
closeButton.widthAnchor.constraint(equalToConstant: 25).isActive = true
closeButton.heightAnchor.constraint(equalToConstant: 25).isActive = true
closeButton.translatesAutoresizingMaskIntoConstraints = false

constraintEqual(anchor: backButton.centerYAnchor, toAnchor: self.topAnchor, constant: 45)
constraintEqual(anchor: backButton.leftAnchor, toAnchor: self.leftAnchor, constant: 10)
backButton.widthAnchor.constraint(equalToConstant: 25).isActive = true
backButton.heightAnchor.constraint(equalToConstant: 25).isActive = true
backButton.translatesAutoresizingMaskIntoConstraints = false

if #available(iOS 11, *) {
let guide = self.safeAreaLayoutGuide
constraintEqual(anchor: titleView.bottomAnchor, toAnchor: guide.bottomAnchor, constant: -10)
constraintEqual(anchor: closeButton.centerYAnchor, toAnchor: guide.topAnchor, constant: 15)
constraintEqual(anchor: closeButton.rightAnchor, toAnchor: guide.rightAnchor, constant: -10)
constraintEqual(anchor: backButton.centerYAnchor, toAnchor: guide.topAnchor, constant: 15)
constraintEqual(anchor: backButton.leftAnchor, toAnchor: guide.leftAnchor, constant: 10)
constraintEqual(anchor: logoView.topAnchor, toAnchor: guide.topAnchor)
} else {
constraintEqual(anchor: titleView.bottomAnchor, toAnchor: centerGuide.bottomAnchor)
constraintEqual(anchor: closeButton.centerYAnchor, toAnchor: self.topAnchor, constant: 45)
constraintEqual(anchor: closeButton.rightAnchor, toAnchor: self.rightAnchor, constant: -10)
constraintEqual(anchor: backButton.centerYAnchor, toAnchor: self.topAnchor, constant: 45)
constraintEqual(anchor: backButton.leftAnchor, toAnchor: self.leftAnchor, constant: 10)
constraintEqual(anchor: logoView.topAnchor, toAnchor: centerGuide.topAnchor)
}

self.applyBackground()
self.apply(style: Style.Auth0)
titleView.font = regularSystemFont(size: 20)
Expand All @@ -181,7 +193,7 @@ public class HeaderView: UIView {
}

public override var intrinsicContentSize: CGSize {
return CGSize(width: 200, height: 154)
return CGSize(width: 200, height: 170)
}

@objc func buttonPressed(_ sender: UIButton) {
Expand Down