Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose a data-source-oriented API for PhotosViewController #226

Merged
merged 37 commits into from
Jan 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1acd496
clarify when `NYTPhotoCaptionView` is used
Dec 9, 2016
66784db
rename concrete data source to `NYTPhotoViewerArrayDataSource`
Dec 9, 2016
f5e3dc8
[minor] add clarifying comment to umbrella header
Dec 9, 2016
4c180d9
Rename `NYTPhotoViewerDataSource` and clarify it vs. delegate
Dec 9, 2016
d1394c6
[minor] Improve comments in `NYTPhoto.h`
Dec 9, 2016
e615a09
Update library code to work with new `NYTPhotoViewerDataSource`
Dec 10, 2016
2652474
Update Example app to work with new `NYTPhotoViewerDataSource`
Dec 10, 2016
577aa89
Clean up ArrayDataSource interface
Jan 26, 2017
ae015e2
Add factory method for ArrayDataSource
Jan 26, 2017
620540d
Handle null input properly in ArrayDataSource
Jan 26, 2017
207a448
NYTPhotosViewController takes a data source, not an array
Jan 26, 2017
3e0dba9
Allow informing PhotosVC that an individual photo has changed
Jan 26, 2017
de002c1
Better document updatePhotoAtIndex: behavior
Jan 27, 2017
ed8f246
refactor: use a property that’s already been implemented
Jan 27, 2017
b0a9525
Add another example photo
Jan 27, 2017
762483b
Better document updatePhoto: methods
Jan 27, 2017
587c82b
Allow setting `NYTPhotosVC` data source
Jan 27, 2017
4750578
Add reload-all-photos method to `NYTPhotosVC`
Jan 27, 2017
d3d2323
Add an Example codepath which demos replacing the data source
Jan 27, 2017
290ba8c
Improve `NYTPhotosVC` animation logic
Jan 27, 2017
8f6011a
Add a single-photo data source class
Jan 27, 2017
3dcdbf0
docs: tweak ArrayDataSource initializer documentation
Jan 27, 2017
f8ccb16
Modernize PhotosVC code style
Jan 27, 2017
62d54be
Make Xcode (8.2) recommended updates to NYTPhotoViewer’s Xcode project
Jan 27, 2017
21c3852
Avoid using `NYTPhotosVC`’s delegate until after `-init…` returns
Jan 27, 2017
bb38825
Add convenience `NYTPhotosVC` initializer accepting solely a data source
Jan 27, 2017
2f45ab9
Fix incorrect `NYTPhotosVC` convenience initializer
Jan 27, 2017
b5e3c07
style: correct spacing in Example ViewController
Jan 27, 2017
f71d8f4
fix: use proper equality checks
Jan 27, 2017
4f81acb
docs: clarify how NYTPhoto equality is determined
Jan 27, 2017
cf9cfbc
docs: add this feature to CHANGELOG
Jan 27, 2017
a57f6d2
Update LICENSE to specify (c) through 2017
Jan 30, 2017
db4ccb5
docs: add missing copyright in headers
Jan 30, 2017
bbacf0c
example: Use a more obvious demo for custom maximum zoom scale
Jan 31, 2017
7dc1e0d
example: Improve data-source-swap demo
Jan 31, 2017
d7aa268
example: Improve caption for photo with a loading spinner
Jan 31, 2017
c67c605
Use more modern `nullable` instead of `_Nullable`
Jan 31, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

_This space intentionally left blank._
- Expose a data-source-oriented API for PhotosViewController ([#226](https://github.com/NYTimes/NYTPhotoViewer/pull/226))

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

Expand Down
10 changes: 10 additions & 0 deletions Example/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down
23 changes: 23 additions & 0 deletions Example/Assets.xcassets/Chess.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "dzombak-chess.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "dzombak-chess-1.jpg",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "dzombak-chess-2.jpg",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
204 changes: 134 additions & 70 deletions Example/NYTViewController.m

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Copyright (c) 2015-2016 The New York Times Company
Copyright (c) 2015-2017 The New York Times Company

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this library except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
59 changes: 40 additions & 19 deletions NYTPhotoViewer.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 2 additions & 0 deletions NYTPhotoViewer/NYTPhotoCaptionView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ NS_ASSUME_NONNULL_BEGIN

/**
* A view used to display the caption for a photo.
*
* This is used by default when no custom caption view is provided.
*/
@interface NYTPhotoCaptionView : UIView <NYTPhotoCaptionViewLayoutWidthHinting>

Expand Down
5 changes: 3 additions & 2 deletions NYTPhotoViewer/NYTPhotoViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ FOUNDATION_EXPORT const unsigned char NYTPhotoViewerVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <NYTPhotoViewer/PublicHeader.h>
#import <NYTPhotoViewer/NYTPhotoCaptionView.h>
#import <NYTPhotoViewer/NYTPhotoDismissalInteractionController.h>
#import <NYTPhotoViewer/NYTPhotosDataSource.h>
#import <NYTPhotoViewer/NYTPhotoViewerArrayDataSource.h>
#import <NYTPhotoViewer/NYTPhotosOverlayView.h>
#import <NYTPhotoViewer/NYTPhotosViewController.h>
#import <NYTPhotoViewer/NYTPhotoTransitionAnimator.h>
Expand All @@ -29,6 +29,7 @@ FOUNDATION_EXPORT const unsigned char NYTPhotoViewerVersionString[];
#import <NYTPhotoViewer/NYTPhoto.h>
#import <NYTPhotoViewer/NYTPhotoCaptionViewLayoutWidthHinting.h>
#import <NYTPhotoViewer/NYTPhotoContainer.h>
#import <NYTPhotoViewer/NYTPhotosViewControllerDataSource.h>
#import <NYTPhotoViewer/NYTPhotoViewerDataSource.h>

// Support
#import <NYTPhotoViewer/NSBundle+NYTPhotoViewer.h>
37 changes: 37 additions & 0 deletions NYTPhotoViewer/NYTPhotoViewerArrayDataSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// NYTPhotoViewerArrayDataSource.h
// NYTPhotoViewer
//
// Created by Brian Capps on 2/11/15.
// Copyright (c) 2017 The New York Times Company. All rights reserved.
//

@import Foundation;

#import "NYTPhotoViewerDataSource.h"

NS_ASSUME_NONNULL_BEGIN

/**
* A simple concrete implementation of `NYTPhotoViewerDataSource`, for use with an array of images.
*/
@interface NYTPhotoViewerArrayDataSource : NSObject <NYTPhotoViewerDataSource, NSFastEnumeration>

@property (nonatomic, readonly) NSArray<id<NYTPhoto>> *photos;

/**
* The designated initializer that takes and stores an array of photos.
*
* @param photos An array of objects conforming to the `NYTPhoto` protocol.
*
* @return A fully initialized data source.
*/
- (instancetype)initWithPhotos:(nullable NSArray<id<NYTPhoto>> *)photos NS_DESIGNATED_INITIALIZER;

+ (instancetype)dataSourceWithPhotos:(nullable NSArray<id<NYTPhoto>> *)photos;

- (id<NYTPhoto>)objectAtIndexedSubscript:(NSUInteger)idx;

@end

NS_ASSUME_NONNULL_END
69 changes: 69 additions & 0 deletions NYTPhotoViewer/NYTPhotoViewerArrayDataSource.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// NYTPhotoViewerArrayDataSource.m
// NYTPhotoViewer
//
// Created by Brian Capps on 2/11/15.
// Copyright (c) 2017 The New York Times Company. All rights reserved.
//

#import "NYTPhotoViewerArrayDataSource.h"

@implementation NYTPhotoViewerArrayDataSource

#pragma mark - NSObject

- (instancetype)init {
return [self initWithPhotos:nil];
}

#pragma mark - NYTPhotosDataSource

- (instancetype)initWithPhotos:(nullable NSArray<id<NYTPhoto>> *)photos {
self = [super init];

if (self) {
if (photos == nil) {
_photos = @[];
} else {
_photos = [photos copy];
}
}

return self;
}

+ (instancetype)dataSourceWithPhotos:(nullable NSArray<id<NYTPhoto>> *)photos {
return [[self alloc] initWithPhotos:photos];
}

#pragma mark - NSFastEnumeration

- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(__unsafe_unretained id [])buffer count:(NSUInteger)length {
return [self.photos countByEnumeratingWithState:state objects:buffer count:length];
}

#pragma mark - NYTPhotosViewControllerDataSource

- (NSNumber *)numberOfPhotos {
return @(self.photos.count);
}

- (nullable id <NYTPhoto>)photoAtIndex:(NSInteger)photoIndex {
if (photoIndex < self.photos.count) {
return self.photos[photoIndex];
}

return nil;
}

- (NSInteger)indexOfPhoto:(id <NYTPhoto>)photo {
return [self.photos indexOfObject:photo];
}

#pragma mark - Subscripting

- (id<NYTPhoto>)objectAtIndexedSubscript:(NSUInteger)idx {
return self.photos[idx];
}

@end
7 changes: 4 additions & 3 deletions NYTPhotoViewer/NYTPhotoViewerCore.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// NYTPhotoViewer.h
// NYTPhotoViewerCore.h
// NYTPhotoViewer
//
// Created by David Beck on 3/2/16.
Expand All @@ -17,7 +17,7 @@ FOUNDATION_EXPORT const unsigned char NYTPhotoViewerCoreVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <NYTPhotoViewer/PublicHeader.h>
#import <NYTPhotoViewer/NYTPhotoCaptionView.h>
#import <NYTPhotoViewer/NYTPhotoDismissalInteractionController.h>
#import <NYTPhotoViewer/NYTPhotosDataSource.h>
#import <NYTPhotoViewer/NYTPhotoViewerArrayDataSource.h>
#import <NYTPhotoViewer/NYTPhotosOverlayView.h>
#import <NYTPhotoViewer/NYTPhotosViewController.h>
#import <NYTPhotoViewer/NYTPhotoTransitionAnimator.h>
Expand All @@ -29,6 +29,7 @@ FOUNDATION_EXPORT const unsigned char NYTPhotoViewerCoreVersionString[];
#import <NYTPhotoViewer/NYTPhoto.h>
#import <NYTPhotoViewer/NYTPhotoCaptionViewLayoutWidthHinting.h>
#import <NYTPhotoViewer/NYTPhotoContainer.h>
#import <NYTPhotoViewer/NYTPhotosViewControllerDataSource.h>
#import <NYTPhotoViewer/NYTPhotoViewerDataSource.h>

// Support
#import <NYTPhotoViewer/NSBundle+NYTPhotoViewer.h>
40 changes: 40 additions & 0 deletions NYTPhotoViewer/NYTPhotoViewerSinglePhotoDataSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// NYTPhotoViewerSinglePhotoDataSource.h
// NYTPhotoViewer
//
// Created by Chris Dzombak on 1/27/17.
// Copyright © 2017 The New York Times Company. All rights reserved.
//

@import Foundation;

#import "NYTPhotoViewerDataSource.h"

NS_ASSUME_NONNULL_BEGIN

/**
* A simple concrete implementation of `NYTPhotoViewerDataSource`, for use with a single image.
*/
@interface NYTPhotoViewerSinglePhotoDataSource : NSObject <NYTPhotoViewerDataSource>

@property (nonatomic, readonly) id<NYTPhoto> photo;

/**
* The designated initializer that takes and stores a single photo.
*
* @param photos An object conforming to the `NYTPhoto` protocol.
*
* @return A fully initialized data source.
*/
- (instancetype)initWithPhoto:(id<NYTPhoto>)photo NS_DESIGNATED_INITIALIZER;

+ (instancetype)dataSourceWithPhoto:(id<NYTPhoto>)photo;

/**
* Initializing without a photo is invalid.
*/
- (instancetype)init NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END
38 changes: 38 additions & 0 deletions NYTPhotoViewer/NYTPhotoViewerSinglePhotoDataSource.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// NYTPhotoViewerSinglePhotoDataSource.m
// NYTPhotoViewer
//
// Created by Chris Dzombak on 1/27/17.
// Copyright © 2017 The New York Times Company. All rights reserved.
//

#import "NYTPhotoViewerSinglePhotoDataSource.h"

@implementation NYTPhotoViewerSinglePhotoDataSource

- (instancetype)initWithPhoto:(id<NYTPhoto>)photo {
if ((self = [super init])) {
_photo = photo;
}
return self;
}

+ (instancetype)dataSourceWithPhoto:(id<NYTPhoto>)photo {
return [[self alloc] initWithPhoto:photo];
}

#pragma mark NYTPhotoViewerDataSource

- (NSNumber *)numberOfPhotos {
return @(1);
}

- (id<NYTPhoto>)photoAtIndex:(NSInteger)photoIndex {
return self.photo;
}

- (NSInteger)indexOfPhoto:(id<NYTPhoto>)photo {
return 0;
}

@end
31 changes: 0 additions & 31 deletions NYTPhotoViewer/NYTPhotosDataSource.h

This file was deleted.

Loading