From 49d54ba813917b5fd72376802fbb7befd5dfd063 Mon Sep 17 00:00:00 2001 From: Chris Dzombak Date: Wed, 13 Jan 2016 14:56:35 -0500 Subject: [PATCH 1/5] [minor] change space/braces style to adhere to style guide --- Pod/Classes/ios/NYTPhotosViewController.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Pod/Classes/ios/NYTPhotosViewController.m b/Pod/Classes/ios/NYTPhotosViewController.m index ec058ccc..cb8a9e77 100644 --- a/Pod/Classes/ios/NYTPhotosViewController.m +++ b/Pod/Classes/ios/NYTPhotosViewController.m @@ -346,8 +346,7 @@ - (void)didPanWithGestureRecognizer:(UIPanGestureRecognizer *)panGestureRecogniz } } --(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion -{ +- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion { UIView *startingView; if (self.currentlyDisplayedPhoto.image || self.currentlyDisplayedPhoto.placeholderImage || self.currentlyDisplayedPhoto.imageData) { startingView = self.currentPhotoViewController.scalingImageView.imageView; From 75b1fdbed21e718f58842577980ce5fdb0477fa9 Mon Sep 17 00:00:00 2001 From: Chris Dzombak Date: Wed, 13 Jan 2016 14:57:18 -0500 Subject: [PATCH 2/5] [minor] change name of animation flag --- Pod/Classes/ios/NYTPhotosViewController.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Pod/Classes/ios/NYTPhotosViewController.m b/Pod/Classes/ios/NYTPhotosViewController.m index cb8a9e77..d5f070da 100644 --- a/Pod/Classes/ios/NYTPhotosViewController.m +++ b/Pod/Classes/ios/NYTPhotosViewController.m @@ -346,7 +346,7 @@ - (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; @@ -361,7 +361,7 @@ - (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))comp [[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) { From 79d35948aa950556b01e2a5d830521e884be5113 Mon Sep 17 00:00:00 2001 From: Chris Dzombak Date: Wed, 13 Jan 2016 14:58:08 -0500 Subject: [PATCH 3/5] Run user-supplied completion block on dismissing PhotosVC --- Pod/Classes/ios/NYTPhotosViewController.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Pod/Classes/ios/NYTPhotosViewController.m b/Pod/Classes/ios/NYTPhotosViewController.m index d5f070da..43bb9237 100644 --- a/Pod/Classes/ios/NYTPhotosViewController.m +++ b/Pod/Classes/ios/NYTPhotosViewController.m @@ -375,6 +375,10 @@ - (void)dismissViewControllerAnimated:(BOOL)animated completion:(void (^)(void)) [[NSNotificationCenter defaultCenter] postNotificationName:NYTPhotosViewControllerDidDismissNotification object:self]; } + + if (completion) { + completion(); + } }]; } From e5b3144dd869c61aa7a977587a6d69eb21de8546 Mon Sep 17 00:00:00 2001 From: Chris Dzombak Date: Wed, 13 Jan 2016 15:02:04 -0500 Subject: [PATCH 4/5] =?UTF-8?q?Don=E2=80=99t=20call=20delegate=20methods?= =?UTF-8?q?=20for=20non-interactive=20dismissals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This seems to align with Cocoa convention but I will accept debate on this choice. --- Pod/Classes/ios/NYTPhotosViewController.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Pod/Classes/ios/NYTPhotosViewController.m b/Pod/Classes/ios/NYTPhotosViewController.m index 43bb9237..f0597e58 100644 --- a/Pod/Classes/ios/NYTPhotosViewController.m +++ b/Pod/Classes/ios/NYTPhotosViewController.m @@ -354,8 +354,12 @@ - (void)dismissViewControllerAnimated:(BOOL)animated completion:(void (^)(void)) self.transitionController.startingView = startingView; self.transitionController.endingView = self.referenceViewForCurrentPhoto; + + // 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]; } @@ -369,7 +373,7 @@ - (void)dismissViewControllerAnimated:(BOOL)animated completion:(void (^)(void)) } if (!isStillOnscreen) { - if ([self.delegate respondsToSelector:@selector(photosViewControllerDidDismiss:)]) { + if (shouldSendDelegateMessages && [self.delegate respondsToSelector:@selector(photosViewControllerDidDismiss:)]) { [self.delegate photosViewControllerDidDismiss:self]; } From c17b7f7e27f231ca4187dba77f3a831f082faa5e Mon Sep 17 00:00:00 2001 From: Chris Dzombak Date: Wed, 13 Jan 2016 15:13:04 -0500 Subject: [PATCH 5/5] =?UTF-8?q?Move=20overlay=20dismissal=20logic=20to=20d?= =?UTF-8?q?ismissViewController:=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that all dismissals go through this method, this seems like the right place to manage overlay view visibility. --- Pod/Classes/ios/NYTPhotosViewController.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Pod/Classes/ios/NYTPhotosViewController.m b/Pod/Classes/ios/NYTPhotosViewController.m index f0597e58..a56133bd 100644 --- a/Pod/Classes/ios/NYTPhotosViewController.m +++ b/Pod/Classes/ios/NYTPhotosViewController.m @@ -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 { @@ -355,6 +353,9 @@ - (void)dismissViewControllerAnimated:(BOOL)animated completion:(void (^)(void)) 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;