Skip to content

Commit

Permalink
Bugfix: Content Height Adjustment (#31)
Browse files Browse the repository at this point in the history
* Adjust alignment of top and bottom constraint to line up with safe area
  • Loading branch information
heyltsjay committed May 11, 2021
1 parent 91289cc commit 5ec0fe5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion RPStackable.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Pod::Spec.new do |s|
s.name = 'RPStackable'
s.module_name = "Stackable"
s.version = '0.1.4'
s.version = '0.1.5'
s.summary = 'Stackable is a delightful and declarative set of utilities for UIStackView.'

# This description is used to generate tags and improve search results.
Expand Down
31 changes: 23 additions & 8 deletions Stackable/ScrollingStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,44 @@ open class ScrollingStackView: UIScrollView {
return super.touchesShouldCancel(in: view)
}

open override func safeAreaInsetsDidChange() {
super.safeAreaInsetsDidChange()
topSafeAreaConstraint?.constant = safeAreaInsets.top
bottomSafeAreaConstraint?.constant = safeAreaInsets.bottom
}

var topSafeAreaConstraint: NSLayoutConstraint?
var bottomSafeAreaConstraint: NSLayoutConstraint?

/// A container used to enforce that the stack content stays at least the height of the frame.
private let contentView = UIView()

public init() {
super.init(frame: .zero)

contentInsetAdjustmentBehavior = .never

addSubview(contentView)
contentView.translatesAutoresizingMaskIntoConstraints = false
contentView.clipsToBounds = false


topSafeAreaConstraint = contentView.topAnchor.constraint(equalTo: topAnchor, constant: safeAreaInsets.top)
topSafeAreaConstraint?.isActive = true

bottomSafeAreaConstraint = contentView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: safeAreaInsets.bottom)
bottomSafeAreaConstraint?.isActive = true

NSLayoutConstraint.activate([
contentView.topAnchor.constraint(equalTo: topAnchor),
contentView.leadingAnchor.constraint(equalTo: leadingAnchor),
contentView.trailingAnchor.constraint(equalTo: trailingAnchor),
contentView.bottomAnchor.constraint(equalTo: bottomAnchor),

contentView.heightAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.heightAnchor),
contentView.widthAnchor.constraint(equalTo: widthAnchor),

contentView.heightAnchor.constraint(greaterThanOrEqualTo: safeAreaLayoutGuide.heightAnchor),
contentView.widthAnchor.constraint(equalTo: frameLayoutGuide.widthAnchor),
])

contentView.addSubview(stackView)
stackView.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
stackView.topAnchor.constraint(equalTo: contentView.layoutMarginsGuide.topAnchor),
stackView.leadingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leadingAnchor),
Expand Down

0 comments on commit 5ec0fe5

Please sign in to comment.