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

Fix for constraint SafeArea loop crash. #5703

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
22 changes: 13 additions & 9 deletions SignalUI/ViewControllers/ActionSheetController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,16 @@ open class ActionSheetController: OWSViewController {
// Depending on the number of actions, the sheet may need
// to scroll to allow access to all options.
view.addSubview(scrollView)

// Set the top margin for the scrollview to avoid hugging the top of the view
let topMargin: CGFloat = 59
scrollView.clipsToBounds = false
scrollView.showsVerticalScrollIndicator = false
scrollView.autoPinEdge(toSuperviewEdge: .bottom)

// Adjust ScrollView to fit within the safeArea
scrollView.autoPinEdge(toSuperviewSafeArea: .bottom)
scrollView.autoHCenterInSuperview()
scrollView.autoMatch(.height, to: .height, of: view, withOffset: 0, relation: .lessThanOrEqual)
scrollView.autoMatch(.height, to: .height, of: view, withOffset: -topMargin, relation: .lessThanOrEqual)

// Prefer to be full width, but don't exceed the maximum width
scrollView.autoSetDimension(.width, toSize: 414, relation: .lessThanOrEqual)
Expand All @@ -164,19 +169,17 @@ open class ActionSheetController: OWSViewController {
scrollView.autoPinWidthToSuperview()
}

let topMargin: CGFloat = 18

scrollView.addSubview(contentView)
contentView.autoPinWidthToSuperview()
contentView.autoPinEdge(toSuperviewEdge: .top, withInset: topMargin)
contentView.autoPinEdge(toSuperviewEdge: .top)
contentView.autoPinEdge(toSuperviewEdge: .bottom)
contentView.autoMatch(.width, to: .width, of: scrollView)

// If possible, the scrollview should be as tall as the content (no scrolling)
// but if it doesn't fit on screen, it's okay to be greater than the scroll view.
contentView.autoMatch(.height, to: .height, of: scrollView, withOffset: -topMargin, relation: .greaterThanOrEqual)
contentView.autoMatch(.height, to: .height, of: scrollView, withOffset: 0, relation: .greaterThanOrEqual)
NSLayoutConstraint.autoSetPriority(.defaultHigh) {
contentView.autoMatch(.height, to: .height, of: scrollView, withOffset: -topMargin)
contentView.autoMatch(.height, to: .height, of: scrollView)
}

// The backdrop view needs to extend from the top of the scroll view content to the bottom of the scroll view
Expand All @@ -192,13 +195,14 @@ open class ActionSheetController: OWSViewController {
contentView.addSubview(backgroundView)
backgroundView.autoPinWidthToSuperview()
backgroundView.autoPinEdge(.top, to: .top, of: contentView)
scrollView.frameLayoutGuide.bottomAnchor.constraint(equalTo: backgroundView.bottomAnchor).isActive = true
//Make sure the background is pinned to the bottom of the view as the scrollview avoids the safeArea
backgroundView.autoPinEdge(.bottom, to: .bottom, of: view)

// Stack views don't support corner masking pre-iOS 14
// Instead we add our stack view to a wrapper view with masksToBounds: true
let stackViewContainer = UIView()
contentView.addSubview(stackViewContainer)
stackViewContainer.autoPinEdgesToSuperviewSafeArea()
stackViewContainer.autoPinEdgesToSuperviewEdges()

stackViewContainer.addSubview(stackView)
stackView.autoPinEdgesToSuperviewEdges()
Expand Down