From 93dab95f69d65631469956413e5dbba5a5835052 Mon Sep 17 00:00:00 2001 From: Benoit Pasquier Date: Wed, 20 Dec 2017 12:21:48 +0000 Subject: [PATCH 1/2] Ability to create an infinite loop between last photo and first photo --- NYTPhotoViewer/NYTPhotosViewController.h | 5 +++++ NYTPhotoViewer/NYTPhotosViewController.m | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/NYTPhotoViewer/NYTPhotosViewController.h b/NYTPhotoViewer/NYTPhotosViewController.h index be8a9845..35615873 100644 --- a/NYTPhotoViewer/NYTPhotosViewController.h +++ b/NYTPhotoViewer/NYTPhotosViewController.h @@ -98,6 +98,11 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification; */ @property (nonatomic, weak, nullable) id delegate; +/** + * Enable a loop navigation between last photo and first photo + */ +@property (nonatomic) BOOL canLoop; + /** * Initializes a `PhotosViewController` with the given data source, initially displaying the first photo in the data source. * diff --git a/NYTPhotoViewer/NYTPhotosViewController.m b/NYTPhotoViewer/NYTPhotosViewController.m index 79e3281b..635f496c 100644 --- a/NYTPhotoViewer/NYTPhotosViewController.m +++ b/NYTPhotoViewer/NYTPhotosViewController.m @@ -572,6 +572,11 @@ - (void)photoViewController:(NYTPhotoViewController *)photoViewController didLon - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController { NSUInteger photoIndex = [self.dataSource indexOfPhoto:viewController.photo]; if (photoIndex == 0 || photoIndex == NSNotFound) { + + if (self.canLoop && self.dataSource.numberOfPhotos.integerValue > 1) { + return [self newPhotoViewControllerForPhoto:[self.dataSource photoAtIndex:(self.dataSource.numberOfPhotos.integerValue - 1)]]; + } + return nil; } @@ -583,6 +588,10 @@ - (UIViewController *)pageViewController:(UIPageViewController *)pageViewControl if (photoIndex == NSNotFound) { return nil; } + + if (self.canLoop && photoIndex + 1 == self.dataSource.numberOfPhotos.integerValue) { + return [self newPhotoViewControllerForPhoto:[self.dataSource photoAtIndex:0]]; + } return [self newPhotoViewControllerForPhoto:[self.dataSource photoAtIndex:(photoIndex + 1)]]; } From 76d0ae13cd7ded42bdf780fa1eb228e372614691 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 20 Dec 2017 12:27:36 +0000 Subject: [PATCH 2/2] Update CHANGELOG.md Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17bf98fc..91618fb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Changes for users of the library currently on `develop`: - 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)) - Respect safe areas for iOS 11 support +- Ability to create an infinite loop slideshow ## [1.2.0](https://github.com/NYTimes/NYTPhotoViewer/releases/tag/1.2.0)