Skip to content

Commit

Permalink
Merge pull request #227 from NYTimes/fix/bounds-and-nullability
Browse files Browse the repository at this point in the history
Bugfixes: bounds checks, don't retain data source
  • Loading branch information
cdzombak committed Feb 3, 2017
2 parents f399642 + 6602a08 commit 369d70e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Changes for users of the library currently on `develop`:

- 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))

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

Expand Down
4 changes: 1 addition & 3 deletions NYTPhotoViewer/NYTPhotosViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification;
* The data source underlying this PhotosViewController.
*
* After setting a new data source, you must call `-reloadPhotosAnimated:`.
*
* The data source is retained (unlike UITableView's data source).
*/
@property (nonatomic) id <NYTPhotoViewerDataSource> dataSource;
@property (nonatomic, weak, nullable) id <NYTPhotoViewerDataSource> dataSource;

/**
* The object conforming to `NYTPhoto` that is currently being displayed by the `pageViewController`.
Expand Down
8 changes: 8 additions & 0 deletions NYTPhotoViewer/NYTPhotosViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,19 @@ - (void)photoViewController:(NYTPhotoViewController *)photoViewController didLon

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController <NYTPhotoContainer> *)viewController {
NSUInteger photoIndex = [self.dataSource indexOfPhoto:viewController.photo];
if (photoIndex == 0 || photoIndex == NSNotFound) {
return nil;
}

return [self newPhotoViewControllerForPhoto:[self.dataSource photoAtIndex:(photoIndex - 1)]];
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController <NYTPhotoContainer> *)viewController {
NSUInteger photoIndex = [self.dataSource indexOfPhoto:viewController.photo];
if (photoIndex == NSNotFound) {
return nil;
}

return [self newPhotoViewControllerForPhoto:[self.dataSource photoAtIndex:(photoIndex + 1)]];
}

Expand Down

0 comments on commit 369d70e

Please sign in to comment.