From 4d9ab3aeec709334c9daa1fe6fccf6c2d4308918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Garc=C3=ADa?= Date: Thu, 24 Nov 2016 15:49:16 +0100 Subject: [PATCH 1/6] Show gallery under status bar option when showed. --- NYTPhotoViewer/NYTPhotosViewController.h | 5 +++++ NYTPhotoViewer/NYTPhotosViewController.m | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/NYTPhotoViewer/NYTPhotosViewController.h b/NYTPhotoViewer/NYTPhotosViewController.h index 11cbca67..8b8bf66a 100644 --- a/NYTPhotoViewer/NYTPhotosViewController.h +++ b/NYTPhotoViewer/NYTPhotosViewController.h @@ -75,6 +75,11 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification; */ @property (nonatomic, readonly, nullable) NYTPhotosOverlayView *overlayView; +/** + * Shows all content under status bar frame. Default NO. + */ +@property (nonatomic) BOOL underStatusBar; + /** * The left bar button item overlaying the photo. */ diff --git a/NYTPhotoViewer/NYTPhotosViewController.m b/NYTPhotoViewer/NYTPhotosViewController.m index 7255f6ce..d91af0b2 100644 --- a/NYTPhotoViewer/NYTPhotosViewController.m +++ b/NYTPhotoViewer/NYTPhotosViewController.m @@ -142,8 +142,14 @@ - (void)viewDidAppear:(BOOL)animated { - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; - self.pageViewController.view.frame = self.view.bounds; - self.overlayView.frame = self.view.bounds; + CGRect frame = self.view.bounds; + if (self.underStatusBar) { + CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;; + frame.origin.y = statusBarHeight; + frame.size.height -= statusBarHeight; + } + self.pageViewController.view.frame = frame; + self.overlayView.frame = frame; } - (BOOL)prefersStatusBarHidden { From 701db3f9b9080dc864c7a17e8a1723f691565c2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Garc=C3=ADa?= Date: Wed, 20 Sep 2017 13:00:11 +0200 Subject: [PATCH 2/6] Delegate life cyble some methods --- NYTPhotoViewer/NYTPhotosViewController.h | 15 +++++++++++++++ NYTPhotoViewer/NYTPhotosViewController.m | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/NYTPhotoViewer/NYTPhotosViewController.h b/NYTPhotoViewer/NYTPhotosViewController.h index 8b8bf66a..94eb76b0 100644 --- a/NYTPhotoViewer/NYTPhotosViewController.h +++ b/NYTPhotoViewer/NYTPhotosViewController.h @@ -182,6 +182,21 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification; @optional +/** + * Called when the view is about to made visible. + * + * @param photosViewController The `NYTPhotosViewController` instance that sent the delegate message. + * @param animated + */ +- (void)photosViewController:(NYTPhotosViewController *)photosViewController viewWillAppear:(BOOL)animated; + +/** + * Called when the view is dismissed, covered or otherwise hidden. + * + * @param photosViewController The `NYTPhotosViewController` instance that sent the delegate message. + */ +- (void)photosViewController:(NYTPhotosViewController *)photosViewController viewWillDisappear:(BOOL)animated; + /** * Called when a new photo is displayed through a swipe gesture. * diff --git a/NYTPhotoViewer/NYTPhotosViewController.m b/NYTPhotoViewer/NYTPhotosViewController.m index d91af0b2..2521e7cc 100644 --- a/NYTPhotoViewer/NYTPhotosViewController.m +++ b/NYTPhotoViewer/NYTPhotosViewController.m @@ -131,6 +131,20 @@ - (void)viewDidLoad { self.transitionController.endingView = endingView; } +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + if ([_delegate respondsToSelector:@selector(photosViewController:viewWillAppear:)]) { + [_delegate photosViewController:self viewWillAppear:animated]; + } +} + +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + if ([_delegate respondsToSelector:@selector(photosViewController:viewWillDisappear:)]) { + [_delegate photosViewController:self viewWillDisappear:animated]; + } +} + - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; From 8a0aae7f9dbe5ed8a5f00026c8e6c0c0d5b6dba6 Mon Sep 17 00:00:00 2001 From: eric3 Date: Tue, 8 Dec 2020 22:55:32 -0500 Subject: [PATCH 3/6] move the status bar overrides into NYTPhotoViewController, tweak Objc example to demonstrate the feature. --- Examples/Sources/ObjC/NYTViewController.m | 2 ++ NYTPhotoViewer/NYTPhotosViewController.m | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Examples/Sources/ObjC/NYTViewController.m b/Examples/Sources/ObjC/NYTViewController.m index 8f7ba720..694d6149 100644 --- a/Examples/Sources/ObjC/NYTViewController.m +++ b/Examples/Sources/ObjC/NYTViewController.m @@ -35,6 +35,8 @@ - (IBAction)imageButtonTapped:(id)sender { NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithDataSource:self.dataSource initialPhoto:nil delegate:self]; + photosViewController.underStatusBar = YES; + [self presentViewController:photosViewController animated:YES completion:nil]; [self updateImagesOnPhotosViewController:photosViewController afterDelayWithDataSource:self.dataSource]; diff --git a/NYTPhotoViewer/NYTPhotosViewController.m b/NYTPhotoViewer/NYTPhotosViewController.m index 2521e7cc..92c202ea 100644 --- a/NYTPhotoViewer/NYTPhotosViewController.m +++ b/NYTPhotoViewer/NYTPhotosViewController.m @@ -167,7 +167,11 @@ - (void)viewWillLayoutSubviews { } - (BOOL)prefersStatusBarHidden { - return YES; + return !self.underStatusBar; +} + +- (UIStatusBarStyle)preferredStatusBarStyle { + return UIStatusBarStyleLightContent; } - (BOOL)prefersHomeIndicatorAutoHidden { From 57d6cb17a35346920a845074933f2bec1760e2d3 Mon Sep 17 00:00:00 2001 From: Eric Slosser <325572+mr-fixit@users.noreply.github.com> Date: Thu, 10 Dec 2020 22:30:16 -0500 Subject: [PATCH 4/6] remove duplicate semi-colon. thanks @zeveisenberg Co-authored-by: Zev Eisenberg --- NYTPhotoViewer/NYTPhotosViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NYTPhotoViewer/NYTPhotosViewController.m b/NYTPhotoViewer/NYTPhotosViewController.m index 92c202ea..0b9a03dc 100644 --- a/NYTPhotoViewer/NYTPhotosViewController.m +++ b/NYTPhotoViewer/NYTPhotosViewController.m @@ -158,7 +158,7 @@ - (void)viewWillLayoutSubviews { CGRect frame = self.view.bounds; if (self.underStatusBar) { - CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;; + CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height; frame.origin.y = statusBarHeight; frame.size.height -= statusBarHeight; } From 6f9f9814df8107e7e1a529d9332f7c4397b762a2 Mon Sep 17 00:00:00 2001 From: Eric Slosser Date: Wed, 6 Jan 2021 10:49:38 -0500 Subject: [PATCH 5/6] don't hide the status bar if the notch is there. --- Examples/Sources/ObjC/NYTViewController.m | 2 +- NYTPhotoViewer/NYTPhotosViewController.h | 15 +++++++++++---- NYTPhotoViewer/NYTPhotosViewController.m | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Examples/Sources/ObjC/NYTViewController.m b/Examples/Sources/ObjC/NYTViewController.m index 694d6149..f105bfe8 100644 --- a/Examples/Sources/ObjC/NYTViewController.m +++ b/Examples/Sources/ObjC/NYTViewController.m @@ -35,7 +35,7 @@ - (IBAction)imageButtonTapped:(id)sender { NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithDataSource:self.dataSource initialPhoto:nil delegate:self]; - photosViewController.underStatusBar = YES; + photosViewController.underStatusBar = TristateBoolTrue; [self presentViewController:photosViewController animated:YES completion:nil]; diff --git a/NYTPhotoViewer/NYTPhotosViewController.h b/NYTPhotoViewer/NYTPhotosViewController.h index 94eb76b0..db8d44a8 100644 --- a/NYTPhotoViewer/NYTPhotosViewController.h +++ b/NYTPhotoViewer/NYTPhotosViewController.h @@ -41,6 +41,12 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification; @interface NYTPhotosViewController : UIViewController +typedef NS_ENUM(NSUInteger, TristateBool) { + TristateBoolDefault, + TristateBoolFalse, + TristateBoolTrue +}; + /** * The pan gesture recognizer used for panning to dismiss the photo. Disable to stop the pan-to-dismiss behavior. */ @@ -76,10 +82,12 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification; @property (nonatomic, readonly, nullable) NYTPhotosOverlayView *overlayView; /** - * Shows all content under status bar frame. Default NO. + * Shows all content under status bar frame. Defaults TristateBoolDefault. + * If 'TristateBoolTrue' or 'TristateBoolFalse', prefersStatusBarHidden returns the inverse. + * If 'TristateBoolDefault', prefersStatusBarHidden returns view.safeArea.top == 0. */ -@property (nonatomic) BOOL underStatusBar; - +@property (nonatomic) TristateBool underStatusBar; + /** * The left bar button item overlaying the photo. */ @@ -186,7 +194,6 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification; * Called when the view is about to made visible. * * @param photosViewController The `NYTPhotosViewController` instance that sent the delegate message. - * @param animated */ - (void)photosViewController:(NYTPhotosViewController *)photosViewController viewWillAppear:(BOOL)animated; diff --git a/NYTPhotoViewer/NYTPhotosViewController.m b/NYTPhotoViewer/NYTPhotosViewController.m index 0b9a03dc..711120e8 100644 --- a/NYTPhotoViewer/NYTPhotosViewController.m +++ b/NYTPhotoViewer/NYTPhotosViewController.m @@ -157,7 +157,7 @@ - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; CGRect frame = self.view.bounds; - if (self.underStatusBar) { + if (!self.prefersStatusBarHidden) { CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height; frame.origin.y = statusBarHeight; frame.size.height -= statusBarHeight; @@ -167,7 +167,19 @@ - (void)viewWillLayoutSubviews { } - (BOOL)prefersStatusBarHidden { - return !self.underStatusBar; + BOOL result; + switch (self.underStatusBar) { + case TristateBoolDefault: + result = self.view.safeAreaInsets.top == 0; + break; + case TristateBoolFalse: + result = true; + break; + case TristateBoolTrue: + result = false; + break; + } + return result; } - (UIStatusBarStyle)preferredStatusBarStyle { From 35f5f9d18f984635b4395cca7baf2856de00361a Mon Sep 17 00:00:00 2001 From: Eric Slosser Date: Thu, 14 Jan 2021 17:28:06 -0500 Subject: [PATCH 6/6] change underStatusBar from a Bool to an Enum, respond to rotations properly, stop setting the global BUNDLE_PATH --- Examples/Sources/ObjC/NYTViewController.m | 2 -- NYTPhotoViewer/NYTPhotosViewController.h | 15 +++++++-------- NYTPhotoViewer/NYTPhotosViewController.m | 15 +++++++++++---- scripts/bootstrap | 4 +++- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Examples/Sources/ObjC/NYTViewController.m b/Examples/Sources/ObjC/NYTViewController.m index f105bfe8..8f7ba720 100644 --- a/Examples/Sources/ObjC/NYTViewController.m +++ b/Examples/Sources/ObjC/NYTViewController.m @@ -35,8 +35,6 @@ - (IBAction)imageButtonTapped:(id)sender { NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithDataSource:self.dataSource initialPhoto:nil delegate:self]; - photosViewController.underStatusBar = TristateBoolTrue; - [self presentViewController:photosViewController animated:YES completion:nil]; [self updateImagesOnPhotosViewController:photosViewController afterDelayWithDataSource:self.dataSource]; diff --git a/NYTPhotoViewer/NYTPhotosViewController.h b/NYTPhotoViewer/NYTPhotosViewController.h index db8d44a8..e5aea1da 100644 --- a/NYTPhotoViewer/NYTPhotosViewController.h +++ b/NYTPhotoViewer/NYTPhotosViewController.h @@ -41,10 +41,10 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification; @interface NYTPhotosViewController : UIViewController -typedef NS_ENUM(NSUInteger, TristateBool) { - TristateBoolDefault, - TristateBoolFalse, - TristateBoolTrue +typedef NS_ENUM(NSUInteger, NYTPhotoViewerStatusBarMode) { + NYTPhotoViewerStatusBarModeDynamic, /* hide statusbar when view.safeArea.top == 0 */ + NYTPhotoViewerStatusBarModeHidden, + NYTPhotoViewerStatusBarModeShown }; /** @@ -82,11 +82,10 @@ typedef NS_ENUM(NSUInteger, TristateBool) { @property (nonatomic, readonly, nullable) NYTPhotosOverlayView *overlayView; /** - * Shows all content under status bar frame. Defaults TristateBoolDefault. - * If 'TristateBoolTrue' or 'TristateBoolFalse', prefersStatusBarHidden returns the inverse. - * If 'TristateBoolDefault', prefersStatusBarHidden returns view.safeArea.top == 0. + * This determines whether we display the status bar or not + * Defaults to NYTPhotoViewerStatusBarModeDynamic. */ -@property (nonatomic) TristateBool underStatusBar; +@property (nonatomic) NYTPhotoViewerStatusBarMode statusBarMode; /** * The left bar button item overlaying the photo. diff --git a/NYTPhotoViewer/NYTPhotosViewController.m b/NYTPhotoViewer/NYTPhotosViewController.m index 711120e8..077bf5d1 100644 --- a/NYTPhotoViewer/NYTPhotosViewController.m +++ b/NYTPhotoViewer/NYTPhotosViewController.m @@ -168,20 +168,27 @@ - (void)viewWillLayoutSubviews { - (BOOL)prefersStatusBarHidden { BOOL result; - switch (self.underStatusBar) { - case TristateBoolDefault: + switch (self.statusBarMode) { + case NYTPhotoViewerStatusBarModeDynamic: result = self.view.safeAreaInsets.top == 0; break; - case TristateBoolFalse: + case NYTPhotoViewerStatusBarModeHidden: result = true; break; - case TristateBoolTrue: + case NYTPhotoViewerStatusBarModeShown: result = false; break; } return result; } +- (void)viewSafeAreaInsetsDidChange { + if (self.statusBarMode == NYTPhotoViewerStatusBarModeDynamic) { + [self setNeedsStatusBarAppearanceUpdate]; + } + [super viewSafeAreaInsetsDidChange]; +} + - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } diff --git a/scripts/bootstrap b/scripts/bootstrap index 8525e5eb..f17329b7 100755 --- a/scripts/bootstrap +++ b/scripts/bootstrap @@ -11,6 +11,8 @@ fi cd "$(dirname "$0")/../Examples" -bundle config set path 'vendor/bundle' +# uncomment the following if you get errors about not having access to the system's install +# bundle config --local path 'vendor/bundle' + bundle install bundle exec pod install