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

add 'statusBarMode' to drive whether the status bar is hidden or not. #336

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
26 changes: 26 additions & 0 deletions NYTPhotoViewer/NYTPhotosViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification;

@interface NYTPhotosViewController : UIViewController

typedef NS_ENUM(NSUInteger, NYTPhotoViewerStatusBarMode) {
NYTPhotoViewerStatusBarModeDynamic, /* hide statusbar when view.safeArea.top == 0 */
NYTPhotoViewerStatusBarModeHidden,
NYTPhotoViewerStatusBarModeShown
};

/**
* The pan gesture recognizer used for panning to dismiss the photo. Disable to stop the pan-to-dismiss behavior.
*/
Expand Down Expand Up @@ -75,6 +81,12 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification;
*/
@property (nonatomic, readonly, nullable) NYTPhotosOverlayView *overlayView;

/**
* This determines whether we display the status bar or not
* Defaults to NYTPhotoViewerStatusBarModeDynamic.
*/
@property (nonatomic) NYTPhotoViewerStatusBarMode statusBarMode;

/**
* The left bar button item overlaying the photo.
*/
Expand Down Expand Up @@ -177,6 +189,20 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification;

@optional

/**
* Called when the view is about to made visible.
*
* @param photosViewController The `NYTPhotosViewController` instance that sent the delegate message.
mr-fixit marked this conversation as resolved.
Show resolved Hide resolved
*/
- (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.
*
Expand Down
49 changes: 46 additions & 3 deletions NYTPhotoViewer/NYTPhotosViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -142,12 +156,41 @@ - (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.prefersStatusBarHidden) {
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 {
return YES;
BOOL result;
switch (self.statusBarMode) {
case NYTPhotoViewerStatusBarModeDynamic:
result = self.view.safeAreaInsets.top == 0;
break;
case NYTPhotoViewerStatusBarModeHidden:
result = true;
break;
case NYTPhotoViewerStatusBarModeShown:
result = false;
break;
}
return result;
}

- (void)viewSafeAreaInsetsDidChange {
if (self.statusBarMode == NYTPhotoViewerStatusBarModeDynamic) {
[self setNeedsStatusBarAppearanceUpdate];
}
[super viewSafeAreaInsetsDidChange];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
mr-fixit marked this conversation as resolved.
Show resolved Hide resolved
}

- (BOOL)prefersHomeIndicatorAutoHidden {
Expand Down
4 changes: 3 additions & 1 deletion scripts/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -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
mr-fixit marked this conversation as resolved.
Show resolved Hide resolved
# bundle config --local path 'vendor/bundle'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually pretty rare to mention this stuff in a script like this. If we want to guide people on their ruby setup, maybe we should do it in the readme instead, under a "Contributing" section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm happy to delete it. it's probably wrong-advice anyway.


bundle install
bundle exec pod install