-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #251 from NYTimes/feature/merge-2.0-develop
Merge Develop into Master (v2.0.0)
- Loading branch information
Showing
37 changed files
with
911 additions
and
489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// Photo.swift | ||
// NYTPhotoViewer | ||
// | ||
// Created by Chris Dzombak on 2/2/17. | ||
// Copyright © 2017 NYTimes. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
/// A photo may often be represented in a Swift application as a value type. | ||
struct Photo { | ||
// 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 identifier: Int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// PhotoBox.swift | ||
// NYTPhotoViewer | ||
// | ||
// Created by Chris Dzombak on 2/2/17. | ||
// Copyright © 2017 NYTimes. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import NYTPhotoViewer | ||
|
||
/// A box allowing NYTPhotoViewer to consume Swift value types from our codebase. | ||
final class NYTPhotoBox: NSObject, NYTPhoto { | ||
|
||
let value: Photo | ||
|
||
init(_ photo: Photo) { | ||
value = photo | ||
} | ||
|
||
// MARK: NYTPhoto | ||
|
||
var image: UIImage? | ||
var imageData: Data? | ||
var placeholderImage: UIImage? | ||
|
||
var attributedCaptionTitle: NSAttributedString? | ||
|
||
var attributedCaptionSummary: NSAttributedString? { | ||
let attributes = [NSForegroundColorAttributeName: UIColor.white, | ||
NSFontAttributeName: UIFont.preferredFont(forTextStyle: .body)] | ||
return NSAttributedString(string: value.summary, attributes: attributes) | ||
} | ||
|
||
var attributedCaptionCredit: NSAttributedString? { | ||
let attributes = [NSForegroundColorAttributeName: UIColor.gray, | ||
NSFontAttributeName: UIFont.preferredFont(forTextStyle: .footnote)] | ||
return NSAttributedString(string: value.credit, attributes: attributes) | ||
} | ||
} | ||
|
||
// MARK: NSObject Equality | ||
|
||
extension NYTPhotoBox { | ||
@objc | ||
override func isEqual(_ object: Any?) -> Bool { | ||
guard let otherPhoto = object as? NYTPhotoBox else { return false } | ||
return value.identifier == otherPhoto.value.identifier | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// PhotoViewerCoordinator.swift | ||
// NYTPhotoViewer | ||
// | ||
// Created by Chris Dzombak on 2/2/17. | ||
// Copyright © 2017 NYTimes. All rights reserved. | ||
// | ||
|
||
import NYTPhotoViewer | ||
|
||
/// Coordinates interaction between the application's data layer and the photo viewer component. | ||
final class PhotoViewerCoordinator: NYTPhotoViewerDataSource { | ||
let slideshow: [NYTPhotoBox] | ||
let provider: PhotosProvider | ||
|
||
lazy var photoViewer: NYTPhotosViewController = { | ||
return NYTPhotosViewController(dataSource: self) | ||
}() | ||
|
||
init(provider: PhotosProvider) { | ||
self.provider = provider | ||
self.slideshow = provider.fetchDemoSlideshow().map { NYTPhotoBox($0) } | ||
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) | ||
}) | ||
} | ||
} | ||
|
||
// MARK: NYTPhotoViewerDataSource | ||
|
||
@objc | ||
var numberOfPhotos: NSNumber? { | ||
return NSNumber(integerLiteral: slideshow.count) | ||
} | ||
|
||
@objc | ||
func index(of photo: NYTPhoto) -> Int { | ||
guard let box = photo as? NYTPhotoBox else { return NSNotFound } | ||
return slideshow.index(where: { $0.value.identifier == box.value.identifier }) ?? NSNotFound | ||
} | ||
|
||
@objc | ||
func photo(at index: Int) -> NYTPhoto? { | ||
guard index < slideshow.count else { return nil } | ||
return slideshow[index] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.