Skip to content

Commit

Permalink
Merge pull request #281 from nytimes/develop
Browse files Browse the repository at this point in the history
Merge master into develop
  • Loading branch information
yorkepb authored Oct 7, 2019
2 parents a6d27dd + 7ea04a9 commit d9cf272
Show file tree
Hide file tree
Showing 30 changed files with 562 additions and 181 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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

- Fixed some tests, added tests for NYTPhotoViewerSinglePhotoDataSource
- Fixed a strict warning and a subscripting bug in NYTPhotoViewerArrayDataSource.m
- Added support for interstitial views

## [2.0.0](https://github.com/NYTimes/NYTPhotoViewer/releases/tag/2.0.0)

Changes for users of the library in 2.0.0:

- Expose a data-source-oriented API for PhotosViewController ([#226](https://github.com/NYTimes/NYTPhotoViewer/pull/226))
- A data source no longer has to handle out-of-bounds indexes ([#227](https://github.com/NYTimes/NYTPhotoViewer/pull/227))
- The data source is not retained ([#227](https://github.com/NYTimes/NYTPhotoViewer/pull/227))
Expand Down
19 changes: 0 additions & 19 deletions Example-Swift/Photo.swift

This file was deleted.

14 changes: 11 additions & 3 deletions Example-Swift/PhotoBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import NYTPhotoViewer
/// A box allowing NYTPhotoViewer to consume Swift value types from our codebase.
final class NYTPhotoBox: NSObject, NYTPhoto {

let value: Photo
let value: PhotoItem

init(_ photo: Photo) {
value = photo
init(_ photoItem: PhotoItem) {
value = photoItem
}

// MARK: NYTPhoto
Expand All @@ -24,6 +24,14 @@ final class NYTPhotoBox: NSObject, NYTPhoto {
var imageData: Data?
var placeholderImage: UIImage?

var isPhoto: Bool {
return value.itemType == .image
}

var isView: Bool {
return value.itemType == .view
}

var attributedCaptionTitle: NSAttributedString?

var attributedCaptionSummary: NSAttributedString? {
Expand Down
34 changes: 34 additions & 0 deletions Example-Swift/PhotoItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// PhotoItem.swift
// NYTPhotoViewer
//
// Created by Chris Dzombak on 2/2/17.
// Copyright © 2017 NYTimes. All rights reserved.
//

import UIKit

/// A photo item can either be an image or a view
enum PhotoItemType {
case image
case view
}

/// A photo may often be represented in a Swift application as a value type.
struct PhotoItem {
// This would usually be a URL, but for this demo we load images from the bundle.
let name: String
let summary: String
let credit: String
let itemType: PhotoItemType
let identifier: Int

init(name: String = "", summary: String = "", credit: String = "", itemType: PhotoItemType, identifier: Int) {
self.name = name
self.summary = summary
self.credit = credit
self.itemType = itemType
self.identifier = identifier
}

}
33 changes: 27 additions & 6 deletions Example-Swift/PhotoViewerCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import NYTPhotoViewer

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

Expand All @@ -20,23 +20,43 @@ final class PhotoViewerCoordinator: NYTPhotoViewerDataSource {
init(provider: PhotosProvider) {
self.provider = provider
self.slideshow = provider.fetchDemoSlideshow().map { NYTPhotoBox($0) }
super.init()
self.fetchPhotos()
}

func fetchPhotos() {
for box in slideshow {
provider.fetchPhoto(named: box.value.name, then: { [weak self] (result) in
box.image = result
self?.photoViewer.update(box)
})
if box.isPhoto {
provider.fetchPhoto(named: box.value.name, then: { [weak self] (result) in
box.image = result
self?.photoViewer.update(box)
})
}
}
}

// MARK: NYTPhotoViewerDataSource

@objc
var numberOfPhotos: NSNumber? {
return NSNumber(integerLiteral: slideshow.count)
return NSNumber(integerLiteral: slideshow.filter({ $0.isPhoto }).count)
}

@objc
func numberOfInterstitialViews() -> NSNumber {
return NSNumber(integerLiteral: slideshow.filter({ $0.isView }).count)
}

@objc
func isPhoto(at idx: Int) -> Bool {
guard idx < slideshow.count else { return false }
return slideshow[idx].isPhoto
}

@objc
func isInterstitialView(at idx: Int) -> Bool {
guard idx < slideshow.count else { return false }
return slideshow[idx].isView
}

@objc
Expand All @@ -48,6 +68,7 @@ final class PhotoViewerCoordinator: NYTPhotoViewerDataSource {
@objc
func photo(at index: Int) -> NYTPhoto? {
guard index < slideshow.count else { return nil }
guard slideshow[index].isPhoto else { return nil }
return slideshow[index]
}
}
12 changes: 8 additions & 4 deletions Example-Swift/PhotosProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import UIKit

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

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

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

extension PhotosProvider {
fileprivate func demoPhoto(identifier: Int) -> Photo {
fileprivate func demoPhoto(identifier: Int) -> PhotoItem {
let photoName: String
let photoSummary: String
let photoCredit: String
Expand All @@ -44,6 +44,10 @@ extension PhotosProvider {
photoCredit = "Photo: Nic Lehoux"
}

return Photo(name: photoName, summary: photoSummary, credit: photoCredit, identifier: identifier)
return PhotoItem(name: photoName, summary: photoSummary, credit: photoCredit, itemType: .image, identifier: identifier)
}

fileprivate func demoView(identifier: Int) -> PhotoItem {
return PhotoItem(itemType: .view, identifier: identifier)
}
}
11 changes: 11 additions & 0 deletions Example-Swift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,15 @@ extension ViewController: NYTPhotosViewControllerDelegate {
func photosViewControllerDidDismiss(_ photosViewController: NYTPhotosViewController) {
photoViewerCoordinator = nil
}

func photosViewController(_ photosViewController: NYTPhotosViewController, interstitialViewAt index: UInt) -> UIView {
let redView = UIView(frame: CGRect(origin: .zero, size: CGSize(width: photosViewController.view.frame.width, height: 200)))
redView.backgroundColor = .red
redView.autoresizingMask = [.flexibleWidth]
return redView
}

func photosViewController(_ photosViewController: NYTPhotosViewController, didNavigateToInterstialView view: UIView, at index: UInt) {
view.backgroundColor = .blue
}
}
2 changes: 1 addition & 1 deletion NYTPhotoViewer.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "NYTPhotoViewer"
s.version = "2.0.0"
s.version = "3.0.0"

s.description = <<-DESC
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.
Expand Down
Loading

0 comments on commit d9cf272

Please sign in to comment.