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

Add iPhoneX layout support #372

Merged
merged 1 commit into from
Mar 29, 2018
Merged
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
31 changes: 27 additions & 4 deletions Source/Extensions/ConstraintsSetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ extension ImagePickerController {

func setupConstraints() {
let attributes: [NSLayoutAttribute] = [.bottom, .right, .width]
let topViewAttributes: [NSLayoutAttribute] = [.left, .top, .width]
let topViewAttributes: [NSLayoutAttribute] = [.left, .width]

for attribute in attributes {
view.addConstraint(NSLayoutConstraint(item: bottomContainer, attribute: attribute,
Expand All @@ -123,9 +123,32 @@ extension ImagePickerController {
multiplier: 1, constant: 0))
}

view.addConstraint(NSLayoutConstraint(item: bottomContainer, attribute: .height,
relatedBy: .equal, toItem: nil, attribute: .notAnAttribute,
multiplier: 1, constant: BottomContainerView.Dimensions.height))
if #available(iOS 11.0, *) {
view.addConstraint(NSLayoutConstraint(item: topView, attribute: .top,
relatedBy: .equal, toItem: view.safeAreaLayoutGuide,
attribute: .top,
multiplier: 1, constant: 0))
} else {
view.addConstraint(NSLayoutConstraint(item: topView, attribute: .top,
relatedBy: .equal, toItem: view,
attribute: .top,
multiplier: 1, constant: 0))
}

if #available(iOS 11.0, *) {
let heightPadding = UIApplication.shared.keyWindow!.safeAreaInsets.bottom
view.addConstraint(NSLayoutConstraint(item: bottomContainer, attribute: .height,
relatedBy: .equal, toItem: nil,
attribute: .notAnAttribute,
multiplier: 1,
constant: BottomContainerView.Dimensions.height + heightPadding))
} else {
view.addConstraint(NSLayoutConstraint(item: bottomContainer, attribute: .height,
relatedBy: .equal, toItem: nil,
attribute: .notAnAttribute,
multiplier: 1,
constant: BottomContainerView.Dimensions.height))
}

Choose a reason for hiding this comment

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

Nice! I was also about to add the iPhoneX support, but I'm glad that you were quicker ;-)

LGTM 👍

Just as an idea: You could add the new constraints in a bit more compact way like this:

    var topViewToItem: Any? = view
    var bottomContainerHeight = BottomContainerView.Dimensions.height
    
    if #available(iOS 11.0, *) {
        topViewToItem = view.safeAreaLayoutGuide
        bottomContainerHeight += UIApplication.shared.keyWindow!.safeAreaInsets.bottom
    }
    
    view.addConstraint(NSLayoutConstraint(item: topView, attribute: .top,
                                          relatedBy: .equal, toItem: topViewToItem,
                                          attribute: .top,
                                          multiplier: 1, constant: 0))
    
    view.addConstraint(NSLayoutConstraint(item: bottomContainer, attribute: .height,
                                            relatedBy: .equal, toItem: nil,
                                            attribute: .notAnAttribute,
                                            multiplier: 1,
                                            constant: bottomContainerHeight)
    )


view.addConstraint(NSLayoutConstraint(item: topView, attribute: .height,
relatedBy: .equal, toItem: nil, attribute: .notAnAttribute,
Expand Down