Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactored to align to the current project code style
  • Loading branch information
Aymenworks authored Sep 6, 2018
commit 736f2364eea04b5364fa5bf99d3e59faf9efea6c
48 changes: 41 additions & 7 deletions StackScrollView/StackScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,50 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
}
}

open func remove(viewsToRemove : [UIView]) {
for view in viewsToRemove {
if let index = views.index(of: view) {
views.remove(at: index)
open func remove(views: [UIView], animated: Bool) {

var indicesForRemove: [Int] = []

for view in views {
if let index = self.views.index(of: view) {
indicesForRemove.append(index)
}
}

// It seems that the layout is not updated properly unless the order is aligned.
indicesForRemove.sort(by: >)

for index in indicesForRemove {
self.views.remove(at: index)
}

if animated {
UIView.animate(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but doesn't performBatchUpdates already animate the deletion?

withDuration: 0.5,
delay: 0,
usingSpringWithDamping: 1,
initialSpringVelocity: 0,
options: [
.beginFromCurrentState,
.allowUserInteraction,
.overrideInheritedCurve,
.overrideInheritedOptions,
.overrideInheritedDuration
],
animations: {
self.performBatchUpdates({
self.deleteItems(at: indicesForRemove.map { IndexPath.init(item: $0, section: 0) })
}, completion: nil)
})
} else {
UIView.performWithoutAnimation {
performBatchUpdates({
self.deleteItems(at: indicesForRemove.map { IndexPath.init(item: $0, section: 0) })
}, completion: nil)
}
}

reloadData()
}

open func scroll(to view: UIView, animated: Bool) {

let targetRect = view.convert(view.bounds, to: self)
Expand Down