Skip to content

Commit 888067c

Browse files
authored
Merge pull request #155 from hyperoslo/fix/image_download
Allow custom download
2 parents 4f5ee72 + 0180ca7 commit 888067c

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
[![Platform](https://img.shields.io/cocoapods/p/Lightbox.svg?style=flat)](http://cocoadocs.org/docsets/Lightbox)
77
![Swift](https://img.shields.io/badge/%20in-swift%204.0-orange.svg)
88

9-
[Demo](https://appetize.io/app/wfgwc2uvg82m9pzbt17p4rrgh4?device=iphone5s&scale=75&orientation=portrait&osVersion=9.3)
10-
119
<img src="https://raw.githubusercontent.com/hyperoslo/Lightbox/master/Images/Icon.png" alt="Lightbox Icon" align="right" />
1210

1311
**Lightbox** is a convenient and easy to use image viewer for your iOS app,
@@ -17,10 +15,11 @@ packed with all the features you expect:
1715
- [x] Video support.
1816
- [x] Double-tap to zoom.
1917
- [x] Image caption.
20-
- [x] Dynamic background.
18+
- [x] Dynamic background based on [Hue](https://github.com/hyperoslo/Hue)
19+
- [x] Remote image loading and caching based on [Imaginary](https://github.com/hyperoslo/Imaginary)
2120
- [x] Interactive transition animations.
2221
- [x] Powerful configuration.
23-
- [x] Demo project.
22+
- [x] [Live Demo](https://appetize.io/app/wfgwc2uvg82m9pzbt17p4rrgh4?device=iphone5s&scale=75&orientation=portrait&osVersion=9.3)
2423

2524
<div align="center">
2625
<img src="Images/demo.png" height="500">
@@ -111,9 +110,7 @@ extension ViewController: LightboxControllerDismissalDelegate: class {
111110

112111
### Image loading
113112

114-
By default images are loaded using `sendAsynchronousRequest` method of
115-
`NSURLConnection`. But it's easy to change this behavior using **Lightbox**
116-
configuration.
113+
By default images are loaded using [Imagary](https://github.com/hyperoslo/Imaginary) for reliable loading and caching. But it's easy to change this behavior using **LightboxConfig**
117114

118115
```swift
119116
LightboxConfig.loadImage = {
@@ -124,7 +121,7 @@ LightboxConfig.loadImage = {
124121

125122
### Video
126123

127-
**Lightbox** has video support out of the box. Configure video by using `videoURL`:
124+
**Lightbox** can show and plays video using default `AVPlayerViewController`. Showning video by using `videoURL`:
128125

129126
```swift
130127
LightboxImage(
@@ -162,7 +159,7 @@ LightboxConfig.DeleteButton.image = UIImage(named: ImageList.Lightbox.deleteButt
162159
LightboxConfig.DeleteButton.textAttributes = TextAttributes.Lightbox.deleteButton
163160
LightboxConfig.DeleteButton.text = "Delete"
164161

165-
LightboxConfig.InfoLabel.ellipsisText = "ShowMore"
162+
LightboxConfig.InfoLabel.ellipsisText = "Show more"
166163
```
167164

168165
## Installation

Source/LightboxConfig.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import UIKit
22
import Hue
33
import AVKit
44
import AVFoundation
5+
import Imaginary
56

67
public class LightboxConfig {
78
/// Whether to show status bar while Lightbox is presented
@@ -17,6 +18,21 @@ public class LightboxConfig {
1718
}
1819
}
1920

21+
/// How to load image onto UIImageView
22+
public static var loadImage: (UIImageView, URL, ((UIImage?) -> Void)?) -> Void =
23+
{ (imageView, imageURL , completion) in
24+
25+
// Use Imaginary by default
26+
imageView.setImage(url: imageURL, placeholder: nil, completion: { result in
27+
switch result {
28+
case .value(let image):
29+
completion?(image)
30+
case .error:
31+
completion?(nil)
32+
}
33+
})
34+
}
35+
2036
/// Indicator is used to show while image is being fetched
2137
public static var makeLoadingIndicator: () -> UIView = {
2238
return LoadingIndicator()

Source/LightboxImage.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,12 @@ open class LightboxImage {
2222
self.videoURL = videoURL
2323
}
2424

25-
open func addImageTo(_ imageView: UIImageView, completion: ((_ image: UIImage?) -> Void)? = nil) {
25+
open func addImageTo(_ imageView: UIImageView, completion: ((UIImage?) -> Void)? = nil) {
2626
if let image = image {
2727
imageView.image = image
2828
completion?(image)
2929
} else if let imageURL = imageURL {
30-
imageView.setImage(url: imageURL, placeholder: nil, completion: { result in
31-
switch result {
32-
case .value(let image):
33-
completion?(image)
34-
case .error:
35-
completion?(nil)
36-
}
37-
})
30+
LightboxConfig.loadImage(imageView, imageURL, completion)
3831
}
3932
}
4033
}

0 commit comments

Comments
 (0)