Skip to content

Commit 4aff71d

Browse files
committed
Update remove()
1 parent 54dbc26 commit 4aff71d

File tree

7 files changed

+72
-29
lines changed

7 files changed

+72
-29
lines changed

Cartfile.resolved

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github "nakiostudio/EasyPeasy" "1.4.1"
21
github "devxoul/Then" "2.1.0"
2+
github "nakiostudio/EasyPeasy" "1.4.2"

RevealServer.framework/Info.plist

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<plist version="1.0">
44
<dict>
55
<key>BuildMachineOSBuild</key>
6-
<string>16B2555</string>
6+
<string>16E195</string>
77
<key>CFBundleDevelopmentRegion</key>
88
<string>en</string>
99
<key>CFBundleExecutable</key>
@@ -17,31 +17,31 @@
1717
<key>CFBundlePackageType</key>
1818
<string>FMWK</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>7</string>
20+
<string>8</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleSupportedPlatforms</key>
2424
<array>
2525
<string>iPhoneOS</string>
2626
</array>
2727
<key>CFBundleVersion</key>
28-
<string>9558</string>
28+
<string>9667</string>
2929
<key>DTCompiler</key>
3030
<string>com.apple.compilers.llvm.clang.1_0</string>
3131
<key>DTPlatformBuild</key>
32-
<string>14C89</string>
32+
<string>14E269</string>
3333
<key>DTPlatformName</key>
3434
<string>iphoneos</string>
3535
<key>DTPlatformVersion</key>
36-
<string>10.2</string>
36+
<string>10.3</string>
3737
<key>DTSDKBuild</key>
38-
<string>14C89</string>
38+
<string>14E269</string>
3939
<key>DTSDKName</key>
40-
<string>iphoneos10.2</string>
40+
<string>iphoneos10.3</string>
4141
<key>DTXcode</key>
42-
<string>0821</string>
42+
<string>0830</string>
4343
<key>DTXcodeBuild</key>
44-
<string>8C1002</string>
44+
<string>8E162</string>
4545
<key>MinimumOSVersion</key>
4646
<string>8.0</string>
4747
<key>UIDeviceFamily</key>
-5.09 MB
Binary file not shown.

RevealServer.framework/_CodeSignature/CodeResources

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</data>
1111
<key>Info.plist</key>
1212
<data>
13-
mRYRWnn89cvA0oOFg/OtVl0TKqA=
13+
LQTBZDrBuFWf//dKyd0gwtMMTv0=
1414
</data>
1515
<key>Modules/module.modulemap</key>
1616
<data>

StackScrollView-Demo/ViewController.swift

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,20 @@ class ViewController: UIViewController {
8989
private var stackScrollView = StackScrollView()
9090
}
9191

92-
class LabelStackViewCell: UIView {
92+
class LabelStackViewCell: UIView, StackScrollViewCellType {
93+
94+
let button = UIButton(type: .system)
95+
let titleLabel = UILabel()
96+
let detailLabel = UILabel()
9397

9498
init() {
9599
super.init(frame: .zero)
96100

101+
button.setTitle("Remove", for: .normal)
102+
97103
addSubview(titleLabel)
98104
addSubview(detailLabel)
105+
addSubview(button)
99106

100107
titleLabel <- [
101108
Left(8),
@@ -106,6 +113,13 @@ class LabelStackViewCell: UIView {
106113
Right(8),
107114
CenterY(),
108115
]
116+
117+
button <- [
118+
CenterX(),
119+
CenterY(),
120+
]
121+
122+
button.addTarget(self, action: #selector(tap), for: .touchUpInside)
109123
}
110124

111125
override var intrinsicContentSize : CGSize {
@@ -116,8 +130,10 @@ class LabelStackViewCell: UIView {
116130
fatalError("init(coder:) has not been implemented")
117131
}
118132

119-
let titleLabel = UILabel()
120-
let detailLabel = UILabel()
133+
@objc private func tap() {
134+
135+
remove()
136+
}
121137
}
122138

123139
class SwitchStackViewCell: UIView, StackScrollViewCellType {
@@ -157,10 +173,10 @@ class SwitchStackViewCell: UIView, StackScrollViewCellType {
157173
]
158174

159175
label <- [
160-
Top().with(.mediumPriority),
176+
Top().with(.medium),
161177
Right(),
162178
Left(),
163-
Bottom().with(.mediumPriority),
179+
Bottom().with(.medium),
164180
CenterY(),
165181
]
166182

StackScrollView/StackScrollView.swift

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
3333
}
3434

3535
open var views: [UIView] {
36-
return source.map { $0.0 }
36+
return source
3737
}
3838

39-
private var source: [(UIView, String)] = []
39+
private var source: [UIView] = []
4040

4141
public convenience init() {
4242
self.init(frame: .zero)
@@ -73,11 +73,7 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
7373

7474
open func append(view: UIView) {
7575

76-
let key = UUID().uuidString
77-
source.append((view, key))
78-
79-
register(Cell.self, forCellWithReuseIdentifier: key)
80-
76+
source.append(view)
8177
reloadData()
8278
}
8379

@@ -91,9 +87,36 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
9187

9288
open func remove(view: UIView, animated: Bool) {
9389

94-
if let index = source.map({ $0.0 }).index(of: view) {
90+
if let index = source.index(of: view) {
9591
source.remove(at: index)
96-
view.removeFromSuperview()
92+
if animated {
93+
UIView.animate(
94+
withDuration: 0.5,
95+
delay: 0,
96+
usingSpringWithDamping: 1,
97+
initialSpringVelocity: 0,
98+
options: [
99+
.beginFromCurrentState,
100+
.allowUserInteraction,
101+
.overrideInheritedCurve,
102+
.overrideInheritedOptions,
103+
.overrideInheritedDuration
104+
],
105+
animations: {
106+
self.performBatchUpdates({
107+
self.deleteItems(at: [IndexPath.init(item: index, section: 0)])
108+
}, completion: nil)
109+
}) { (finish) in
110+
111+
}
112+
113+
} else {
114+
UIView.performWithoutAnimation {
115+
performBatchUpdates({
116+
self.deleteItems(at: [IndexPath.init(item: index, section: 0)])
117+
}, completion: nil)
118+
}
119+
}
97120
}
98121
}
99122

@@ -104,7 +127,7 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
104127
}
105128

106129
open func scroll(to view: UIView, at position: UICollectionViewScrollPosition, animated: Bool) {
107-
if let index = source.map({ $0.0 }).index(of: view) {
130+
if let index = source.index(of: view) {
108131
scrollToItem(at: IndexPath(item: index, section: 0), at: position, animated: animated)
109132
}
110133
}
@@ -123,9 +146,9 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
123146

124147
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
125148

126-
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: source[indexPath.item].1, for: indexPath)
149+
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath)
127150

128-
let view = source[indexPath.item].0
151+
let view = source[indexPath.item]
129152

130153
if view.superview == cell.contentView {
131154
return cell
@@ -163,7 +186,7 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
163186

164187
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
165188

166-
let view = source[indexPath.item].0
189+
let view = source[indexPath.item]
167190

168191
let width: NSLayoutConstraint = {
169192

StackScrollView/StackScrollViewCellType.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ extension StackScrollViewCellType where Self: UIView {
5151
invalidateIntrinsicContentSize()
5252
stackScrollView?.updateLayout(animated: animated)
5353
}
54+
55+
public func remove() {
56+
stackScrollView?.remove(view: self, animated: true)
57+
}
5458
}

0 commit comments

Comments
 (0)