Skip to content

Commit 4a33bb5

Browse files
authored
call layoutIfNeeded before doing batch updates (#13)
1 parent c2920a2 commit 4a33bb5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

StackScrollView/StackScrollView.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
115115

116116
open func insert(views _views: [UIView], at index: Int, animated: Bool) {
117117

118+
layoutIfNeeded()
119+
118120
var _views = _views
119121
_views.removeAll(where: views.contains(_:))
120122
views.insert(contentsOf: _views, at: index)
@@ -164,7 +166,9 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
164166
}
165167

166168
open func remove(view: UIView, animated: Bool) {
167-
169+
170+
layoutIfNeeded()
171+
168172
if let index = views.firstIndex(of: view) {
169173
views.remove(at: index)
170174
if animated {
@@ -200,6 +204,8 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
200204

201205
open func remove(views: [UIView], animated: Bool) {
202206

207+
layoutIfNeeded()
208+
203209
var indicesForRemove: [Int] = []
204210

205211
for view in views {

0 commit comments

Comments
 (0)