Skip to content

Commit 90148d7

Browse files
committed
Working on demo app
1 parent 5dbddb6 commit 90148d7

File tree

8 files changed

+376
-4
lines changed

8 files changed

+376
-4
lines changed

ScrollStackController.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/* Begin PBXBuildFile section */
1010
52D6D9871BEFF229002C0205 /* ScrollStackController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6D97C1BEFF229002C0205 /* ScrollStackController.framework */; };
1111
6402E1F22347A8540087963C /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6402E1F12347A8540087963C /* Extension.swift */; };
12+
647C77B32348EA1600CAEB9F /* PricingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 647C77B22348EA1600CAEB9F /* PricingVC.swift */; };
13+
64A8E8B32348CCCE00E893FB /* WelcomeVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64A8E8B02348CCCE00E893FB /* WelcomeVC.swift */; };
1214
64C02255234735A800A6D844 /* ScrollStackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0224F234735A800A6D844 /* ScrollStackViewController.swift */; };
1315
64C02256234735A800A6D844 /* ScrollStackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0224F234735A800A6D844 /* ScrollStackViewController.swift */; };
1416
64C02257234735A800A6D844 /* ScrollStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02250234735A800A6D844 /* ScrollStack.swift */; };
@@ -60,6 +62,8 @@
6062
52D6D9861BEFF229002C0205 /* ScrollStackController-iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ScrollStackController-iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
6163
52D6D9F01BEFFFBE002C0205 /* ScrollStackController.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ScrollStackController.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6264
6402E1F12347A8540087963C /* Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = "<group>"; };
65+
647C77B22348EA1600CAEB9F /* PricingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PricingVC.swift; sourceTree = "<group>"; };
66+
64A8E8B02348CCCE00E893FB /* WelcomeVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeVC.swift; sourceTree = "<group>"; };
6367
64C0224F234735A800A6D844 /* ScrollStackViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStackViewController.swift; sourceTree = "<group>"; };
6468
64C02250234735A800A6D844 /* ScrollStack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStack.swift; sourceTree = "<group>"; };
6569
64C02251234735A800A6D844 /* ScrollStackRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStackRow.swift; sourceTree = "<group>"; };
@@ -167,6 +171,8 @@
167171
children = (
168172
64C0227C234753A100A6D844 /* GalleryVC.swift */,
169173
64C022892347834300A6D844 /* TagsVC.swift */,
174+
64A8E8B02348CCCE00E893FB /* WelcomeVC.swift */,
175+
647C77B22348EA1600CAEB9F /* PricingVC.swift */,
170176
);
171177
path = "Child View Controllers";
172178
sourceTree = "<group>";
@@ -470,10 +476,12 @@
470476
64C0227F2347582D00A6D844 /* ScrollStackRow.swift in Sources */,
471477
64C0228A2347834300A6D844 /* TagsVC.swift in Sources */,
472478
64C022822347582D00A6D844 /* ScrollStackViewController.swift in Sources */,
479+
64A8E8B32348CCCE00E893FB /* WelcomeVC.swift in Sources */,
473480
64C0226C2347360800A6D844 /* ViewController.swift in Sources */,
474481
64C022812347582D00A6D844 /* ScrollStackSeparator.swift in Sources */,
475482
64C0227E2347582D00A6D844 /* ScrollStack.swift in Sources */,
476483
64C022682347360800A6D844 /* AppDelegate.swift in Sources */,
484+
647C77B32348EA1600CAEB9F /* PricingVC.swift in Sources */,
477485
6402E1F22347A8540087963C /* Extension.swift in Sources */,
478486
64C022832347582D00A6D844 /* UIView+AutoLayout_Extensions.swift in Sources */,
479487
64C0227D234753A100A6D844 /* GalleryVC.swift in Sources */,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"idiom" : "universal",
9+
"filename" : "hotel.png",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
269 KB
Loading

ScrollStackControllerDemo/Base.lproj/Main.storyboard

Lines changed: 184 additions & 2 deletions
Large diffs are not rendered by default.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//
2+
// PricingVC.swift
3+
// ScrollStackControllerDemo
4+
//
5+
// Created by Daniele Margutti on 05/10/2019.
6+
// Copyright © 2019 ScrollStackController. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
public protocol PricingVCProtocol: class {
12+
func addFee()
13+
}
14+
15+
public class PricingVC: UIViewController, ScrollStackContainableController {
16+
17+
public weak var delegate: PricingVCProtocol?
18+
19+
@IBOutlet public var pricingTable: UITableView!
20+
@IBOutlet public var pricingTableHeightConstraint: NSLayoutConstraint!
21+
22+
public var pricingTags: [PricingTag] = [
23+
PricingTag(title: "Night fee", subtitle: "$750 x 3 nights", price: "$2,250.00"),
24+
PricingTag(title: "Hospitality fees", subtitle: "This fee covers services that come with the room", price: "$10.00"),
25+
PricingTag(title: "Property use taxes", subtitle: "Taxes the cost pays to rent their room", price: "$200.00")
26+
]
27+
28+
public static func create(delegate: PricingVCProtocol) -> PricingVC {
29+
let storyboard = UIStoryboard(name: "Main", bundle: nil)
30+
let vc = storyboard.instantiateViewController(identifier: "PricingVC") as! PricingVC
31+
vc.delegate = delegate
32+
return vc
33+
}
34+
35+
public func scrollStackRowSizeForAxis(_ axis: NSLayoutConstraint.Axis, row: ScrollStackRow, in stackView: ScrollStack) -> CGFloat? {
36+
let size = CGSize(width: stackView.bounds.size.width, height: 9000)
37+
let best = self.view.systemLayoutSizeFitting(size, withHorizontalFittingPriority: .required, verticalFittingPriority: .defaultLow)
38+
// it's important to set both the height constraint and bottom safe area for table bottom
39+
return best.height
40+
}
41+
42+
override public func updateViewConstraints() {
43+
pricingTableHeightConstraint.constant = pricingTable.contentSize.height
44+
super.updateViewConstraints()
45+
}
46+
47+
public override func viewDidLoad() {
48+
super.viewDidLoad()
49+
50+
pricingTable.rowHeight = UITableView.automaticDimension
51+
pricingTable.estimatedRowHeight = 60
52+
53+
pricingTable.reloadData()
54+
pricingTable.sizeToFit()
55+
}
56+
57+
public func addFee(_ otherFee: PricingTag) {
58+
pricingTags.append(otherFee)
59+
pricingTable.reloadData()
60+
updateViewConstraints()
61+
}
62+
63+
public func reloadContentFromStackViewRow() {
64+
65+
}
66+
67+
@IBAction public func addFee() {
68+
delegate?.addFee()
69+
}
70+
71+
}
72+
73+
extension PricingVC: UITableViewDataSource {
74+
75+
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
76+
return pricingTags.count
77+
}
78+
79+
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
80+
let cell = tableView.dequeueReusableCell(withIdentifier: "PricingCell", for: indexPath) as! PricingCell
81+
cell.priceTag = pricingTags[indexPath.row]
82+
return cell
83+
}
84+
85+
}
86+
87+
public struct PricingTag {
88+
public let title: String
89+
public let subtitle: String
90+
public let price: String
91+
92+
public init(title: String, subtitle: String, price: String) {
93+
self.title = title
94+
self.subtitle = subtitle
95+
self.price = price
96+
}
97+
98+
}
99+
100+
public class PricingCell: UITableViewCell {
101+
@IBOutlet public var titleLabel: UILabel!
102+
@IBOutlet public var subtitleLabel: UILabel!
103+
@IBOutlet public var priceLabel: UILabel!
104+
105+
public var priceTag: PricingTag? {
106+
didSet {
107+
titleLabel.text = priceTag?.title ?? ""
108+
subtitleLabel.text = priceTag?.subtitle ?? ""
109+
priceLabel.text = priceTag?.price ?? ""
110+
}
111+
}
112+
113+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// WelcomeVC.swift
3+
// ScrollStackController
4+
//
5+
// Created by Daniele Margutti on 05/10/2019.
6+
// Copyright © 2019 ScrollStackController. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
public class WelcomeVC: UIViewController, ScrollStackContainableController {
12+
13+
public static func create() -> WelcomeVC {
14+
let storyboard = UIStoryboard(name: "Main", bundle: nil)
15+
let vc = storyboard.instantiateViewController(identifier: "WelcomeVC") as! WelcomeVC
16+
return vc
17+
}
18+
19+
public func scrollStackRowSizeForAxis(_ axis: NSLayoutConstraint.Axis, row: ScrollStackRow, in stackView: ScrollStack) -> CGFloat? {
20+
let size = CGSize(width: stackView.bounds.size.width, height: 9000)
21+
let best = self.view.systemLayoutSizeFitting(size, withHorizontalFittingPriority: .required, verticalFittingPriority: .defaultLow)
22+
return best.height
23+
}
24+
25+
public func reloadContentFromStackViewRow() {
26+
27+
}
28+
29+
}

ScrollStackControllerDemo/ViewController.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ class ViewController: UIViewController {
2020

2121

2222
private var tagsVC: TagsVC!
23-
23+
private var welcomeVC: WelcomeVC!
24+
private var galleryVC: GalleryVC!
25+
private var pricingVC: PricingVC!
26+
2427
override func viewDidLoad() {
2528
super.viewDidLoad()
2629
}
@@ -33,8 +36,13 @@ class ViewController: UIViewController {
3336

3437
// Prepare content
3538

39+
welcomeVC = WelcomeVC.create()
3640
tagsVC = TagsVC.create(delegate: self)
37-
stackView.addRow(controller: tagsVC, at: .top, animated: false)
41+
galleryVC = GalleryVC.create()
42+
pricingVC = PricingVC.create(delegate: self)
43+
44+
stackView.addRows(controllers: [welcomeVC, tagsVC, galleryVC,pricingVC], animated: false)
45+
3846
}
3947

4048
@IBAction public func addNewRow() {
@@ -77,3 +85,14 @@ extension ViewController: TagsVCProtocol {
7785
}
7886

7987
}
88+
89+
extension ViewController: PricingVCProtocol {
90+
91+
func addFee() {
92+
let otherFee = PricingTag(title: "Another fee", subtitle: "Some spare taxes", price: "$50.00")
93+
pricingVC.addFee(otherFee)
94+
let index = stackView.rowForController(pricingVC)!.index
95+
stackView.reloadRow(index: index)
96+
}
97+
98+
}

0 commit comments

Comments
 (0)