Skip to content

Commit

Permalink
Merge pull request #45 from hyperoslo/feature/loading-spinner
Browse files Browse the repository at this point in the history
Feature/loading spinner
  • Loading branch information
vadymmarkov committed Oct 12, 2015
2 parents 758b30e + a005564 commit 2583b0a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Source/LightboxDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ extension LightboxController: UICollectionViewDataSource {
let config = LightboxConfig.sharedInstance.config

cell.parentViewController = self
cell.loadingIndicator.alpha = 0
cell.setupTransitionManager()

if let imageString = image as? String {
if let imageURL = NSURL(string: imageString) where config.remoteImages {
cell.loadingIndicator.alpha = 1
config.loadImage(
imageView: cell.lightboxView.imageView, URL: imageURL) { error in
if error == nil { cell.lightboxView.updateViewLayout() }
if error == nil {
cell.loadingIndicator.alpha = 0
cell.lightboxView.updateViewLayout()
}
}
} else {
cell.lightboxView.imageView.image = UIImage(named: imageString)
Expand Down
7 changes: 4 additions & 3 deletions Source/LightboxView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ public class LightboxView: UIView {
let imageView = UIImageView(frame: CGRectZero)
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.userInteractionEnabled = true

return imageView
}()
}()

lazy var scrollView: UIScrollView = { [unowned self] in
let scrollView = UIScrollView(frame: CGRectZero)
Expand All @@ -24,7 +25,7 @@ public class LightboxView: UIView {
scrollView.showsHorizontalScrollIndicator = false

return scrollView
}()
}()

var imageConstraintLeading: NSLayoutConstraint!
var imageConstraintTrailing: NSLayoutConstraint!
Expand All @@ -45,7 +46,7 @@ public class LightboxView: UIView {
minimumZoomScale = config.zoom.minimumScale
maximumZoomScale = config.zoom.maximumScale

scrollView.addSubview(self.imageView)
scrollView.addSubview(imageView)
addSubview(scrollView)
}

Expand Down
20 changes: 20 additions & 0 deletions Source/LightboxViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@ public class LightboxViewCell: UICollectionViewCell {
return lightboxView
}()

public lazy var loadingIndicator: UIActivityIndicatorView = {
let loadingIndicator = UIActivityIndicatorView(activityIndicatorStyle: .White)
loadingIndicator.startAnimating()
loadingIndicator.alpha = 0
loadingIndicator.translatesAutoresizingMaskIntoConstraints = false

return loadingIndicator
}()

public override func layoutSubviews() {
super.layoutSubviews()

if loadingIndicator.superview == nil { self.contentView.addSubview(loadingIndicator) }

setupConstraints()
lightboxView.updateViewLayout()
}
Expand All @@ -37,6 +49,14 @@ public class LightboxViewCell: UICollectionViewCell {
multiplier: 1, constant: 0))
}

addConstraint(NSLayoutConstraint(item: loadingIndicator, attribute: .CenterX,
relatedBy: .Equal, toItem: self.contentView, attribute: .CenterX,
multiplier: 1, constant: 0))

addConstraint(NSLayoutConstraint(item: loadingIndicator, attribute: .CenterY,
relatedBy: .Equal, toItem: self.contentView, attribute: .CenterY,
multiplier: 1, constant: 0))

constraintsAdded = true
}
}
Expand Down

0 comments on commit 2583b0a

Please sign in to comment.