Skip to content

Commit d9cf272

Browse files
authored
Merge pull request #281 from nytimes/develop
Merge master into develop
2 parents a6d27dd + 7ea04a9 commit d9cf272

30 files changed

+562
-181
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
Changes for users of the library currently on `develop`:
44

5+
- Fixed some tests, added tests for NYTPhotoViewerSinglePhotoDataSource
6+
- Fixed a strict warning and a subscripting bug in NYTPhotoViewerArrayDataSource.m
7+
- Added support for interstitial views
8+
9+
## [2.0.0](https://github.com/NYTimes/NYTPhotoViewer/releases/tag/2.0.0)
10+
11+
Changes for users of the library in 2.0.0:
12+
513
- Expose a data-source-oriented API for PhotosViewController ([#226](https://github.com/NYTimes/NYTPhotoViewer/pull/226))
614
- A data source no longer has to handle out-of-bounds indexes ([#227](https://github.com/NYTimes/NYTPhotoViewer/pull/227))
715
- The data source is not retained ([#227](https://github.com/NYTimes/NYTPhotoViewer/pull/227))

Example-Swift/Photo.swift

Lines changed: 0 additions & 19 deletions
This file was deleted.

Example-Swift/PhotoBox.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import NYTPhotoViewer
1212
/// A box allowing NYTPhotoViewer to consume Swift value types from our codebase.
1313
final class NYTPhotoBox: NSObject, NYTPhoto {
1414

15-
let value: Photo
15+
let value: PhotoItem
1616

17-
init(_ photo: Photo) {
18-
value = photo
17+
init(_ photoItem: PhotoItem) {
18+
value = photoItem
1919
}
2020

2121
// MARK: NYTPhoto
@@ -24,6 +24,14 @@ final class NYTPhotoBox: NSObject, NYTPhoto {
2424
var imageData: Data?
2525
var placeholderImage: UIImage?
2626

27+
var isPhoto: Bool {
28+
return value.itemType == .image
29+
}
30+
31+
var isView: Bool {
32+
return value.itemType == .view
33+
}
34+
2735
var attributedCaptionTitle: NSAttributedString?
2836

2937
var attributedCaptionSummary: NSAttributedString? {

Example-Swift/PhotoItem.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// PhotoItem.swift
3+
// NYTPhotoViewer
4+
//
5+
// Created by Chris Dzombak on 2/2/17.
6+
// Copyright © 2017 NYTimes. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
/// A photo item can either be an image or a view
12+
enum PhotoItemType {
13+
case image
14+
case view
15+
}
16+
17+
/// A photo may often be represented in a Swift application as a value type.
18+
struct PhotoItem {
19+
// This would usually be a URL, but for this demo we load images from the bundle.
20+
let name: String
21+
let summary: String
22+
let credit: String
23+
let itemType: PhotoItemType
24+
let identifier: Int
25+
26+
init(name: String = "", summary: String = "", credit: String = "", itemType: PhotoItemType, identifier: Int) {
27+
self.name = name
28+
self.summary = summary
29+
self.credit = credit
30+
self.itemType = itemType
31+
self.identifier = identifier
32+
}
33+
34+
}

Example-Swift/PhotoViewerCoordinator.swift

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import NYTPhotoViewer
1010

1111
/// Coordinates interaction between the application's data layer and the photo viewer component.
12-
final class PhotoViewerCoordinator: NYTPhotoViewerDataSource {
12+
final class PhotoViewerCoordinator: NSObject, NYTPhotoViewerDataSource {
1313
let slideshow: [NYTPhotoBox]
1414
let provider: PhotosProvider
1515

@@ -20,23 +20,43 @@ final class PhotoViewerCoordinator: NYTPhotoViewerDataSource {
2020
init(provider: PhotosProvider) {
2121
self.provider = provider
2222
self.slideshow = provider.fetchDemoSlideshow().map { NYTPhotoBox($0) }
23+
super.init()
2324
self.fetchPhotos()
2425
}
2526

2627
func fetchPhotos() {
2728
for box in slideshow {
28-
provider.fetchPhoto(named: box.value.name, then: { [weak self] (result) in
29-
box.image = result
30-
self?.photoViewer.update(box)
31-
})
29+
if box.isPhoto {
30+
provider.fetchPhoto(named: box.value.name, then: { [weak self] (result) in
31+
box.image = result
32+
self?.photoViewer.update(box)
33+
})
34+
}
3235
}
3336
}
3437

3538
// MARK: NYTPhotoViewerDataSource
3639

3740
@objc
3841
var numberOfPhotos: NSNumber? {
39-
return NSNumber(integerLiteral: slideshow.count)
42+
return NSNumber(integerLiteral: slideshow.filter({ $0.isPhoto }).count)
43+
}
44+
45+
@objc
46+
func numberOfInterstitialViews() -> NSNumber {
47+
return NSNumber(integerLiteral: slideshow.filter({ $0.isView }).count)
48+
}
49+
50+
@objc
51+
func isPhoto(at idx: Int) -> Bool {
52+
guard idx < slideshow.count else { return false }
53+
return slideshow[idx].isPhoto
54+
}
55+
56+
@objc
57+
func isInterstitialView(at idx: Int) -> Bool {
58+
guard idx < slideshow.count else { return false }
59+
return slideshow[idx].isView
4060
}
4161

4262
@objc
@@ -48,6 +68,7 @@ final class PhotoViewerCoordinator: NYTPhotoViewerDataSource {
4868
@objc
4969
func photo(at index: Int) -> NYTPhoto? {
5070
guard index < slideshow.count else { return nil }
71+
guard slideshow[index].isPhoto else { return nil }
5172
return slideshow[index]
5273
}
5374
}

Example-Swift/PhotosProvider.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import UIKit
1010

1111
/// A component of your data layer, which might load photos from the cache or network.
1212
final class PhotosProvider {
13-
typealias Slideshow = [Photo]
13+
typealias Slideshow = [PhotoItem]
1414

1515
/// Simulate a synchronous fetch of a slideshow, perhaps from a local database.
1616
func fetchDemoSlideshow() -> Slideshow {
17-
return (0...4).map { demoPhoto(identifier: $0) }
17+
return (0...7).map { [2,5].contains($0) ? demoView(identifier: $0) : demoPhoto(identifier: $0) }
1818
}
1919

2020
/// Simulate fetching a photo from the network.
@@ -29,7 +29,7 @@ final class PhotosProvider {
2929
}
3030

3131
extension PhotosProvider {
32-
fileprivate func demoPhoto(identifier: Int) -> Photo {
32+
fileprivate func demoPhoto(identifier: Int) -> PhotoItem {
3333
let photoName: String
3434
let photoSummary: String
3535
let photoCredit: String
@@ -44,6 +44,10 @@ extension PhotosProvider {
4444
photoCredit = "Photo: Nic Lehoux"
4545
}
4646

47-
return Photo(name: photoName, summary: photoSummary, credit: photoCredit, identifier: identifier)
47+
return PhotoItem(name: photoName, summary: photoSummary, credit: photoCredit, itemType: .image, identifier: identifier)
48+
}
49+
50+
fileprivate func demoView(identifier: Int) -> PhotoItem {
51+
return PhotoItem(itemType: .view, identifier: identifier)
4852
}
4953
}

Example-Swift/ViewController.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,15 @@ extension ViewController: NYTPhotosViewControllerDelegate {
6868
func photosViewControllerDidDismiss(_ photosViewController: NYTPhotosViewController) {
6969
photoViewerCoordinator = nil
7070
}
71+
72+
func photosViewController(_ photosViewController: NYTPhotosViewController, interstitialViewAt index: UInt) -> UIView {
73+
let redView = UIView(frame: CGRect(origin: .zero, size: CGSize(width: photosViewController.view.frame.width, height: 200)))
74+
redView.backgroundColor = .red
75+
redView.autoresizingMask = [.flexibleWidth]
76+
return redView
77+
}
78+
79+
func photosViewController(_ photosViewController: NYTPhotosViewController, didNavigateToInterstialView view: UIView, at index: UInt) {
80+
view.backgroundColor = .blue
81+
}
7182
}

NYTPhotoViewer.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "NYTPhotoViewer"
3-
s.version = "2.0.0"
3+
s.version = "3.0.0"
44

55
s.description = <<-DESC
66
NYTPhotoViewer is a slideshow and image viewer that includes double tap to zoom, captions, support for multiple images, interactive flick to dismiss, animated zooming presentation, and more.

0 commit comments

Comments
 (0)