Skip to content

Commit

Permalink
Merge pull request #122 from NYTimes/cdz/121-dismissal-followup
Browse files Browse the repository at this point in the history
Followup from dismissal PR #121
  • Loading branch information
Twigz committed Jan 13, 2016
2 parents fe13f40 + c17b7f7 commit ef4b7b8
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Pod/Classes/ios/NYTPhotosViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,6 @@ - (void)didSingleTapWithGestureRecognizer:(UITapGestureRecognizer *)tapGestureRe
- (void)didPanWithGestureRecognizer:(UIPanGestureRecognizer *)panGestureRecognizer {
if (panGestureRecognizer.state == UIGestureRecognizerStateBegan) {
self.transitionController.forcesNonInteractiveDismissal = NO;
self.overlayWasHiddenBeforeTransition = self.overlayView.hidden;
[self setOverlayViewHidden:YES animated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
}
else {
Expand All @@ -346,36 +344,46 @@ - (void)didPanWithGestureRecognizer:(UIPanGestureRecognizer *)panGestureRecogniz
}
}

-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
{
- (void)dismissViewControllerAnimated:(BOOL)animated completion:(void (^)(void))completion {
UIView *startingView;
if (self.currentlyDisplayedPhoto.image || self.currentlyDisplayedPhoto.placeholderImage || self.currentlyDisplayedPhoto.imageData) {
startingView = self.currentPhotoViewController.scalingImageView.imageView;
}

self.transitionController.startingView = startingView;
self.transitionController.endingView = self.referenceViewForCurrentPhoto;

self.overlayWasHiddenBeforeTransition = self.overlayView.hidden;
[self setOverlayViewHidden:YES animated:animated];

// Cocoa convention is not to call delegate methods when you do something directly in code,
// so we'll not call delegate methods if this is a programmatic, noninteractive dismissal:
BOOL shouldSendDelegateMessages = self.transitionController.forcesNonInteractiveDismissal;

if ([self.delegate respondsToSelector:@selector(photosViewControllerWillDismiss:)]) {
if (shouldSendDelegateMessages && [self.delegate respondsToSelector:@selector(photosViewControllerWillDismiss:)]) {
[self.delegate photosViewControllerWillDismiss:self];
}

[[NSNotificationCenter defaultCenter] postNotificationName:NYTPhotosViewControllerWillDismissNotification object:self];

[super dismissViewControllerAnimated:flag completion:^{
[super dismissViewControllerAnimated:animated completion:^{
BOOL isStillOnscreen = self.view.window != nil; // Happens when the dismissal is canceled.

if (isStillOnscreen && !self.overlayWasHiddenBeforeTransition) {
[self setOverlayViewHidden:NO animated:YES];
}

if (!isStillOnscreen) {
if ([self.delegate respondsToSelector:@selector(photosViewControllerDidDismiss:)]) {
if (shouldSendDelegateMessages && [self.delegate respondsToSelector:@selector(photosViewControllerDidDismiss:)]) {
[self.delegate photosViewControllerDidDismiss:self];
}

[[NSNotificationCenter defaultCenter] postNotificationName:NYTPhotosViewControllerDidDismissNotification object:self];
}

if (completion) {
completion();
}
}];
}

Expand Down

0 comments on commit ef4b7b8

Please sign in to comment.