From 60e90e7c5cf7cd26ee5c7701610a67f78c9f1407 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 1 Jan 2020 12:23:09 -0500 Subject: [PATCH] Add examples --- .../project.pbxproj | 41 ++++++- .../xcshareddata/swiftpm/Package.resolved | 16 +++ .../Base.lproj/Main.storyboard | 51 ++++++++- .../ContentTableViewController.swift | 65 +++++++++++ SheetControllerExamples/Info.plist | 2 - SheetControllerExamples/ViewController.swift | 107 +++++++++++++++++- 6 files changed, 269 insertions(+), 13 deletions(-) create mode 100644 SheetControllerExamples.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved create mode 100644 SheetControllerExamples/ContentTableViewController.swift diff --git a/SheetControllerExamples.xcodeproj/project.pbxproj b/SheetControllerExamples.xcodeproj/project.pbxproj index 6f6e48e..e9c4762 100644 --- a/SheetControllerExamples.xcodeproj/project.pbxproj +++ b/SheetControllerExamples.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 52; objects = { /* Begin PBXBuildFile section */ @@ -13,6 +13,8 @@ D6B0536323BD06D800A066FA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D6B0536123BD06D800A066FA /* Main.storyboard */; }; D6B0536523BD06DA00A066FA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D6B0536423BD06DA00A066FA /* Assets.xcassets */; }; D6B0536823BD06DA00A066FA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D6B0536623BD06DA00A066FA /* LaunchScreen.storyboard */; }; + D6B0537123BD087000A066FA /* SheetController in Frameworks */ = {isa = PBXBuildFile; productRef = D6B0537023BD087000A066FA /* SheetController */; }; + D6B0537423BD0AEE00A066FA /* ContentTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6B0537323BD0AEE00A066FA /* ContentTableViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -24,6 +26,7 @@ D6B0536423BD06DA00A066FA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; D6B0536723BD06DA00A066FA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; D6B0536923BD06DA00A066FA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + D6B0537323BD0AEE00A066FA /* ContentTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentTableViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -31,6 +34,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + D6B0537123BD087000A066FA /* SheetController in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -42,6 +46,7 @@ children = ( D6B0535A23BD06D800A066FA /* SheetControllerExamples */, D6B0535923BD06D800A066FA /* Products */, + D6B0537223BD099000A066FA /* Frameworks */, ); sourceTree = ""; }; @@ -59,6 +64,7 @@ D6B0535B23BD06D800A066FA /* AppDelegate.swift */, D6B0535D23BD06D800A066FA /* SceneDelegate.swift */, D6B0535F23BD06D800A066FA /* ViewController.swift */, + D6B0537323BD0AEE00A066FA /* ContentTableViewController.swift */, D6B0536123BD06D800A066FA /* Main.storyboard */, D6B0536423BD06DA00A066FA /* Assets.xcassets */, D6B0536623BD06DA00A066FA /* LaunchScreen.storyboard */, @@ -67,6 +73,13 @@ path = SheetControllerExamples; sourceTree = ""; }; + D6B0537223BD099000A066FA /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -83,6 +96,9 @@ dependencies = ( ); name = SheetControllerExamples; + packageProductDependencies = ( + D6B0537023BD087000A066FA /* SheetController */, + ); productName = SheetControllerExamples; productReference = D6B0535823BD06D800A066FA /* SheetControllerExamples.app */; productType = "com.apple.product-type.application"; @@ -111,6 +127,9 @@ Base, ); mainGroup = D6B0534F23BD06D800A066FA; + packageReferences = ( + D6B0536F23BD087000A066FA /* XCRemoteSwiftPackageReference "SheetController" */, + ); productRefGroup = D6B0535923BD06D800A066FA /* Products */; projectDirPath = ""; projectRoot = ""; @@ -140,6 +159,7 @@ files = ( D6B0536023BD06D800A066FA /* ViewController.swift in Sources */, D6B0535C23BD06D800A066FA /* AppDelegate.swift in Sources */, + D6B0537423BD0AEE00A066FA /* ContentTableViewController.swift in Sources */, D6B0535E23BD06D800A066FA /* SceneDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -338,6 +358,25 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + D6B0536F23BD087000A066FA /* XCRemoteSwiftPackageReference "SheetController" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://git.shadowfacts.net/shadowfacts/SheetController.git"; + requirement = { + branch = master; + kind = branch; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + D6B0537023BD087000A066FA /* SheetController */ = { + isa = XCSwiftPackageProductDependency; + package = D6B0536F23BD087000A066FA /* XCRemoteSwiftPackageReference "SheetController" */; + productName = SheetController; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = D6B0535023BD06D800A066FA /* Project object */; } diff --git a/SheetControllerExamples.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/SheetControllerExamples.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..7068ebf --- /dev/null +++ b/SheetControllerExamples.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,16 @@ +{ + "object": { + "pins": [ + { + "package": "SheetController", + "repositoryURL": "https://git.shadowfacts.net/shadowfacts/SheetController.git", + "state": { + "branch": "master", + "revision": "ca374422db48f381f46be8b5dae52c944e51daf0", + "version": null + } + } + ] + }, + "version": 1 +} diff --git a/SheetControllerExamples/Base.lproj/Main.storyboard b/SheetControllerExamples/Base.lproj/Main.storyboard index 25a7638..07ffe98 100644 --- a/SheetControllerExamples/Base.lproj/Main.storyboard +++ b/SheetControllerExamples/Base.lproj/Main.storyboard @@ -1,7 +1,8 @@ - + + - + @@ -9,16 +10,56 @@ - + - + - + + + + + + + + + + + + + + + + + diff --git a/SheetControllerExamples/ContentTableViewController.swift b/SheetControllerExamples/ContentTableViewController.swift new file mode 100644 index 0000000..9a14ae8 --- /dev/null +++ b/SheetControllerExamples/ContentTableViewController.swift @@ -0,0 +1,65 @@ +// +// ContentTableViewController.swift +// SheetControllerExamples +// +// Created by Shadowfacts on 1/1/20. +// Copyright © 2020 Shadowfacts. All rights reserved. +// + +import UIKit + +class ContentTableViewController: UITableViewController { + + init() { + super.init(style: .plain) + } + + required init?(coder: NSCoder) { + fatalError() + } + + override func viewDidLoad() { + super.viewDidLoad() + + tableView.register(UITableViewCell.self, forCellReuseIdentifier: "testCell") + } + + // MARK: - Table view data source + + override func numberOfSections(in tableView: UITableView) -> Int { + return 1 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return 40 + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "testCell", for: indexPath) + + cell.textLabel!.text = "\(indexPath.row)" + + return cell + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + guard let navController = navigationController else { return } + + navController.pushViewController(ContentTableViewController(), animated: true) + return + + let vc = UIViewController() + vc.view.backgroundColor = .systemBackground + let label = UILabel() + label.translatesAutoresizingMaskIntoConstraints = false + label.text = "\(indexPath.row)" + vc.view.addSubview(label) + NSLayoutConstraint.activate([ + label.centerXAnchor.constraint(equalTo: vc.view.centerXAnchor), + label.centerYAnchor.constraint(equalTo: vc.view.centerYAnchor) + ]) + + navController.pushViewController(vc, animated: true) + } + +} diff --git a/SheetControllerExamples/Info.plist b/SheetControllerExamples/Info.plist index 2a3483c..b5f9c07 100644 --- a/SheetControllerExamples/Info.plist +++ b/SheetControllerExamples/Info.plist @@ -50,8 +50,6 @@ UISupportedInterfaceOrientations UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight UISupportedInterfaceOrientations~ipad diff --git a/SheetControllerExamples/ViewController.swift b/SheetControllerExamples/ViewController.swift index 52ce249..c98a834 100644 --- a/SheetControllerExamples/ViewController.swift +++ b/SheetControllerExamples/ViewController.swift @@ -7,14 +7,111 @@ // import UIKit +import SheetController class ViewController: UIViewController { - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view. + var sheet: SheetContainerViewController! + + func showSheet(content: UIViewController) { + sheet = SheetContainerViewController(content: content) + sheet.delegate = self + sheet.detents = [.bottom, .middle, .top] + + present(sheet, animated: true) + } + + @IBAction func plainPressed(_ sender: Any) { + let content = UIViewController() + content.view.translatesAutoresizingMaskIntoConstraints = false + + let blurEffect = UIBlurEffect(style: .systemChromeMaterial) + let blurView = UIVisualEffectView(effect: blurEffect) + blurView.translatesAutoresizingMaskIntoConstraints = false + let label = UILabel() + label.translatesAutoresizingMaskIntoConstraints = false + label.text = "Hello, sheet!" + blurView.contentView.addSubview(label) + content.view.addSubview(blurView) + NSLayoutConstraint.activate([ + content.view.leadingAnchor.constraint(equalTo: blurView.contentView.leadingAnchor), + content.view.trailingAnchor.constraint(equalTo: blurView.contentView.trailingAnchor), + content.view.topAnchor.constraint(equalTo: blurView.contentView.topAnchor), + content.view.bottomAnchor.constraint(equalTo: blurView.contentView.bottomAnchor), + label.centerXAnchor.constraint(equalTo: blurView.contentView.centerXAnchor), + label.centerYAnchor.constraint(equalTo: blurView.contentView.centerYAnchor) + ]) + + showSheet(content: content) + } + + @IBAction func tablePressed(_ sender: Any) { + let content = ContentTableViewController() + content.view.translatesAutoresizingMaskIntoConstraints = false + content.view.layer.masksToBounds = true + content.view.layer.cornerRadius = view.bounds.width * 0.02 + + showSheet(content: content) + } + @IBAction func navPressed(_ sender: Any) { + let root = UIViewController() + root.view.backgroundColor = .systemBackground + let label = UILabel() + label.text = "Root VC" + label.translatesAutoresizingMaskIntoConstraints = false + root.view.addSubview(label) + NSLayoutConstraint.activate([ + label.centerXAnchor.constraint(equalTo: root.view.centerXAnchor), + label.centerYAnchor.constraint(equalTo: root.view.centerYAnchor) + ]) + + let nav = UINavigationController(rootViewController: root) + nav.view.translatesAutoresizingMaskIntoConstraints = false + nav.view.layer.masksToBounds = true + nav.view.layer.cornerRadius = view.bounds.width * 0.02 + + showSheet(content: nav) + } + @IBAction func navTablePressed(_ sender: Any) { + let table = ContentTableViewController() + + let nav = UINavigationController(rootViewController: table) + nav.delegate = self + nav.view.translatesAutoresizingMaskIntoConstraints = false + nav.view.layer.masksToBounds = true + nav.view.layer.cornerRadius = view.bounds.width * 0.02 + + showSheet(content: nav) } - - } +extension ViewController: SheetContainerViewControllerDelegate { + func sheetContainer(_ sheetContainer: SheetContainerViewController, willSnapToDetent detent: Detent) -> Bool { + if detent == .bottom { + sheetContainer.dismiss(animated: true) + return false + } + return true + } + func sheetContainerContentScrollView(_ sheetContainer: SheetContainerViewController) -> UIScrollView? { + if let navController = sheetContainer.content as? UINavigationController, + let scrollView = navController.visibleViewController?.view as? UIScrollView { + return scrollView + } else { + return nil + } + } + func sheetContainer(_ sheetContainer: SheetContainerViewController, topContentOffsetForScrollView scrollView: UIScrollView) -> CGFloat { + if let navController = sheetContainer.content as? UINavigationController { + return -navController.navigationBar.bounds.height + } else { + return 0 + } + } +} + +extension ViewController: UINavigationControllerDelegate { + func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) { + sheet.contentScrollViewChanged() + } +}