Skip to content

Commit b59da0e

Browse files
committed
🤔WIP [ci skip]
1 parent c0acbdb commit b59da0e

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

StackScrollView-Demo/ViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class ViewController: UIViewController {
8787
// Dispose of any resources that can be recreated.
8888
}
8989

90-
private var stackScrollView = BetaStackScrollView()
90+
private var stackScrollView = StackScrollView()
9191
}
9292

9393
class LabelStackViewCell: UIView {
@@ -121,7 +121,7 @@ class LabelStackViewCell: UIView {
121121
let detailLabel = UILabel()
122122
}
123123

124-
class SwitchStackViewCell: UIView, BetaStackScrollViewCellType {
124+
class SwitchStackViewCell: UIView, StackScrollViewCellType {
125125

126126
var valueChanged: (Bool) -> Void = { _ in }
127127

@@ -158,7 +158,7 @@ class SwitchStackViewCell: UIView, BetaStackScrollViewCellType {
158158

159159
@objc fileprivate func switchValueChanged() {
160160

161-
valueChanged(switchView.isOn)
161+
valueChanged(switchView.isOn)
162162
updateLayout(animated: true)
163163
}
164164
}

StackScrollView.xcodeproj/project.pbxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
4B6C2DB71D8DA68E003D3A46 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4B6C2DB51D8DA68E003D3A46 /* Main.storyboard */; };
1717
4B6C2DB91D8DA68E003D3A46 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B6C2DB81D8DA68E003D3A46 /* Assets.xcassets */; };
1818
4B6C2DBC1D8DA68E003D3A46 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4B6C2DBA1D8DA68E003D3A46 /* LaunchScreen.storyboard */; };
19-
4BDB87D71DBFB49500E70D5B /* BetaStackScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BDB87D61DBFB49500E70D5B /* BetaStackScrollView.swift */; };
2019
4BDB87D91DBFBC8F00E70D5B /* RevealServer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BDB87D81DBFBC8800E70D5B /* RevealServer.framework */; };
2120
4BDB87DA1DBFBC8F00E70D5B /* RevealServer.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4BDB87D81DBFBC8800E70D5B /* RevealServer.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2221
4BE8B6ED1D8E5A9700A4DC33 /* StackScrollView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B6C2D991D8DA3FB003D3A46 /* StackScrollView.framework */; };
@@ -270,7 +269,6 @@
270269
buildActionMask = 2147483647;
271270
files = (
272271
4B6C2DA71D8DA42A003D3A46 /* StackScrollViewCellType.swift in Sources */,
273-
4BDB87D71DBFB49500E70D5B /* BetaStackScrollView.swift in Sources */,
274272
4B6C2DA61D8DA42A003D3A46 /* StackScrollView.swift in Sources */,
275273
);
276274
runOnlyForDeploymentPostprocessing = 0;

StackScrollView/BetaStackScrollView.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extension BetaStackScrollViewCellType where Self: UIView {
2727
}
2828

2929
public func updateLayout(animated: Bool) {
30+
// invalidateIntrinsicContentSize()
3031
stackScrollView.updateLayout(animated: animated)
3132
}
3233

@@ -130,14 +131,20 @@ open class BetaStackScrollView: UIView, UITableViewDataSource, UITableViewDelega
130131
private let tableView = UITableView(frame: .zero, style: .plain)
131132

132133
public func updateLayout(animated: Bool) {
134+
135+
cells.forEach {
136+
$0.contentView.subviews.first?.invalidateIntrinsicContentSize()
137+
}
138+
133139
if animated {
134-
UIView.animate(withDuration: 0.3, animations: {
135-
self.tableView.beginUpdates()
136-
self.tableView.endUpdates()
137-
})
140+
self.tableView.beginUpdates()
141+
self.tableView.endUpdates()
142+
138143
}else {
139-
tableView.beginUpdates()
140-
tableView.endUpdates()
144+
UIView.performWithoutAnimation {
145+
tableView.beginUpdates()
146+
tableView.endUpdates()
147+
}
141148
}
142149
}
143150

@@ -181,7 +188,6 @@ open class BetaStackScrollView: UIView, UITableViewDataSource, UITableViewDelega
181188
let cell = cells[indexPath.row]
182189

183190
let contentView = cell.contentView
184-
contentView.invalidateIntrinsicContentSize()
185191

186192
guard contentView.subviews.first?.isHidden == false else {
187193
return 0

StackScrollView/StackScrollViewCellType.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,22 @@ extension StackScrollViewCellType where Self: UIView {
4848

4949
stackScrollView.scroll(to: self, animated: animated)
5050
}
51+
52+
public func updateLayout(animated: Bool) {
53+
invalidateIntrinsicContentSize()
54+
55+
if animated {
56+
UIView.animate(withDuration: 0.3, delay: 0, options: [], animations: {
57+
self.stackScrollView.setNeedsLayout()
58+
self.stackScrollView.layoutIfNeeded()
59+
}) { (finish) in
60+
61+
}
62+
} else {
63+
UIView.performWithoutAnimation {
64+
stackScrollView.setNeedsLayout()
65+
stackScrollView.layoutIfNeeded()
66+
}
67+
}
68+
}
5169
}

0 commit comments

Comments
 (0)