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 share GIF #263

Open
wants to merge 3 commits into
base: develop
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Changes for users of the library in 2.0.0:
- A data source no longer has to handle out-of-bounds indexes ([#227](https://github.com/NYTimes/NYTPhotoViewer/pull/227))
- The data source is not retained ([#227](https://github.com/NYTimes/NYTPhotoViewer/pull/227))
- Respect safe areas for iOS 11 support
- Fixed some tests, added tests for NYTPhotoViewerSinglePhotoDataSource
- Fixed a strict warning and a subscripting bug in NYTPhotoViewerArrayDataSource.m
- Share GIF with UIActivityViewController
- Copy GIF with UIMenuController

## [1.2.0](https://github.com/NYTimes/NYTPhotoViewer/releases/tag/1.2.0)

Expand Down
14 changes: 11 additions & 3 deletions NYTPhotoViewer/NYTPhotosViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import "NYTPhotosOverlayView.h"
#import "NYTPhotoCaptionView.h"
#import "NSBundle+NYTPhotoViewer.h"
#import <MobileCoreServices/MobileCoreServices.h>

#ifdef ANIMATED_GIF_SUPPORT
#import <FLAnimatedImage/FLAnimatedImage.h>
Expand Down Expand Up @@ -70,7 +71,12 @@ - (void)dealloc {
#pragma mark - NSObject(UIResponderStandardEditActions)

- (void)copy:(id)sender {
[[UIPasteboard generalPasteboard] setImage:self.currentlyDisplayedPhoto.image];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
if (self.currentlyDisplayedPhoto.image) {
[pasteboard setImage:self.currentlyDisplayedPhoto.image];
} else {
[pasteboard setData:self.currentlyDisplayedPhoto.imageData forPasteboardType:(NSString *) kUTTypeGIF];
}
}

#pragma mark - UIResponder
Expand All @@ -80,7 +86,9 @@ - (BOOL)canBecomeFirstResponder {
}

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (self.shouldHandleLongPress && action == @selector(copy:) && self.currentlyDisplayedPhoto.image) {
BOOL containsImage = self.currentlyDisplayedPhoto.image || self.currentlyDisplayedPhoto.imageData;

if (self.shouldHandleLongPress && action == @selector(copy:) && containsImage) {
return YES;
}

Expand Down Expand Up @@ -290,7 +298,7 @@ - (void)actionButtonTapped:(id)sender {
}

if (!clientDidHandle && (self.currentlyDisplayedPhoto.image || self.currentlyDisplayedPhoto.imageData)) {
UIImage *image = self.currentlyDisplayedPhoto.image ? self.currentlyDisplayedPhoto.image : [UIImage imageWithData:self.currentlyDisplayedPhoto.imageData];
NSData *image = self.currentlyDisplayedPhoto.image ? UIImagePNGRepresentation(self.currentlyDisplayedPhoto.image) : self.currentlyDisplayedPhoto.imageData;
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[image] applicationActivities:nil];
activityViewController.popoverPresentationController.barButtonItem = sender;
activityViewController.completionWithItemsHandler = ^(NSString * __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError) {
Expand Down