Skip to content

Commit 2583b0a

Browse files
committed
Merge pull request #45 from hyperoslo/feature/loading-spinner
Feature/loading spinner
2 parents 758b30e + a005564 commit 2583b0a

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

Source/LightboxDataSource.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ extension LightboxController: UICollectionViewDataSource {
1414
let config = LightboxConfig.sharedInstance.config
1515

1616
cell.parentViewController = self
17+
cell.loadingIndicator.alpha = 0
1718
cell.setupTransitionManager()
1819

1920
if let imageString = image as? String {
2021
if let imageURL = NSURL(string: imageString) where config.remoteImages {
22+
cell.loadingIndicator.alpha = 1
2123
config.loadImage(
2224
imageView: cell.lightboxView.imageView, URL: imageURL) { error in
23-
if error == nil { cell.lightboxView.updateViewLayout() }
25+
if error == nil {
26+
cell.loadingIndicator.alpha = 0
27+
cell.lightboxView.updateViewLayout()
28+
}
2429
}
2530
} else {
2631
cell.lightboxView.imageView.image = UIImage(named: imageString)

Source/LightboxView.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ public class LightboxView: UIView {
1010
let imageView = UIImageView(frame: CGRectZero)
1111
imageView.translatesAutoresizingMaskIntoConstraints = false
1212
imageView.userInteractionEnabled = true
13+
1314
return imageView
14-
}()
15+
}()
1516

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

2627
return scrollView
27-
}()
28+
}()
2829

2930
var imageConstraintLeading: NSLayoutConstraint!
3031
var imageConstraintTrailing: NSLayoutConstraint!
@@ -45,7 +46,7 @@ public class LightboxView: UIView {
4546
minimumZoomScale = config.zoom.minimumScale
4647
maximumZoomScale = config.zoom.maximumScale
4748

48-
scrollView.addSubview(self.imageView)
49+
scrollView.addSubview(imageView)
4950
addSubview(scrollView)
5051
}
5152

Source/LightboxViewCell.swift

+20
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,20 @@ public class LightboxViewCell: UICollectionViewCell {
1616
return lightboxView
1717
}()
1818

19+
public lazy var loadingIndicator: UIActivityIndicatorView = {
20+
let loadingIndicator = UIActivityIndicatorView(activityIndicatorStyle: .White)
21+
loadingIndicator.startAnimating()
22+
loadingIndicator.alpha = 0
23+
loadingIndicator.translatesAutoresizingMaskIntoConstraints = false
24+
25+
return loadingIndicator
26+
}()
27+
1928
public override func layoutSubviews() {
2029
super.layoutSubviews()
30+
31+
if loadingIndicator.superview == nil { self.contentView.addSubview(loadingIndicator) }
32+
2133
setupConstraints()
2234
lightboxView.updateViewLayout()
2335
}
@@ -37,6 +49,14 @@ public class LightboxViewCell: UICollectionViewCell {
3749
multiplier: 1, constant: 0))
3850
}
3951

52+
addConstraint(NSLayoutConstraint(item: loadingIndicator, attribute: .CenterX,
53+
relatedBy: .Equal, toItem: self.contentView, attribute: .CenterX,
54+
multiplier: 1, constant: 0))
55+
56+
addConstraint(NSLayoutConstraint(item: loadingIndicator, attribute: .CenterY,
57+
relatedBy: .Equal, toItem: self.contentView, attribute: .CenterY,
58+
multiplier: 1, constant: 0))
59+
4060
constraintsAdded = true
4161
}
4262
}

0 commit comments

Comments
 (0)