Skip to content

Commit 0c67cb0

Browse files
committed
Added support to receive events for row visibility during scroll of the stack
1 parent 5628e2f commit 0c67cb0

File tree

10 files changed

+200
-112
lines changed

10 files changed

+200
-112
lines changed

ScrollStackController.xcodeproj/project.pbxproj

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
52D6D9871BEFF229002C0205 /* ScrollStackController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6D97C1BEFF229002C0205 /* ScrollStackController.framework */; };
11+
6402E1F22347A8540087963C /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6402E1F12347A8540087963C /* Extension.swift */; };
1112
64C02255234735A800A6D844 /* ScrollStackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0224F234735A800A6D844 /* ScrollStackViewController.swift */; };
1213
64C02256234735A800A6D844 /* ScrollStackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0224F234735A800A6D844 /* ScrollStackViewController.swift */; };
1314
64C02257234735A800A6D844 /* ScrollStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02250234735A800A6D844 /* ScrollStack.swift */; };
@@ -18,8 +19,6 @@
1819
64C0225C234735A800A6D844 /* ScrollStackSeparator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02252234735A800A6D844 /* ScrollStackSeparator.swift */; };
1920
64C0225D234735A800A6D844 /* UIView+AutoLayout_Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02253234735A800A6D844 /* UIView+AutoLayout_Extensions.swift */; };
2021
64C0225E234735A800A6D844 /* UIView+AutoLayout_Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02253234735A800A6D844 /* UIView+AutoLayout_Extensions.swift */; };
21-
64C0225F234735A800A6D844 /* ScrollStackRowHighlightable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02254234735A800A6D844 /* ScrollStackRowHighlightable.swift */; };
22-
64C02260234735A800A6D844 /* ScrollStackRowHighlightable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02254234735A800A6D844 /* ScrollStackRowHighlightable.swift */; };
2322
64C022682347360800A6D844 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C022672347360800A6D844 /* AppDelegate.swift */; };
2423
64C0226A2347360800A6D844 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C022692347360800A6D844 /* SceneDelegate.swift */; };
2524
64C0226C2347360800A6D844 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0226B2347360800A6D844 /* ViewController.swift */; };
@@ -29,13 +28,12 @@
2928
64C0227D234753A100A6D844 /* VC1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0227C234753A100A6D844 /* VC1.swift */; };
3029
64C0227E2347582D00A6D844 /* ScrollStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02250234735A800A6D844 /* ScrollStack.swift */; };
3130
64C0227F2347582D00A6D844 /* ScrollStackRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02251234735A800A6D844 /* ScrollStackRow.swift */; };
32-
64C022802347582D00A6D844 /* ScrollStackRowHighlightable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02254234735A800A6D844 /* ScrollStackRowHighlightable.swift */; };
3331
64C022812347582D00A6D844 /* ScrollStackSeparator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02252234735A800A6D844 /* ScrollStackSeparator.swift */; };
3432
64C022822347582D00A6D844 /* ScrollStackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0224F234735A800A6D844 /* ScrollStackViewController.swift */; };
3533
64C022832347582D00A6D844 /* UIView+AutoLayout_Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02253234735A800A6D844 /* UIView+AutoLayout_Extensions.swift */; };
36-
64C0228623475A0E00A6D844 /* ScrollStack+Support.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0228523475A0E00A6D844 /* ScrollStack+Support.swift */; };
37-
64C0228723475A0E00A6D844 /* ScrollStack+Support.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0228523475A0E00A6D844 /* ScrollStack+Support.swift */; };
38-
64C0228823475A0E00A6D844 /* ScrollStack+Support.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0228523475A0E00A6D844 /* ScrollStack+Support.swift */; };
34+
64C0228623475A0E00A6D844 /* ScrollStack+Protocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0228523475A0E00A6D844 /* ScrollStack+Protocols.swift */; };
35+
64C0228723475A0E00A6D844 /* ScrollStack+Protocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0228523475A0E00A6D844 /* ScrollStack+Protocols.swift */; };
36+
64C0228823475A0E00A6D844 /* ScrollStack+Protocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0228523475A0E00A6D844 /* ScrollStack+Protocols.swift */; };
3937
64C0228A2347834300A6D844 /* VC2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C022892347834300A6D844 /* VC2.swift */; };
4038
DD7502921C690C7A006590AF /* ScrollStackController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6D9F01BEFFFBE002C0205 /* ScrollStackController.framework */; };
4139
/* End PBXBuildFile section */
@@ -61,12 +59,12 @@
6159
52D6D97C1BEFF229002C0205 /* ScrollStackController.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ScrollStackController.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6260
52D6D9861BEFF229002C0205 /* ScrollStackController-iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ScrollStackController-iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
6361
52D6D9F01BEFFFBE002C0205 /* ScrollStackController.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ScrollStackController.framework; sourceTree = BUILT_PRODUCTS_DIR; };
62+
6402E1F12347A8540087963C /* Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = "<group>"; };
6463
64C0224F234735A800A6D844 /* ScrollStackViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStackViewController.swift; sourceTree = "<group>"; };
6564
64C02250234735A800A6D844 /* ScrollStack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStack.swift; sourceTree = "<group>"; };
6665
64C02251234735A800A6D844 /* ScrollStackRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStackRow.swift; sourceTree = "<group>"; };
6766
64C02252234735A800A6D844 /* ScrollStackSeparator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStackSeparator.swift; sourceTree = "<group>"; };
6867
64C02253234735A800A6D844 /* UIView+AutoLayout_Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+AutoLayout_Extensions.swift"; sourceTree = "<group>"; };
69-
64C02254234735A800A6D844 /* ScrollStackRowHighlightable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStackRowHighlightable.swift; sourceTree = "<group>"; };
7068
64C022652347360800A6D844 /* ScrollStackControllerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ScrollStackControllerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
7169
64C022672347360800A6D844 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7270
64C022692347360800A6D844 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
@@ -76,7 +74,7 @@
7674
64C022732347360900A6D844 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
7775
64C022752347360900A6D844 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7876
64C0227C234753A100A6D844 /* VC1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VC1.swift; sourceTree = "<group>"; };
79-
64C0228523475A0E00A6D844 /* ScrollStack+Support.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ScrollStack+Support.swift"; sourceTree = "<group>"; };
77+
64C0228523475A0E00A6D844 /* ScrollStack+Protocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ScrollStack+Protocols.swift"; sourceTree = "<group>"; };
8078
64C022892347834300A6D844 /* VC2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VC2.swift; sourceTree = "<group>"; };
8179
AD2FAA261CD0B6D800659CF4 /* ScrollStackController.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ScrollStackController.plist; sourceTree = "<group>"; };
8280
AD2FAA281CD0B6E100659CF4 /* ScrollStackControllerTests.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ScrollStackControllerTests.plist; sourceTree = "<group>"; };
@@ -155,6 +153,15 @@
155153
path = Configs;
156154
sourceTree = "<group>";
157155
};
156+
64A8E8AE2348933C00E893FB /* Support */ = {
157+
isa = PBXGroup;
158+
children = (
159+
64C0228523475A0E00A6D844 /* ScrollStack+Protocols.swift */,
160+
64C02253234735A800A6D844 /* UIView+AutoLayout_Extensions.swift */,
161+
);
162+
path = Support;
163+
sourceTree = "<group>";
164+
};
158165
64C0224A2347358400A6D844 /* Sources */ = {
159166
isa = PBXGroup;
160167
children = (
@@ -169,10 +176,8 @@
169176
64C0224F234735A800A6D844 /* ScrollStackViewController.swift */,
170177
64C02250234735A800A6D844 /* ScrollStack.swift */,
171178
64C02251234735A800A6D844 /* ScrollStackRow.swift */,
172-
64C02254234735A800A6D844 /* ScrollStackRowHighlightable.swift */,
173179
64C02252234735A800A6D844 /* ScrollStackSeparator.swift */,
174-
64C0228523475A0E00A6D844 /* ScrollStack+Support.swift */,
175-
64C02253234735A800A6D844 /* UIView+AutoLayout_Extensions.swift */,
180+
64A8E8AE2348933C00E893FB /* Support */,
176181
);
177182
path = ScrollStackController;
178183
sourceTree = "<group>";
@@ -183,6 +188,7 @@
183188
64C022672347360800A6D844 /* AppDelegate.swift */,
184189
64C022692347360800A6D844 /* SceneDelegate.swift */,
185190
64C0226B2347360800A6D844 /* ViewController.swift */,
191+
6402E1F12347A8540087963C /* Extension.swift */,
186192
64C0227C234753A100A6D844 /* VC1.swift */,
187193
64C022892347834300A6D844 /* VC2.swift */,
188194
64C0226D2347360800A6D844 /* Main.storyboard */,
@@ -419,13 +425,12 @@
419425
isa = PBXSourcesBuildPhase;
420426
buildActionMask = 2147483647;
421427
files = (
422-
64C0228623475A0E00A6D844 /* ScrollStack+Support.swift in Sources */,
428+
64C0228623475A0E00A6D844 /* ScrollStack+Protocols.swift in Sources */,
423429
64C02259234735A800A6D844 /* ScrollStackRow.swift in Sources */,
424430
64C02255234735A800A6D844 /* ScrollStackViewController.swift in Sources */,
425431
64C02257234735A800A6D844 /* ScrollStack.swift in Sources */,
426432
64C0225D234735A800A6D844 /* UIView+AutoLayout_Extensions.swift in Sources */,
427433
64C0225B234735A800A6D844 /* ScrollStackSeparator.swift in Sources */,
428-
64C0225F234735A800A6D844 /* ScrollStackRowHighlightable.swift in Sources */,
429434
);
430435
runOnlyForDeploymentPostprocessing = 0;
431436
};
@@ -440,29 +445,28 @@
440445
isa = PBXSourcesBuildPhase;
441446
buildActionMask = 2147483647;
442447
files = (
443-
64C0228723475A0E00A6D844 /* ScrollStack+Support.swift in Sources */,
448+
64C0228723475A0E00A6D844 /* ScrollStack+Protocols.swift in Sources */,
444449
64C0225A234735A800A6D844 /* ScrollStackRow.swift in Sources */,
445450
64C02256234735A800A6D844 /* ScrollStackViewController.swift in Sources */,
446451
64C02258234735A800A6D844 /* ScrollStack.swift in Sources */,
447452
64C0225E234735A800A6D844 /* UIView+AutoLayout_Extensions.swift in Sources */,
448453
64C0225C234735A800A6D844 /* ScrollStackSeparator.swift in Sources */,
449-
64C02260234735A800A6D844 /* ScrollStackRowHighlightable.swift in Sources */,
450454
);
451455
runOnlyForDeploymentPostprocessing = 0;
452456
};
453457
64C022612347360800A6D844 /* Sources */ = {
454458
isa = PBXSourcesBuildPhase;
455459
buildActionMask = 2147483647;
456460
files = (
457-
64C0228823475A0E00A6D844 /* ScrollStack+Support.swift in Sources */,
461+
64C0228823475A0E00A6D844 /* ScrollStack+Protocols.swift in Sources */,
458462
64C0227F2347582D00A6D844 /* ScrollStackRow.swift in Sources */,
459-
64C022802347582D00A6D844 /* ScrollStackRowHighlightable.swift in Sources */,
460463
64C0228A2347834300A6D844 /* VC2.swift in Sources */,
461464
64C022822347582D00A6D844 /* ScrollStackViewController.swift in Sources */,
462465
64C0226C2347360800A6D844 /* ViewController.swift in Sources */,
463466
64C022812347582D00A6D844 /* ScrollStackSeparator.swift in Sources */,
464467
64C0227E2347582D00A6D844 /* ScrollStack.swift in Sources */,
465468
64C022682347360800A6D844 /* AppDelegate.swift in Sources */,
469+
6402E1F22347A8540087963C /* Extension.swift in Sources */,
466470
64C022832347582D00A6D844 /* UIView+AutoLayout_Extensions.swift in Sources */,
467471
64C0227D234753A100A6D844 /* VC1.swift in Sources */,
468472
64C0226A2347360800A6D844 /* SceneDelegate.swift in Sources */,

ScrollStackControllerDemo/Base.lproj/Main.storyboard

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
2121
</view>
2222
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="a7Q-tz-rI1">
23-
<rect key="frame" x="20" y="64" width="100" height="30"/>
23+
<rect key="frame" x="20" y="64" width="153" height="30"/>
2424
<color key="backgroundColor" red="0.1333333333" green="0.31372549020000001" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2525
<constraints>
26-
<constraint firstAttribute="width" constant="100" id="eZt-64-3CB"/>
26+
<constraint firstAttribute="width" constant="153" id="eZt-64-3CB"/>
2727
<constraint firstAttribute="height" constant="30" id="uxI-ig-f5J"/>
2828
</constraints>
29-
<state key="normal" title="Toggle Axis">
29+
<state key="normal" title="Add new controller">
3030
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
3131
</state>
3232
<connections>
@@ -51,7 +51,7 @@
5151
</viewController>
5252
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
5353
</objects>
54-
<point key="canvasLocation" x="-383" y="29"/>
54+
<point key="canvasLocation" x="-384.05797101449281" y="28.794642857142854"/>
5555
</scene>
5656
<!--VC1-->
5757
<scene sceneID="F2C-MH-Lwo">
@@ -65,7 +65,7 @@
6565
<rect key="frame" x="182.5" y="134.5" width="51" height="31"/>
6666
</switch>
6767
</subviews>
68-
<color key="backgroundColor" systemColor="systemOrangeColor" red="1" green="0.58431372549019611" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
68+
<color key="backgroundColor" systemColor="systemOrangeColor" red="1" green="0.58431372550000005" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
6969
<constraints>
7070
<constraint firstItem="yVI-0r-6fw" firstAttribute="centerX" secondItem="aW5-uU-IfU" secondAttribute="centerX" id="Mdn-9x-vmJ"/>
7171
<constraint firstItem="yVI-0r-6fw" firstAttribute="centerY" secondItem="aW5-uU-IfU" secondAttribute="centerY" id="yQs-O6-5Cr"/>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Extension.swift
3+
// ScrollStackControllerDemo
4+
//
5+
// Created by Daniele Margutti on 04/10/2019.
6+
// Copyright © 2019 ScrollStackController. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
extension UIColor {
12+
13+
static func random(hue: CGFloat = CGFloat.random(in: 0...1),
14+
saturation: CGFloat = CGFloat.random(in: 0.5...1), // from 0.5 to 1.0 to stay away from white
15+
brightness: CGFloat = CGFloat.random(in: 0.5...1), // from 0.5 to 1.0 to stay away from black
16+
alpha: CGFloat = 1) -> UIColor {
17+
return UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: alpha)
18+
}
19+
20+
}

ScrollStackControllerDemo/VC1.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import UIKit
1010

1111
public class VC1: UIViewController, ScrollStackContainableController {
1212

13+
private var bestSize = CGFloat.random(in: 100..<500)
14+
1315
public static func create(backColor: UIColor) -> VC1 {
1416
let storyboard = UIStoryboard(name: "Main", bundle: nil)
1517
let vc = storyboard.instantiateViewController(identifier: "VC1") as! VC1
@@ -18,7 +20,7 @@ public class VC1: UIViewController, ScrollStackContainableController {
1820
}
1921

2022
public func sizeForAxis(_ axis: NSLayoutConstraint.Axis, row: ScrollStackRow, in stackView: ScrollStack) -> CGFloat? {
21-
return 100
23+
return bestSize
2224
}
2325

2426
}

ScrollStackControllerDemo/ViewController.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ class ViewController: UIViewController {
3838
}
3939

4040
@IBAction public func toggleAxis() {
41-
let otherVC = VC2.create(backColor: .white)
42-
43-
stackController.stackView.setRowHidden(index: 0, isHidden: true, animated: true)
41+
let stackView = stackController.stackView
42+
43+
let randomVC = VC2.create(backColor: UIColor.random())
44+
let position = Int.random(in: 0..<stackView.rows.count)
45+
stackView.addRow(controller: randomVC, at: .atIndex(position), animated: true)
46+
47+
48+
// stackController.stackView.setRowHidden(index: 0, isHidden: true, animated: true)
4449
// stackController.stackView.replaceRowAtIndex(1, withRow: otherVC, animated: true)
4550
// stackController.stackView.moveRowAtIndex(1, to: 2, animated: true)
4651
//stackController.stackView.axis = (stackController.stackView.axis == .horizontal ? .vertical : .horizontal)

0 commit comments

Comments
 (0)