Skip to content

Commit 7110494

Browse files
committed
Completed example app
1 parent c591ce9 commit 7110494

File tree

10 files changed

+345
-156
lines changed

10 files changed

+345
-156
lines changed

ScrollStackController.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
52D6D9871BEFF229002C0205 /* ScrollStackController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6D97C1BEFF229002C0205 /* ScrollStackController.framework */; };
1111
6402E1F22347A8540087963C /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6402E1F12347A8540087963C /* Extension.swift */; };
1212
647C77B32348EA1600CAEB9F /* PricingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 647C77B22348EA1600CAEB9F /* PricingVC.swift */; };
13+
6489C0612349C571003E5344 /* NotesVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6489C0602349C571003E5344 /* NotesVC.swift */; };
1314
64A8E8B32348CCCE00E893FB /* WelcomeVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64A8E8B02348CCCE00E893FB /* WelcomeVC.swift */; };
1415
64C02255234735A800A6D844 /* ScrollStackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0224F234735A800A6D844 /* ScrollStackViewController.swift */; };
1516
64C02256234735A800A6D844 /* ScrollStackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0224F234735A800A6D844 /* ScrollStackViewController.swift */; };
@@ -63,6 +64,7 @@
6364
52D6D9F01BEFFFBE002C0205 /* ScrollStackController.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ScrollStackController.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6465
6402E1F12347A8540087963C /* Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = "<group>"; };
6566
647C77B22348EA1600CAEB9F /* PricingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PricingVC.swift; sourceTree = "<group>"; };
67+
6489C0602349C571003E5344 /* NotesVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotesVC.swift; sourceTree = "<group>"; };
6668
64A8E8B02348CCCE00E893FB /* WelcomeVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeVC.swift; sourceTree = "<group>"; };
6769
64C0224F234735A800A6D844 /* ScrollStackViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStackViewController.swift; sourceTree = "<group>"; };
6870
64C02250234735A800A6D844 /* ScrollStack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStack.swift; sourceTree = "<group>"; };
@@ -173,6 +175,7 @@
173175
64C022892347834300A6D844 /* TagsVC.swift */,
174176
64A8E8B02348CCCE00E893FB /* WelcomeVC.swift */,
175177
647C77B22348EA1600CAEB9F /* PricingVC.swift */,
178+
6489C0602349C571003E5344 /* NotesVC.swift */,
176179
);
177180
path = "Child View Controllers";
178181
sourceTree = "<group>";
@@ -473,6 +476,7 @@
473476
buildActionMask = 2147483647;
474477
files = (
475478
64C0228823475A0E00A6D844 /* ScrollStack+Protocols.swift in Sources */,
479+
6489C0612349C571003E5344 /* NotesVC.swift in Sources */,
476480
64C0227F2347582D00A6D844 /* ScrollStackRow.swift in Sources */,
477481
64C0228A2347834300A6D844 /* TagsVC.swift in Sources */,
478482
64C022822347582D00A6D844 /* ScrollStackViewController.swift in Sources */,

ScrollStackControllerDemo/Base.lproj/Main.storyboard

Lines changed: 250 additions & 133 deletions
Large diffs are not rendered by default.

ScrollStackControllerDemo/Child View Controllers/GalleryVC.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public class GalleryVC: UIViewController, ScrollStackContainableController {
1414
@IBOutlet public var pageControl: UIPageControl!
1515

1616
public var urls: [URL] = [
17-
URL(string: "https://www.telegraph.co.uk/content/dam/Travel/2019/February/fuji.jpg?imwidth=450")!,
18-
URL(string: "https://japan-magazine.jnto.go.jp/jnto2wm/wp-content/uploads/1608_special_TOTO_main.jpg")!,
19-
URL(string: "https://millionmilesecrets.com/wp-content/uploads/Japan-Kyoto.jpg")!,
20-
URL(string: "https://media.cntraveller.in/wp-content/uploads/2019/07/Japan-leadraw-and-fine-866x487.jpg")!
17+
URL(string: "http://cdn.luxuo.com/2011/05/Aerial-view-luxury-Burj-Al-Arab.jpg")!,
18+
URL(string: "https://mediastream.jumeirah.com/webimage/heroactual//globalassets/global/hotels-and-resorts/dubai/burj-al-arab/rooms/new-royal-two-berdoom-suite/burj-al-arab-royal-suite-staircase-5-hero.jpg")!,
19+
URL(string: "https://mediastream.jumeirah.com/webimage/image1152x648//globalassets/global/hotels-and-resorts/dubai/burj-al-arab/rooms/new-sky-one-bedroom-suite/2019/burj-al-arab-jumeirah-sky-one-bedroom-suite-living-room-desktop.jpeg")!,
20+
URL(string: "https://q-xx.bstatic.com/xdata/images/hotel/max500/200178877.jpg?k=229a02237c3998ac6e8b11daae254113268e779e49ab2d18964f2e97bdc947a0&o=")!
2121
]
2222

2323
public static func create() -> GalleryVC {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//
2+
// NotesVC.swift
3+
// ScrollStackControllerDemo
4+
//
5+
// Created by Daniele Margutti on 06/10/2019.
6+
// Copyright © 2019 ScrollStackController. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
public protocol NotesVCProtocol {
12+
13+
}
14+
15+
public class NotesVC: UIViewController, ScrollStackContainableController {
16+
17+
@IBOutlet public var textView: UITextView!
18+
@IBOutlet public var textViewHeightConstraint: NSLayoutConstraint!
19+
20+
public static func create(delegate: NotesVCProtocol) -> NotesVC {
21+
let storyboard = UIStoryboard(name: "Main", bundle: nil)
22+
let vc = storyboard.instantiateViewController(identifier: "NotesVC") as! NotesVC
23+
return vc
24+
}
25+
26+
public func scrollStackRowSizeForAxis(_ axis: NSLayoutConstraint.Axis, row: ScrollStackRow, in stackView: ScrollStack) -> CGFloat? {
27+
let size = CGSize(width: stackView.bounds.size.width, height: 9000)
28+
var best = self.view.systemLayoutSizeFitting(size, withHorizontalFittingPriority: .required, verticalFittingPriority: .defaultLow)
29+
best.height += 20
30+
// it's important to set both the height constraint and bottom safe area for table bottom
31+
return best.height
32+
}
33+
34+
35+
override public func updateViewConstraints() {
36+
let fixedWidth = textView.frame.size.width
37+
let newSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude))
38+
self.textViewHeightConstraint.constant = newSize.height
39+
40+
view.height(constant: nil)
41+
super.updateViewConstraints()
42+
}
43+
44+
public func reloadContentFromStackViewRow() {
45+
46+
}
47+
48+
public override func viewDidLoad() {
49+
super.viewDidLoad()
50+
51+
textView.isScrollEnabled = false
52+
textView.delegate = self
53+
view.height(constant: nil)
54+
}
55+
56+
57+
}
58+
59+
extension NotesVC: UITextViewDelegate {
60+
61+
public func textViewDidChange(_ textView: UITextView) {
62+
updateViewConstraints()
63+
}
64+
65+
}

ScrollStackControllerDemo/Child View Controllers/PricingVC.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ public class PricingVC: UIViewController, ScrollStackContainableController {
3939
return best.height
4040
}
4141

42-
override public func viewDidLayoutSubviews() {
43-
super.viewDidLayoutSubviews()
44-
// pricingTableHeightConstraint.constant = pricingTable.contentSize.height
45-
}
46-
4742
override public func updateViewConstraints() {
4843
pricingTableHeightConstraint.constant = pricingTable.contentSize.height
4944
view.height(constant: nil)

ScrollStackControllerDemo/Child View Controllers/TagsVC.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public class TagsVC: UIViewController, ScrollStackContainableController {
4444
public static func create(delegate: TagsVCProtocol) -> TagsVC {
4545
let storyboard = UIStoryboard(name: "Main", bundle: nil)
4646
let vc = storyboard.instantiateViewController(identifier: "TagsVC") as! TagsVC
47-
vc.view.backgroundColor = UIColor.random()
4847
vc.delegate = delegate
4948
return vc
5049
}

ScrollStackControllerDemo/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,7 @@
6565
<string>UIInterfaceOrientationLandscapeLeft</string>
6666
<string>UIInterfaceOrientationLandscapeRight</string>
6767
</array>
68+
<key>UIUserInterfaceStyle</key>
69+
<string>Light</string>
6870
</dict>
6971
</plist>

ScrollStackControllerDemo/ViewController.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class ViewController: UIViewController {
2323
private var welcomeVC: WelcomeVC!
2424
private var galleryVC: GalleryVC!
2525
private var pricingVC: PricingVC!
26+
private var notesVC: NotesVC!
2627

2728
override func viewDidLoad() {
2829
super.viewDidLoad()
@@ -40,35 +41,37 @@ class ViewController: UIViewController {
4041
tagsVC = TagsVC.create(delegate: self)
4142
galleryVC = GalleryVC.create()
4243
pricingVC = PricingVC.create(delegate: self)
44+
notesVC = NotesVC.create(delegate: self)
4345

44-
stackView.addRows(controllers: [welcomeVC, tagsVC, galleryVC,pricingVC], animated: false)
46+
stackView.addRows(controllers: [welcomeVC, notesVC, tagsVC, galleryVC,pricingVC], animated: false)
4547

4648
}
4749

4850
@IBAction public func addNewRow() {
4951
let galleryVC = GalleryVC.create()
50-
stackView.addRow(controller: galleryVC, at: .bottom, animated: true)
52+
stackView.scrollToTop()
53+
stackView.addRow(controller: galleryVC, at: .top, animated: true)
5154
}
5255

5356
@IBAction public func hideOrShowRandomRow() {
54-
let randomRow = Int.random(in: 0..<stackView.rows.count)
55-
let newRowStatus = !stackView.rows[randomRow].isHidden
56-
stackView.setRowHidden(index: randomRow, isHidden: newRowStatus, animated: true)
57+
//let randomRow = Int.random(in: 0..<stackView.rows.count)
58+
let newRowStatus = !stackView.rows[0].isHidden
59+
stackView.setRowHidden(index: 0, isHidden: newRowStatus, animated: true)
5760
}
5861

5962
@IBAction public func moveRowToRandom() {
60-
let randomSrc = Int.random(in: 0..<stackView.rows.count)
61-
let randomDst = Int.random(in: 0..<stackView.rows.count)
62-
stackView.moveRow(index: randomSrc, to: randomDst, animated: true, completion: nil)
63+
// let randomSrc = Int.random(in: 0..<stackView.rows.count)
64+
let randomDst = Int.random(in: 1..<stackView.rows.count)
65+
stackView.moveRow(index: 0, to: randomDst, animated: true, completion: nil)
6366
}
6467

6568
@IBAction public func removeRow() {
66-
let randomRow = Int.random(in: 0..<stackView.rows.count)
67-
stackView.removeRow(index: randomRow, animated: true)
69+
// let randomRow = Int.random(in: 0..<stackView.rows.count)
70+
stackView.removeRow(index: 0, animated: true)
6871
}
6972

7073
@IBAction public func toggleAxis() {
71-
stackView.toggleAxis(animated: true)
74+
stackView.toggleAxis(animated: false)
7275
}
7376

7477
@IBAction public func scrollToRandom() {
@@ -97,3 +100,7 @@ extension ViewController: PricingVCProtocol {
97100
}
98101

99102
}
103+
104+
extension ViewController: NotesVCProtocol {
105+
106+
}

Sources/ScrollStackController/ScrollStack.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate {
4444
)
4545

4646
public static let defaultSeparatorInset: UIEdgeInsets = UITableView().separatorInset
47-
public static let defaultSeparatorColor = UIColor.red//(UITableView().separatorColor ?? .clear)
47+
public static let defaultSeparatorColor = (UITableView().separatorColor ?? .clear)
4848
public static let defaultRowColor = UIColor.clear
4949
public static let defaultRowHighlightColor = UIColor(red: 0.85, green: 0.85, blue: 0.85, alpha: 1)
5050

@@ -557,7 +557,7 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate {
557557
// Create stack view and add it to the scrollview
558558
stackView.translatesAutoresizingMaskIntoConstraints = false
559559
stackView.axis = .vertical
560-
backgroundColor = UIColor.lightGray
560+
backgroundColor = .white
561561
addSubview(stackView)
562562

563563
// Configure constraints for stackview

0 commit comments

Comments
 (0)