From 680b6e6d940a645abdb0c071bbe3e1f2e4de53b5 Mon Sep 17 00:00:00 2001 From: Pim Date: Wed, 26 Apr 2023 09:51:17 +0200 Subject: [PATCH] Test full-height toggle --- .../ResizingViewController.swift | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/Sample App/PanelPresenter-Sample/PanelPresenter-Sample/ViewControllers/ResizingViewController.swift b/Sample App/PanelPresenter-Sample/PanelPresenter-Sample/ViewControllers/ResizingViewController.swift index cfdcd55..d62eb98 100644 --- a/Sample App/PanelPresenter-Sample/PanelPresenter-Sample/ViewControllers/ResizingViewController.swift +++ b/Sample App/PanelPresenter-Sample/PanelPresenter-Sample/ViewControllers/ResizingViewController.swift @@ -53,6 +53,8 @@ class ResizingViewController: UIViewController, PanelPresentable { return label }() + private lazy var fixedButton: UIButton = compatibleButton(title: "Fixed", selector: #selector(didPressFixedButton)) + private lazy var doneButton: UIButton = compatibleButton(title: "Done", selector: #selector(didPressDoneButton)) required init?(coder: NSCoder) { @@ -97,12 +99,27 @@ class ResizingViewController: UIViewController, PanelPresentable { super.viewDidLoad() panelPresentationController?.showsHeader = true - let titleLabel = UILabel() - titleLabel.text = "Tap anywhere to toggle content" - titleLabel.font = .preferredFont(forTextStyle: .headline) - titleLabel.textAlignment = .center - panelPresentationController?.headerView.addSubview(titleLabel) - titleLabel.extendToSuperviewLayoutMargins() + if let headerView = panelPresentationController?.headerView { + headerView.addSubview(fixedButton) + fixedButton.setContentHuggingPriority(.required, for: .horizontal) + fixedButton.applyConstraints { + $0.trailingAnchor.constraint(equalTo: headerView.layoutMarginsGuide.trailingAnchor) + $0.centerYAnchor.constraint(equalTo: headerView.centerYAnchor) + $0.topAnchor.constraint(equalTo: headerView.layoutMarginsGuide.topAnchor) + $0.bottomAnchor.constraint(equalTo: headerView.layoutMarginsGuide.bottomAnchor) + } + let titleLabel = UILabel() + titleLabel.text = "Tap anywhere to toggle content" + titleLabel.font = .preferredFont(forTextStyle: .headline) + titleLabel.textAlignment = .center + headerView.addSubview(titleLabel) + titleLabel.applyConstraints { + $0.leadingAnchor.constraint(equalTo: headerView.layoutMarginsGuide.leadingAnchor) + $0.trailingAnchor.constraint(equalTo: fixedButton.leadingAnchor) + $0.topAnchor.constraint(equalTo: headerView.layoutMarginsGuide.topAnchor) + $0.bottomAnchor.constraint(equalTo: headerView.layoutMarginsGuide.bottomAnchor) + } + } view.addSubview(tableView) tableView.backgroundColor = .clear @@ -115,6 +132,11 @@ extension ResizingViewController { @objc func didPressDoneButton(button: UIButton) { presentingViewController?.dismiss(animated: true) } + @objc func didPressFixedButton(button: UIButton) { + panelPresentationController?.animateChanges { + self.panelPresentationController?.extendsToFullHeight.toggle() + } + } } extension ResizingViewController: UITableViewDelegate {