Skip to content

Commit

Permalink
Working on demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
malcommac committed Oct 5, 2019
1 parent 5dbddb6 commit 90148d7
Show file tree
Hide file tree
Showing 8 changed files with 376 additions and 4 deletions.
8 changes: 8 additions & 0 deletions ScrollStackController.xcodeproj/project.pbxproj
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
647C77B22348EA1600CAEB9F /* PricingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PricingVC.swift; sourceTree = "<group>"; };
64A8E8B02348CCCE00E893FB /* WelcomeVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeVC.swift; sourceTree = "<group>"; };
64C0224F234735A800A6D844 /* ScrollStackViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStackViewController.swift; sourceTree = "<group>"; };
64C02250234735A800A6D844 /* ScrollStack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStack.swift; sourceTree = "<group>"; };
64C02251234735A800A6D844 /* ScrollStackRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStackRow.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -167,6 +171,8 @@
children = (
64C0227C234753A100A6D844 /* GalleryVC.swift */,
64C022892347834300A6D844 /* TagsVC.swift */,
64A8E8B02348CCCE00E893FB /* WelcomeVC.swift */,
647C77B22348EA1600CAEB9F /* PricingVC.swift */,
);
path = "Child View Controllers";
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
Binary file not shown.
@@ -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"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
186 changes: 184 additions & 2 deletions ScrollStackControllerDemo/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

113 changes: 113 additions & 0 deletions 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 ?? ""
}
}

}
29 changes: 29 additions & 0 deletions 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() {

}

}
23 changes: 21 additions & 2 deletions ScrollStackControllerDemo/ViewController.swift
Expand Up @@ -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()
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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)
}

}

0 comments on commit 90148d7

Please sign in to comment.