Skip to content

Commit

Permalink
Merge pull request #346 from hyperoslo/improve/carousel-scroll-delegates
Browse files Browse the repository at this point in the history
Improve/carousel scroll delegates
  • Loading branch information
vadymmarkov authored Oct 28, 2016
2 parents 46eb79b + 6bbec84 commit c90a2f2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
9 changes: 4 additions & 5 deletions Sources/Shared/Extensions/SpotsProtocol+Mutation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ extension SpotsProtocol {
/// - parameter closure: A completion closure that is invoked when the setup of the new items is complete
///
/// - returns: A boolean value that determines if the closure should run in `process(changes:)`
fileprivate func setupItemsForSpot(_ index: Int, newComponents: [Component], withAnimation animation: Animation = .automatic, closure: Completion = nil) -> Bool {
fileprivate func setupItemsForSpot(at index: Int, newComponents: [Component], withAnimation animation: Animation = .automatic, closure: Completion = nil) -> Bool {
guard let spot = self.spot(at: index, ofType: Spotable.self) else { return false }
let newItems = spot.prepare(items: newComponents[index].items)
let oldItems = spot.items
Expand Down Expand Up @@ -266,9 +266,8 @@ extension SpotsProtocol {
spot.items = newItems
}) {
if !spot.items.filter({ !$0.children.isEmpty }).isEmpty {
spot.reload(nil, withAnimation: animation) {
if spot is Gridable { CATransaction.commit() }
closure?()
spot.reload(nil, withAnimation: animation) { [weak self] in
self?.finishReloading(spot: spot, withCompletion: closure)
}
} else {
spot.updateHeight() { [weak self] in
Expand Down Expand Up @@ -303,7 +302,7 @@ extension SpotsProtocol {
case .removed:
weakSelf.removeSpot(at: index)
case .items:
runClosure = weakSelf.setupItemsForSpot(index,
runClosure = weakSelf.setupItemsForSpot(at: index,
newComponents: newComponents,
withAnimation: animation,
closure: closure)
Expand Down
5 changes: 4 additions & 1 deletion Sources/iOS/Classes/Controller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ open class Controller: UIViewController, SpotsProtocol, CompositeDelegate, UIScr
spot.component.size = CGSize(
width: view.frame.size.width,
height: ceil(spot.render().frame.size.height))
spot.render().layoutIfNeeded()

if !spot.items.isEmpty {
spot.render().layoutIfNeeded()
}
}

#if os(iOS)
Expand Down
2 changes: 1 addition & 1 deletion Sources/iOS/Extensions/Gridable+Extensions+iOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ extension Gridable {

setup(collectionView.bounds.size)
collectionView.layoutIfNeeded()
completion?()

if animation == .none { UIView.setAnimationsEnabled(true) }
completion?()
}

/// Perform animation before mutation
Expand Down

0 comments on commit c90a2f2

Please sign in to comment.