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

Infinite loop slideshow #255

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions NYTPhotoViewer/NYTPhotosViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification;
*/
@property (nonatomic, weak, nullable) id <NYTPhotosViewControllerDelegate> 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.
*
Expand Down
9 changes: 9 additions & 0 deletions NYTPhotoViewer/NYTPhotosViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ - (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) {

if (self.canLoop && self.dataSource.numberOfPhotos.integerValue > 1) {
return [self newPhotoViewControllerForPhoto:[self.dataSource photoAtIndex:(self.dataSource.numberOfPhotos.integerValue - 1)]];
}

return nil;
}

Expand All @@ -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)]];
}
Expand Down