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

Bounds check when pulling item for page. Preemptive return if no image v... #31

Open
wants to merge 3 commits into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ extern UIImage *MHGalleryImage(NSString *imageName);

extern UIView *MHStatusBar(void);

extern CGFloat MHToolbarHeightForOrientation(UIInterfaceOrientation orientation);

extern NSString *const MHYoutubeChannel;
extern NSString *const MHGalleryViewModeShare;
extern NSString *const MHVimeoVideoBaseURL;
Expand Down
11 changes: 11 additions & 0 deletions MHVideoPhotoGallery/MMHVideoPhotoGallery/MHGallery/MHGallery.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@
return statusBar;
}

CGFloat MHToolbarHeightForOrientation(UIInterfaceOrientation orientation) {
CGFloat toolbarHeight = 44.0f;

if (!MHISIPAD) {
if (UIInterfaceOrientationIsLandscape(orientation)) {
toolbarHeight = 32.0f;
}
}

return toolbarHeight;
}

UIImage *MHTemplateImage(NSString *imageName){
return [MHGalleryImage(imageName) imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ -(void)setInteractivePresentationTransition:(MHTransitionPresentMHGallery *)inte
}

-(MHGalleryItem *)itemForIndex:(NSInteger)index{
if (index < 0 || index >= self.galleryItems.count) {
return nil;
}

return self.galleryItems[index];
}

-(NSInteger)numberOfItemsInGallery:(MHGalleryController *)galleryController{
return self.galleryItems.count;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ -(void)viewDidLoad{
[self.pageViewController didMoveToParentViewController:self];
[self.view addSubview:self.pageViewController.view];

self.toolbar = [UIToolbar.alloc initWithFrame:CGRectMake(0, self.view.frame.size.height-44, self.view.frame.size.width, 44)];
self.toolbar = [UIToolbar.alloc initWithFrame:CGRectMake(0, self.view.frame.size.height-MHToolbarHeightForOrientation(self.currentOrientation), self.view.frame.size.width, MHToolbarHeightForOrientation(self.currentOrientation))];
if(self.currentOrientation == UIInterfaceOrientationLandscapeLeft || self.currentOrientation == UIInterfaceOrientationLandscapeRight){
if (self.view.bounds.size.height > self.view.bounds.size.width) {
self.toolbar.frame = CGRectMake(0, self.view.frame.size.width-44, self.view.frame.size.height, 44);
self.toolbar.frame = CGRectMake(0, self.view.frame.size.width-MHToolbarHeightForOrientation(self.currentOrientation), self.view.frame.size.height, MHToolbarHeightForOrientation(self.currentOrientation));
}
}

Expand Down Expand Up @@ -435,6 +435,10 @@ -(void)leftPressed:(id)sender{
self.leftBarButton.enabled = NO;
}

if (!imageViewController) {
return;
}

__weak typeof(self) weakSelf = self;

[self.pageViewController setViewControllers:@[imageViewController] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:^(BOOL finished) {
Expand All @@ -455,6 +459,11 @@ -(void)rightPressed:(id)sender{
if (indexPage+1 == self.numberOfGalleryItems-1) {
self.rightBarButton.enabled = NO;
}

if (!imageViewController) {
return;
}

__weak typeof(self) weakSelf = self;

[self.pageViewController setViewControllers:@[imageViewController] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) {
Expand Down Expand Up @@ -523,7 +532,7 @@ - (UIViewController *)pageViewController:(UIPageViewController *)pvc viewControl
}

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
self.toolbar.frame = CGRectMake(0, self.view.frame.size.height-44, self.view.frame.size.width, 44);
self.toolbar.frame = CGRectMake(0, self.view.frame.size.height-MHToolbarHeightForOrientation(self.currentOrientation), self.view.frame.size.width, MHToolbarHeightForOrientation(self.currentOrientation));
self.pageViewController.view.bounds = self.view.bounds;
[self.pageViewController.view.subviews.firstObject setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) ];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ -(void)setGalleryItem:(MHGalleryItem *)galleryItem{

__weak typeof(self) weakSelf = self;

[self.activityIndicator startAnimating];

if (galleryItem.galleryType == MHGalleryTypeVideo) {
[MHGallerySharedManager.sharedManager startDownloadingThumbImage:galleryItem.URLString
successBlock:^(UIImage *image,NSUInteger videoDuration,NSError *error) {
Expand All @@ -97,6 +99,8 @@ -(void)setGalleryItem:(MHGalleryItem *)galleryItem{
}];
}else{
[self.thumbnail setImageForMHGalleryItem:galleryItem imageType:MHImageTypeThumb successBlock:^(UIImage *image, NSError *error) {
[weakSelf.activityIndicator stopAnimating];

if (!image) {
weakSelf.thumbnail.backgroundColor = UIColor.whiteColor;
weakSelf.thumbnail.image = MHGalleryImage(@"error");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCo
UITextView *descriptionLabel = toViewController.descriptionView;
descriptionLabel.alpha =0;

CGFloat toolbarHeight = MHToolbarHeightForOrientation([UIApplication sharedApplication].statusBarOrientation);
UIToolbar *tb = toViewController.toolbar;
tb.alpha =0;
tb.frame = CGRectMake(0, toViewController.view.frame.size.height-44, toViewController.view.frame.size.width , 44);
tb.frame = CGRectMake(0, toViewController.view.frame.size.height-toolbarHeight, toViewController.view.frame.size.width, toolbarHeight);

UIToolbar *descriptionViewBackground = toViewController.descriptionViewBackground;
descriptionViewBackground.alpha =0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,8 @@ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCo

[containerView addSubview:toViewController.view];




toViewController.toolbar.frame = CGRectMake(0, fromViewController.view.frame.size.height-44, fromViewController.view.frame.size.width, 44);
CGFloat toolbarHeight = MHToolbarHeightForOrientation([UIApplication sharedApplication].statusBarOrientation);
toViewController.toolbar.frame = CGRectMake(0, fromViewController.view.frame.size.height-toolbarHeight, fromViewController.view.frame.size.width, toolbarHeight);
MHGalleryController *galleryController = (MHGalleryController*)fromViewController.navigationController;
MHGalleryItem *item = [galleryController.dataSource itemForIndex:toViewController.pageIndex];
[toViewController updateToolBarForItem:item];
Expand Down