Skip to content

Commit

Permalink
Update pod.
Browse files Browse the repository at this point in the history
  • Loading branch information
antrix1989 committed Apr 24, 2019
1 parent f7ea3e3 commit d61d488
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 36 deletions.
Empty file removed Pod/Assets/.gitkeep
Empty file.
Empty file removed Pod/Classes/.gitkeep
Empty file.
14 changes: 13 additions & 1 deletion Pod/Classes/MWPhotoBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@

@protocol MWProfilePhotosLikeActions <NSObject>

- (BOOL)canShowLikeAnimation;
- (NSUInteger)likesCount:(NSInteger)photoIndex;
- (BOOL)isLiked:(NSInteger)photoIndex;
- (void)likePhoto:(NSInteger)photoIndex like:(BOOL)like;
- (void)showLikes:(NSInteger)photoIndex;
- (void)removeLikesView;

@end

@interface MWPhotoBrowser : UIViewController <UIScrollViewDelegate, UIActionSheetDelegate>
@interface MWPhotoBrowser : UIViewController <UIScrollViewDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate>

@property (nonatomic, weak) IBOutlet id<MWPhotoBrowserDelegate> delegate;
@property (nonatomic, weak) id<MWProfilePhotosLikeActions> fullscreenPhotoDelegate;
Expand All @@ -61,6 +64,13 @@
@property (nonatomic) BOOL autoPlayOnAppear;
@property (nonatomic) NSUInteger delayToHideElements;
@property (nonatomic, readonly) NSUInteger currentIndex;
@property (nonatomic) NSUInteger currentPageIndex;
@property (nonatomic) UIView *transparentView;
@property (nonatomic) UIView *likesView;
@property (nonatomic) BOOL isLikesViewOpened;
@property (nonatomic) BOOL showShareButton;
@property (nonatomic) BOOL showLikesContainer;
@property (nonatomic, copy) void(^onShareButtonTappedBlock)(UIButton *button);

// Customise image selection icons as they are the only icons with a colour tint
// Icon should be located in the app's main bundle
Expand All @@ -81,6 +91,8 @@
- (void)showNextPhotoAnimated:(BOOL)animated;
- (void)showPreviousPhotoAnimated:(BOOL)animated;

// Like button
- (void)likeButtonPressed;
- (void)update;

@end
162 changes: 133 additions & 29 deletions Pod/Classes/MWPhotoBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ - (void)_initialisation {
_currentGridContentOffset = CGPointMake(0, CGFLOAT_MAX);
_didSavePreviousStateOfNavBar = NO;
self.automaticallyAdjustsScrollViewInsets = NO;
_isLikesViewOpened = NO;

// Listen for MWPhoto notifications
[[NSNotificationCenter defaultCenter] addObserver:self
Expand All @@ -99,6 +100,7 @@ - (void)dealloc {
[[SDImageCache sharedImageCache] clearMemory]; // clear memory
}


- (void)releaseAllUnderlyingPhotos:(BOOL)preserveCurrent {
// Create a copy in case this array is modified while we are looping through
// Release photos
Expand Down Expand Up @@ -159,29 +161,45 @@ - (void)viewDidLoad {
_pagingScrollView.contentSize = [self contentSizeForPagingScrollView];
[self.view addSubview:_pagingScrollView];

// Setup likes container under scroll view
CGRect likesContainerRect = [self frameForLikesContainer];
_likesContainer = [[UIView alloc] initWithFrame:likesContainerRect];
_likesContainer.backgroundColor = [UIColor clearColor];
[self.view addSubview:_likesContainer];

// Setup like button
CGRect likesButtonRect = [self frameForLikeButton];
_likesButton = [[UIButton alloc] initWithFrame:likesButtonRect];
[_likesButton setImage:[UIImage imageNamed:@"like_unselected"] forState:UIControlStateNormal];
[_likesButton setImage:[UIImage imageNamed:@"like_selected"] forState:UIControlStateSelected];
[_likesButton addTarget:self action:@selector(likeButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[_likesContainer addSubview:_likesButton];

// Setup like label
CGRect likesLabelRect = [self frameForLikesLabel];
_likesLabel = [[UILabel alloc] initWithFrame:likesLabelRect];
[_likesLabel setFont:[UIFont systemFontOfSize:22]];
_likesLabel.textColor = [UIColor colorWithRed:172.0/255.0 green:172.0/255.0 blue:172.0/255.0 alpha:1];
_likesLabel.numberOfLines = 1;
[_likesContainer addSubview:_likesLabel];


if (self.showLikesContainer) {
// Setup likes container under scroll view
CGRect likesContainerRect = [self frameForLikesContainer];
_likesContainer = [[UIView alloc] initWithFrame:likesContainerRect];
_likesContainer.backgroundColor = [UIColor clearColor];
[self.view addSubview:_likesContainer];

// Setup like button
CGRect likesButtonRect = [self frameForLikeButton];
_likesButton = [[UIButton alloc] initWithFrame:likesButtonRect];
[_likesButton setImage:[UIImage imageNamed:@"like_unselected"] forState:UIControlStateNormal];
[_likesButton setImage:[UIImage imageNamed:@"like_selected"] forState:UIControlStateSelected];
[_likesButton addTarget:self action:@selector(likeButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[_likesContainer addSubview:_likesButton];

// Setup like label
CGRect likesLabelRect = [self frameForLikesLabel];
_likesLabel = [[UILabel alloc] initWithFrame:likesLabelRect];
[_likesLabel setFont:[UIFont systemFontOfSize:20]];
[_likesLabel setUserInteractionEnabled:YES];
UITapGestureRecognizer *tapOnLikesLabel = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showLikesView)];
tapOnLikesLabel.delegate = self;
[_likesLabel addGestureRecognizer:tapOnLikesLabel];
_likesLabel.textColor = [UIColor colorWithRed:172.0/255.0 green:172.0/255.0 blue:172.0/255.0 alpha:1];
_likesLabel.numberOfLines = 1;
[_likesContainer addSubview:_likesLabel];
}

///
if (self.showShareButton) {
CGRect shareButtonFrame = [self frameForShareButton];
UIButton *shareButton = [[UIButton alloc] initWithFrame:shareButtonFrame];
[shareButton setImage:[UIImage imageNamed:@"share"] forState:UIControlStateNormal];
[shareButton addTarget:self action:@selector(onShareButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:shareButton];
}

///

// Toolbar
_toolbar = [[UIToolbar alloc] initWithFrame:[self frameForToolbarAtOrientation:self.interfaceOrientation]];
_toolbar.tintColor = [UIColor whiteColor];
Expand Down Expand Up @@ -214,7 +232,10 @@ - (void)viewDidLoad {
[self.view addGestureRecognizer:swipeGesture];
}

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-60, -60) forBarMetrics:UIBarMetricsDefault];
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version < 11.0) {
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-60, -60) forBarMetrics:UIBarMetricsDefault];
}

// Super
[super viewDidLoad];
Expand Down Expand Up @@ -329,6 +350,8 @@ - (void)viewDidUnload {
_likesContainer = nil;
_likesLabel = nil;
_likesButton = nil;
_transparentView = nil;
_likesView = nil;
_visiblePages = nil;
_recycledPages = nil;
_toolbar = nil;
Expand Down Expand Up @@ -384,6 +407,8 @@ - (void)viewWillAppear:(BOOL)animated {
[self storePreviousNavBarAppearance];
}
[self setNavBarAppearance:animated];
[self.navigationController setNavigationBarHidden:self.isLikesViewOpened];


// Update UI
[self hideControlsAfterDelay];
Expand Down Expand Up @@ -431,8 +456,8 @@ - (void)viewWillDisappear:(BOOL)animated {

// Check that we're disappearing for good
// self.isMovingFromParentViewController just doesn't work, ever. Or self.isBeingDismissed
if ((_doneButton && self.navigationController.isBeingDismissed) ||
([self.navigationController.viewControllers objectAtIndex:0] != self && ![self.navigationController.viewControllers containsObject:self])) {
//if ((_doneButton && self.navigationController.isBeingDismissed) ||
// ([self.navigationController.viewControllers objectAtIndex:0] != self && ![self.navigationController.viewControllers containsObject:self])) {

// State
_viewIsActive = NO;
Expand All @@ -441,7 +466,7 @@ - (void)viewWillDisappear:(BOOL)animated {
// Bar state / appearance
[self restorePreviousNavBarAppearance:animated];

}
//}

// Controls
[self.navigationController.navigationBar.layer removeAllAnimations]; // Stop all animations on nav bar
Expand Down Expand Up @@ -503,6 +528,7 @@ - (void)storePreviousNavBarAppearance {
- (void)restorePreviousNavBarAppearance:(BOOL)animated {
if (_didSavePreviousStateOfNavBar) {
[self.navigationController setNavigationBarHidden:_previousNavBarHidden animated:animated];
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
UINavigationBar *navBar = self.navigationController.navigationBar;
navBar.tintColor = _previousNavBarTintColor;
navBar.translucent = _previousNavBarTranslucent;
Expand Down Expand Up @@ -1014,10 +1040,10 @@ - (void)update
_likesButton.selected = likedByMe;

//Update likes container
NSUInteger *likes = [_fullscreenPhotoDelegate likesCount:_currentPageIndex];
NSUInteger likes = [_fullscreenPhotoDelegate likesCount:_currentPageIndex];
if (likes > 0) {
NSString *likesWord = likes == 1 ? @"like" : @"likes";
_likesLabel.text = [NSString stringWithFormat:@"%d %@", likes, likesWord];
_likesLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)likes, likesWord];
} else {
_likesLabel.text = @"0 likes";
}
Expand All @@ -1041,6 +1067,17 @@ - (CGRect)frameForPagingScrollView {
return CGRectIntegral(frame);
}

- (CGRect)frameForShareButton
{
CGFloat containerWidth = 40;
CGFloat containerHeight = 40;
CGRect scrollViewFrame = [self frameForPagingScrollView];
CGFloat posX = 12;
CGFloat posY = scrollViewFrame.origin.y + scrollViewFrame.size.height;
CGRect frame = CGRectMake(posX, posY, containerWidth, containerHeight);
return CGRectIntegral(frame);
}

- (CGRect)frameForLikesContainer {
CGFloat containerWidth = 120;
CGFloat containerHeight = 40;
Expand Down Expand Up @@ -1734,6 +1771,73 @@ - (void)likeButtonPressed {
[_fullscreenPhotoDelegate isLiked:_currentPageIndex];
}

- (void)onShareButtonTapped:(UIButton *)button
{
if (self.onShareButtonTappedBlock) {
self.onShareButtonTappedBlock(button);
}
}

// MARK: - Show likes view

- (void)showLikesView {
if (!_isLikesViewOpened && ![_likesLabel.text isEqualToString:@""]) {
self.transparentView = [[UIView alloc] initWithFrame:self.view.frame];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeLikesView)];
tapGesture.delegate = self;
[self.transparentView addGestureRecognizer:tapGesture];
[self.view addSubview:self.transparentView];

CGRect transparentViewFrame = self.transparentView.frame;
CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
CGFloat likesContainerWidth = transparentViewFrame.size.width * 0.75;
CGFloat likesContainerHeight = transparentViewFrame.size.height - statusBarHeight;
CGRect likersViewFrame = CGRectMake(self.view.frame.size.width, statusBarHeight, likesContainerWidth, likesContainerHeight);
self.likesView = [[UIView alloc] initWithFrame:likersViewFrame];
[_transparentView addSubview:_likesView];
[self.fullscreenPhotoDelegate showLikes:_currentPageIndex];
[self animateLikesView];
}
}

- (void)animateLikesView {
CGRect likesViewFrame = self.likesView.frame;
[UIView animateWithDuration:0.5 animations:^{
[self.transparentView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.5]];
self.likesView.frame = CGRectMake(self.view.frame.size.width - likesViewFrame.size.width, likesViewFrame.origin.y, likesViewFrame.size.width, likesViewFrame.size.height);
[self.navigationController setNavigationBarHidden:YES];
} completion:^(BOOL finished) {
_isLikesViewOpened = YES;
}];
}

- (void)closeLikesView {
CGRect likesViewFrame = self.likesView.frame;
CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
[UIView animateWithDuration:0.5 animations:^{
[self.transparentView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0]];
self.likesView.frame = CGRectMake(self.view.frame.size.width, statusBarHeight, likesViewFrame.size.width, likesViewFrame.size.height);
} completion:^(BOOL finished) {
[self.navigationController setNavigationBarHidden:NO];
[_fullscreenPhotoDelegate removeLikesView];
[_likesView removeFromSuperview];
[_transparentView removeFromSuperview];
_likesView = nil;
_transparentView = nil;
_isLikesViewOpened = NO;
}];
}

// MARK: - UITapGestureRecognizer

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if (touch.view == _transparentView || touch.view == _likesLabel) {
return YES;
} else {
return NO;
}
}

#pragma mark - Action Progress

- (MBProgressHUD *)progressHUD {
Expand Down
1 change: 0 additions & 1 deletion Pod/Classes/MWPhotoBrowserPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

// Paging & layout
NSMutableSet *_visiblePages, *_recycledPages;
NSUInteger _currentPageIndex;
NSUInteger _previousPageIndex;
CGRect _previousLayoutBounds;
NSUInteger _pageIndexBeforeRotation;
Expand Down
2 changes: 1 addition & 1 deletion Pod/Classes/MWTapDetectingImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
- (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch;
- (void)imageView:(UIImageView *)imageView tripleTapDetected:(UITouch *)touch;

@end
@end
1 change: 1 addition & 0 deletions Pod/Classes/MWZoomingScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@property (nonatomic, weak) MWCaptionView *captionView;
@property (nonatomic, weak) UIButton *selectedButton;
@property (nonatomic, weak) UIButton *playButton;
@property (nonatomic, weak) MWPhotoBrowser *photoBrowser;

- (id)initWithPhotoBrowser:(MWPhotoBrowser *)browser;
- (void)displayImage;
Expand Down
13 changes: 9 additions & 4 deletions Pod/Classes/MWZoomingScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -428,20 +428,25 @@ - (void)imageView:(UIImageView *)imageView singleTapDetected:(UITouch *)touch {
[self handleSingleTap:[touch locationInView:imageView]];
}

- (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch {
- (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch
{
if (!self.photoBrowser.showLikesContainer) { return; }

if (![self.photoBrowser.fullscreenPhotoDelegate canShowLikeAnimation]) { return; }

UIImageView *likeAnimationView = [[UIImageView alloc] initWithFrame:[self frameForLikeAnimation:self.frame]];
likeAnimationView.image = [UIImage imageNamed:@"big_heart"];
likeAnimationView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:likeAnimationView];

[UIView animateWithDuration:0.1f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
likeAnimationView.transform = CGAffineTransformMakeScale(1.3, 1.3);
likeAnimationView.alpha = 1.0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.1f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
likeAnimationView.transform = CGAffineTransformMakeScale(1.0, 1.0);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.1f delay:0.3 options:UIViewAnimationOptionAllowUserInteraction animations:^{
[UIView animateWithDuration:0.2f delay:0.3 options:UIViewAnimationOptionAllowUserInteraction animations:^{
likeAnimationView.transform = CGAffineTransformMakeScale(0.3, 0.3);
likeAnimationView.alpha = 0.0;
} completion:^(BOOL finished) {
Expand Down

0 comments on commit d61d488

Please sign in to comment.