Skip to content

Commit 3eb597f

Browse files
committed
Disabled action button for videos
1 parent 7a5fdd6 commit 3eb597f

File tree

2 files changed

+52
-50
lines changed

2 files changed

+52
-50
lines changed

Pod/Classes/MWPhotoBrowser.m

+52-49
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,16 @@ - (void)updateNavigation {
11001100
// Buttons
11011101
_previousButton.enabled = (_currentPageIndex > 0);
11021102
_nextButton.enabled = (_currentPageIndex < numberOfPhotos - 1);
1103-
_actionButton.enabled = [[self photoAtIndex:_currentPageIndex] underlyingImage] != nil;
1103+
1104+
// Disable action button if there is no image or it's a video
1105+
MWPhoto *photo = [self photoAtIndex:_currentPageIndex];
1106+
if ([photo underlyingImage] == nil || ([photo respondsToSelector:@selector(isVideo)] && photo.isVideo)) {
1107+
_actionButton.enabled = NO;
1108+
_actionButton.tintColor = [UIColor clearColor]; // Tint to hide button
1109+
} else {
1110+
_actionButton.enabled = YES;
1111+
_actionButton.tintColor = nil;
1112+
}
11041113

11051114
}
11061115

@@ -1529,61 +1538,55 @@ - (void)doneButtonPressed:(id)sender {
15291538
#pragma mark - Actions
15301539

15311540
- (void)actionButtonPressed:(id)sender {
1532-
if (_actionsSheet) {
1533-
1534-
// Dismiss
1535-
[_actionsSheet dismissWithClickedButtonIndex:_actionsSheet.cancelButtonIndex animated:YES];
1536-
1537-
} else {
1541+
1542+
// Only react when image has loaded
1543+
id <MWPhoto> photo = [self photoAtIndex:_currentPageIndex];
1544+
if ([self numberOfPhotos] > 0 && [photo underlyingImage]) {
15381545

1539-
// Only react when image has loaded
1540-
id <MWPhoto> photo = [self photoAtIndex:_currentPageIndex];
1541-
if ([self numberOfPhotos] > 0 && [photo underlyingImage]) {
1546+
// If they have defined a delegate method then just message them
1547+
if ([self.delegate respondsToSelector:@selector(photoBrowser:actionButtonPressedForPhotoAtIndex:)]) {
15421548

1543-
// If they have defined a delegate method then just message them
1544-
if ([self.delegate respondsToSelector:@selector(photoBrowser:actionButtonPressedForPhotoAtIndex:)]) {
1545-
1546-
// Let delegate handle things
1547-
[self.delegate photoBrowser:self actionButtonPressedForPhotoAtIndex:_currentPageIndex];
1548-
1549-
} else {
1550-
1551-
// Show activity view controller
1552-
NSMutableArray *items = [NSMutableArray arrayWithObject:[photo underlyingImage]];
1553-
if (photo.caption) {
1554-
[items addObject:photo.caption];
1555-
}
1556-
self.activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
1557-
1558-
// Show loading spinner after a couple of seconds
1559-
double delayInSeconds = 2.0;
1560-
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
1561-
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
1562-
if (self.activityViewController) {
1563-
[self showProgressHUDWithMessage:nil];
1564-
}
1565-
});
1566-
1567-
// Show
1568-
typeof(self) __weak weakSelf = self;
1569-
[self.activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) {
1570-
weakSelf.activityViewController = nil;
1571-
[weakSelf hideControlsAfterDelay];
1572-
[weakSelf hideProgressHUD:YES];
1573-
}];
1574-
// iOS 8 - Set the Anchor Point for the popover
1575-
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8")) {
1576-
self.activityViewController.popoverPresentationController.barButtonItem = _actionButton;
1577-
}
1578-
[self presentViewController:self.activityViewController animated:YES completion:nil];
1579-
1549+
// Let delegate handle things
1550+
[self.delegate photoBrowser:self actionButtonPressedForPhotoAtIndex:_currentPageIndex];
1551+
1552+
} else {
1553+
1554+
// Show activity view controller
1555+
NSMutableArray *items = [NSMutableArray arrayWithObject:[photo underlyingImage]];
1556+
if (photo.caption) {
1557+
[items addObject:photo.caption];
15801558
}
1559+
self.activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
15811560

1582-
// Keep controls hidden
1583-
[self setControlsHidden:NO animated:YES permanent:YES];
1561+
// Show loading spinner after a couple of seconds
1562+
double delayInSeconds = 2.0;
1563+
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
1564+
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
1565+
if (self.activityViewController) {
1566+
[self showProgressHUDWithMessage:nil];
1567+
}
1568+
});
1569+
1570+
// Show
1571+
typeof(self) __weak weakSelf = self;
1572+
[self.activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) {
1573+
weakSelf.activityViewController = nil;
1574+
[weakSelf hideControlsAfterDelay];
1575+
[weakSelf hideProgressHUD:YES];
1576+
}];
1577+
// iOS 8 - Set the Anchor Point for the popover
1578+
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8")) {
1579+
self.activityViewController.popoverPresentationController.barButtonItem = _actionButton;
1580+
}
1581+
[self presentViewController:self.activityViewController animated:YES completion:nil];
15841582

15851583
}
1584+
1585+
// Keep controls hidden
1586+
[self setControlsHidden:NO animated:YES permanent:YES];
1587+
15861588
}
1589+
15871590
}
15881591

15891592
#pragma mark - Action Progress

Pod/Classes/MWPhotoBrowserPrivate.h

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
NSTimer *_controlVisibilityTimer;
3737
UIBarButtonItem *_previousButton, *_nextButton, *_actionButton, *_doneButton;
3838
MBProgressHUD *_progressHUD;
39-
UIActionSheet *_actionsSheet;
4039

4140
// Grid
4241
MWGridViewController *_gridController;

0 commit comments

Comments
 (0)