diff --git a/ScrollStackController.xcodeproj/project.pbxproj b/ScrollStackController.xcodeproj/project.pbxproj index 23616a4..e76e774 100644 --- a/ScrollStackController.xcodeproj/project.pbxproj +++ b/ScrollStackController.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 52D6D9871BEFF229002C0205 /* ScrollStackController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6D97C1BEFF229002C0205 /* ScrollStackController.framework */; }; 6402E1F22347A8540087963C /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6402E1F12347A8540087963C /* Extension.swift */; }; + 647C77B32348EA1600CAEB9F /* PricingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 647C77B22348EA1600CAEB9F /* PricingVC.swift */; }; + 64A8E8B32348CCCE00E893FB /* WelcomeVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64A8E8B02348CCCE00E893FB /* WelcomeVC.swift */; }; 64C02255234735A800A6D844 /* ScrollStackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0224F234735A800A6D844 /* ScrollStackViewController.swift */; }; 64C02256234735A800A6D844 /* ScrollStackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0224F234735A800A6D844 /* ScrollStackViewController.swift */; }; 64C02257234735A800A6D844 /* ScrollStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02250234735A800A6D844 /* ScrollStack.swift */; }; @@ -60,6 +62,8 @@ 52D6D9861BEFF229002C0205 /* ScrollStackController-iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ScrollStackController-iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 52D6D9F01BEFFFBE002C0205 /* ScrollStackController.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ScrollStackController.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 6402E1F12347A8540087963C /* Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = ""; }; + 647C77B22348EA1600CAEB9F /* PricingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PricingVC.swift; sourceTree = ""; }; + 64A8E8B02348CCCE00E893FB /* WelcomeVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeVC.swift; sourceTree = ""; }; 64C0224F234735A800A6D844 /* ScrollStackViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStackViewController.swift; sourceTree = ""; }; 64C02250234735A800A6D844 /* ScrollStack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStack.swift; sourceTree = ""; }; 64C02251234735A800A6D844 /* ScrollStackRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStackRow.swift; sourceTree = ""; }; @@ -167,6 +171,8 @@ children = ( 64C0227C234753A100A6D844 /* GalleryVC.swift */, 64C022892347834300A6D844 /* TagsVC.swift */, + 64A8E8B02348CCCE00E893FB /* WelcomeVC.swift */, + 647C77B22348EA1600CAEB9F /* PricingVC.swift */, ); path = "Child View Controllers"; sourceTree = ""; @@ -470,10 +476,12 @@ 64C0227F2347582D00A6D844 /* ScrollStackRow.swift in Sources */, 64C0228A2347834300A6D844 /* TagsVC.swift in Sources */, 64C022822347582D00A6D844 /* ScrollStackViewController.swift in Sources */, + 64A8E8B32348CCCE00E893FB /* WelcomeVC.swift in Sources */, 64C0226C2347360800A6D844 /* ViewController.swift in Sources */, 64C022812347582D00A6D844 /* ScrollStackSeparator.swift in Sources */, 64C0227E2347582D00A6D844 /* ScrollStack.swift in Sources */, 64C022682347360800A6D844 /* AppDelegate.swift in Sources */, + 647C77B32348EA1600CAEB9F /* PricingVC.swift in Sources */, 6402E1F22347A8540087963C /* Extension.swift in Sources */, 64C022832347582D00A6D844 /* UIView+AutoLayout_Extensions.swift in Sources */, 64C0227D234753A100A6D844 /* GalleryVC.swift in Sources */, diff --git a/ScrollStackController.xcodeproj/project.xcworkspace/xcuserdata/daniele.xcuserdatad/UserInterfaceState.xcuserstate b/ScrollStackController.xcodeproj/project.xcworkspace/xcuserdata/daniele.xcuserdatad/UserInterfaceState.xcuserstate index c956b74..1f0bbed 100644 Binary files a/ScrollStackController.xcodeproj/project.xcworkspace/xcuserdata/daniele.xcuserdatad/UserInterfaceState.xcuserstate and b/ScrollStackController.xcodeproj/project.xcworkspace/xcuserdata/daniele.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ScrollStackControllerDemo/Assets.xcassets/hotel.imageset/Contents.json b/ScrollStackControllerDemo/Assets.xcassets/hotel.imageset/Contents.json new file mode 100644 index 0000000..af0cca7 --- /dev/null +++ b/ScrollStackControllerDemo/Assets.xcassets/hotel.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "hotel.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/ScrollStackControllerDemo/Assets.xcassets/hotel.imageset/hotel.png b/ScrollStackControllerDemo/Assets.xcassets/hotel.imageset/hotel.png new file mode 100644 index 0000000..aa9cc10 Binary files /dev/null and b/ScrollStackControllerDemo/Assets.xcassets/hotel.imageset/hotel.png differ diff --git a/ScrollStackControllerDemo/Base.lproj/Main.storyboard b/ScrollStackControllerDemo/Base.lproj/Main.storyboard index a480cec..67f3c05 100644 --- a/ScrollStackControllerDemo/Base.lproj/Main.storyboard +++ b/ScrollStackControllerDemo/Base.lproj/Main.storyboard @@ -156,7 +156,7 @@ - + @@ -230,6 +230,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -243,7 +368,7 @@ - + @@ -340,5 +465,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ScrollStackControllerDemo/Child View Controllers/PricingVC.swift b/ScrollStackControllerDemo/Child View Controllers/PricingVC.swift new file mode 100644 index 0000000..b4650f7 --- /dev/null +++ b/ScrollStackControllerDemo/Child View Controllers/PricingVC.swift @@ -0,0 +1,113 @@ +// +// PricingVC.swift +// ScrollStackControllerDemo +// +// Created by Daniele Margutti on 05/10/2019. +// Copyright © 2019 ScrollStackController. All rights reserved. +// + +import UIKit + +public protocol PricingVCProtocol: class { + func addFee() +} + +public class PricingVC: UIViewController, ScrollStackContainableController { + + public weak var delegate: PricingVCProtocol? + + @IBOutlet public var pricingTable: UITableView! + @IBOutlet public var pricingTableHeightConstraint: NSLayoutConstraint! + + public var pricingTags: [PricingTag] = [ + PricingTag(title: "Night fee", subtitle: "$750 x 3 nights", price: "$2,250.00"), + PricingTag(title: "Hospitality fees", subtitle: "This fee covers services that come with the room", price: "$10.00"), + PricingTag(title: "Property use taxes", subtitle: "Taxes the cost pays to rent their room", price: "$200.00") + ] + + public static func create(delegate: PricingVCProtocol) -> PricingVC { + let storyboard = UIStoryboard(name: "Main", bundle: nil) + let vc = storyboard.instantiateViewController(identifier: "PricingVC") as! PricingVC + vc.delegate = delegate + return vc + } + + public func scrollStackRowSizeForAxis(_ axis: NSLayoutConstraint.Axis, row: ScrollStackRow, in stackView: ScrollStack) -> CGFloat? { + let size = CGSize(width: stackView.bounds.size.width, height: 9000) + let best = self.view.systemLayoutSizeFitting(size, withHorizontalFittingPriority: .required, verticalFittingPriority: .defaultLow) + // it's important to set both the height constraint and bottom safe area for table bottom + return best.height + } + + override public func updateViewConstraints() { + pricingTableHeightConstraint.constant = pricingTable.contentSize.height + super.updateViewConstraints() + } + + public override func viewDidLoad() { + super.viewDidLoad() + + pricingTable.rowHeight = UITableView.automaticDimension + pricingTable.estimatedRowHeight = 60 + + pricingTable.reloadData() + pricingTable.sizeToFit() + } + + public func addFee(_ otherFee: PricingTag) { + pricingTags.append(otherFee) + pricingTable.reloadData() + updateViewConstraints() + } + + public func reloadContentFromStackViewRow() { + + } + + @IBAction public func addFee() { + delegate?.addFee() + } + +} + +extension PricingVC: UITableViewDataSource { + + public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return pricingTags.count + } + + public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "PricingCell", for: indexPath) as! PricingCell + cell.priceTag = pricingTags[indexPath.row] + return cell + } + +} + +public struct PricingTag { + public let title: String + public let subtitle: String + public let price: String + + public init(title: String, subtitle: String, price: String) { + self.title = title + self.subtitle = subtitle + self.price = price + } + +} + +public class PricingCell: UITableViewCell { + @IBOutlet public var titleLabel: UILabel! + @IBOutlet public var subtitleLabel: UILabel! + @IBOutlet public var priceLabel: UILabel! + + public var priceTag: PricingTag? { + didSet { + titleLabel.text = priceTag?.title ?? "" + subtitleLabel.text = priceTag?.subtitle ?? "" + priceLabel.text = priceTag?.price ?? "" + } + } + +} diff --git a/ScrollStackControllerDemo/Child View Controllers/WelcomeVC.swift b/ScrollStackControllerDemo/Child View Controllers/WelcomeVC.swift new file mode 100644 index 0000000..6d44df2 --- /dev/null +++ b/ScrollStackControllerDemo/Child View Controllers/WelcomeVC.swift @@ -0,0 +1,29 @@ +// +// WelcomeVC.swift +// ScrollStackController +// +// Created by Daniele Margutti on 05/10/2019. +// Copyright © 2019 ScrollStackController. All rights reserved. +// + +import UIKit + +public class WelcomeVC: UIViewController, ScrollStackContainableController { + + public static func create() -> WelcomeVC { + let storyboard = UIStoryboard(name: "Main", bundle: nil) + let vc = storyboard.instantiateViewController(identifier: "WelcomeVC") as! WelcomeVC + return vc + } + + public func scrollStackRowSizeForAxis(_ axis: NSLayoutConstraint.Axis, row: ScrollStackRow, in stackView: ScrollStack) -> CGFloat? { + let size = CGSize(width: stackView.bounds.size.width, height: 9000) + let best = self.view.systemLayoutSizeFitting(size, withHorizontalFittingPriority: .required, verticalFittingPriority: .defaultLow) + return best.height + } + + public func reloadContentFromStackViewRow() { + + } + +} diff --git a/ScrollStackControllerDemo/ViewController.swift b/ScrollStackControllerDemo/ViewController.swift index 5c10b96..3f9d2c4 100644 --- a/ScrollStackControllerDemo/ViewController.swift +++ b/ScrollStackControllerDemo/ViewController.swift @@ -20,7 +20,10 @@ class ViewController: UIViewController { private var tagsVC: TagsVC! - + private var welcomeVC: WelcomeVC! + private var galleryVC: GalleryVC! + private var pricingVC: PricingVC! + override func viewDidLoad() { super.viewDidLoad() } @@ -33,8 +36,13 @@ class ViewController: UIViewController { // Prepare content + welcomeVC = WelcomeVC.create() tagsVC = TagsVC.create(delegate: self) - stackView.addRow(controller: tagsVC, at: .top, animated: false) + galleryVC = GalleryVC.create() + pricingVC = PricingVC.create(delegate: self) + + stackView.addRows(controllers: [welcomeVC, tagsVC, galleryVC,pricingVC], animated: false) + } @IBAction public func addNewRow() { @@ -77,3 +85,14 @@ extension ViewController: TagsVCProtocol { } } + +extension ViewController: PricingVCProtocol { + + func addFee() { + let otherFee = PricingTag(title: "Another fee", subtitle: "Some spare taxes", price: "$50.00") + pricingVC.addFee(otherFee) + let index = stackView.rowForController(pricingVC)!.index + stackView.reloadRow(index: index) + } + +}