Skip to content
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
3 changes: 2 additions & 1 deletion Modules/Sources/WPMediaPicker/WPImageExporter.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

@import MobileCoreServices;
@import ImageIO;
@import UniformTypeIdentifiers;

@implementation WPImageExporter

Expand Down Expand Up @@ -33,7 +34,7 @@ + (BOOL)writeImage:(UIImage *)image withMetadata:(NSDictionary *)metadata toURL:
adjustedMetadata[(NSString *)kCGImagePropertyIPTCDictionary] = adjustedIPTC;
}

CGImageDestinationRef destination = CGImageDestinationCreateWithURL((CFURLRef)fileURL, kUTTypeJPEG, 1, nil);
CGImageDestinationRef destination = CGImageDestinationCreateWithURL((CFURLRef)fileURL, (CFStringRef)UTTypeJPEG.identifier, 1, nil);
if (destination == NULL) {
return NO;
}
Expand Down
134 changes: 0 additions & 134 deletions Modules/Sources/WPMediaPicker/WPInputMediaPickerViewController.m

This file was deleted.

6 changes: 3 additions & 3 deletions Modules/Sources/WPMediaPicker/WPMediaCapturePresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@import MobileCoreServices;
@import AVFoundation;
@import UniformTypeIdentifiers;

@interface WPMediaCapturePresenter () <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (nonatomic, strong, nullable) UIViewController *presentingViewController;
Expand Down Expand Up @@ -79,11 +80,10 @@ - (void)presentCaptureViewController
UIImagePickerControllerSourceTypeCamera]];
NSMutableSet *mediaDesired = [NSMutableSet new];
if (self.mediaType & WPMediaTypeImage) {
[mediaDesired addObject:(__bridge NSString *)kUTTypeImage];
[mediaDesired addObject:UTTypeImage.identifier];
}
if (self.mediaType & WPMediaTypeVideo) {
[mediaDesired addObject:(__bridge NSString *)kUTTypeMovie];

[mediaDesired addObject:UTTypeMovie.identifier];
}
if (mediaDesired.count > 0){
[mediaTypes intersectSet:mediaDesired];
Expand Down
37 changes: 26 additions & 11 deletions Modules/Sources/WPMediaPicker/WPMediaCapturePreviewCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ - (void)startCapture
CALayer *viewLayer = self.previewView.layer;
self.captureVideoPreviewLayer.frame = viewLayer.bounds;
self.captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
UIWindowScene *currentScene = [[[[UIApplication sharedApplication] windows] lastObject] windowScene];
self.captureVideoPreviewLayer.connection.videoOrientation = [self videoOrientationForInterfaceOrientation:[currentScene interfaceOrientation]];
UIWindowScene *currentScene = [self activeWindowScene];
self.captureVideoPreviewLayer.connection.videoRotationAngle = [self videoRotationAngleForInterfaceOrientation:[currentScene interfaceOrientation]];
[viewLayer addSublayer:self.captureVideoPreviewLayer];
});
}
Expand All @@ -121,24 +121,39 @@ - (void)startCapture

- (void)deviceOrientationDidChange:(NSNotification *)notification
{
if (self.captureVideoPreviewLayer.connection.supportsVideoOrientation) {
UIWindowScene *currentScene = [[[[UIApplication sharedApplication] windows] lastObject] windowScene];
self.captureVideoPreviewLayer.connection.videoOrientation = [self videoOrientationForInterfaceOrientation:[currentScene interfaceOrientation]];
UIWindowScene *currentScene = [self activeWindowScene];
self.captureVideoPreviewLayer.connection.videoRotationAngle = [self videoRotationAngleForInterfaceOrientation:[currentScene interfaceOrientation]];
}

- (UIWindowScene *)activeWindowScene
{
for (UIScene *scene in [UIApplication sharedApplication].connectedScenes) {
if ([scene isKindOfClass:[UIWindowScene class]] && scene.activationState == UISceneActivationStateForegroundActive) {
return (UIWindowScene *)scene;
}
}
// Fallback to first window scene if no active one found
for (UIScene *scene in [UIApplication sharedApplication].connectedScenes) {
if ([scene isKindOfClass:[UIWindowScene class]]) {
return (UIWindowScene *)scene;
}
}
return nil;
}

- (AVCaptureVideoOrientation)videoOrientationForInterfaceOrientation:(UIInterfaceOrientation)orientation
- (CGFloat)videoRotationAngleForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
switch (orientation) {
case UIInterfaceOrientationPortrait:
return AVCaptureVideoOrientationPortrait;
return 90.0;
case UIInterfaceOrientationPortraitUpsideDown:
return AVCaptureVideoOrientationPortraitUpsideDown;
return 270.0;
case UIInterfaceOrientationLandscapeLeft:
return AVCaptureVideoOrientationLandscapeLeft;
return 180.0;
case UIInterfaceOrientationLandscapeRight:
return AVCaptureVideoOrientationLandscapeRight;
default:return AVCaptureVideoOrientationPortrait;
return 0.0;
default:
return 90.0;
}
}

Expand Down
51 changes: 25 additions & 26 deletions Modules/Sources/WPMediaPicker/WPMediaPickerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#import "WPMediaGroupPickerViewController.h"
#import "WPPHAssetDataSource.h"
#import "WPMediaCapturePresenter.h"
#import "WPInputMediaPickerViewController.h"
#import "WPCarouselAssetsViewController.h"
#import "UIViewController+MediaAdditions.h"

@import MobileCoreServices;
@import AVFoundation;
@import UniformTypeIdentifiers;

static CGFloat const IPhoneSELandscapeWidth = 568.0f;
static CGFloat const IPhone7PortraitWidth = 375.0f;
Expand Down Expand Up @@ -114,7 +114,8 @@ - (void)viewDidLoad
[self.view addGestureRecognizer:self.longPressGestureRecognizer];

self.layout.sectionInsetReference = UICollectionViewFlowLayoutSectionInsetFromSafeArea;

[self registerForTraitObservation];

[self refreshDataAnimated:NO];
}

Expand Down Expand Up @@ -317,18 +318,6 @@ - (void)viewDidDisappear:(BOOL)animated
[self unregisterForKeyboardNotifications];
}

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
{
[super traitCollectionDidChange:previousTraitCollection];

if ([self shouldShowCustomHeaderView]) {
// If there's a custom header, we'll invalidate it so that it can adapt itself to dynamic type changes.
UICollectionViewFlowLayoutInvalidationContext *context = [UICollectionViewFlowLayoutInvalidationContext new];
[context invalidateSupplementaryElementsOfKind:UICollectionElementKindSectionHeader atIndexPaths:@[ [NSIndexPath indexPathForRow:0 inSection:0] ]];
[self.collectionView.collectionViewLayout invalidateLayout];
}
}

- (UIViewController *)viewControllerToUseToPresent
{
// viewControllerToUseToPresent defaults to self but could be set to nil. Reset to self if needed.
Expand Down Expand Up @@ -381,7 +370,6 @@ - (void)addCollectionViewToView
- (void)setupSearchBar
{
BOOL shouldShowSearchBar = self.options.showSearchBar &&
![self.parentViewController isKindOfClass:[WPInputMediaPickerViewController class]] && //Disable search bar on WPInputMediaPicker
[self.dataSource respondsToSelector:@selector(searchFor:)];

if (shouldShowSearchBar && self.searchBar == nil) {
Expand Down Expand Up @@ -999,7 +987,8 @@ - (void)configureBadgeViewForCell:(WPMediaCollectionViewCell *)cell withAsset:(i
NSString *uttype = [asset UTTypeIdentifier];

if ([self.options.badgedUTTypes containsObject:uttype]) {
NSString *tagName = (__bridge_transfer NSString *)(UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)uttype, kUTTagClassFilenameExtension));
UTType *type = [UTType typeWithIdentifier:uttype];
NSString *tagName = type.preferredFilenameExtension;
cell.badgeView.label.text = [tagName uppercaseString];
cell.badgeView.hidden = NO;
return;
Expand Down Expand Up @@ -1274,12 +1263,12 @@ - (void)processMediaCaptured:(NSDictionary *)info
}
[self addMedia:media animated:YES];
};
if ([info[UIImagePickerControllerMediaType] isEqual:(NSString *)kUTTypeImage]) {
if ([info[UIImagePickerControllerMediaType] isEqual:UTTypeImage.identifier]) {
UIImage *image = (UIImage *)info[UIImagePickerControllerOriginalImage];
[self.dataSource addImage:image
metadata:info[UIImagePickerControllerMediaMetadata]
completionBlock:completionBlock];
} else if ([info[UIImagePickerControllerMediaType] isEqual:(NSString *)kUTTypeMovie]) {
} else if ([info[UIImagePickerControllerMediaType] isEqual:UTTypeMovie.identifier]) {
[self.dataSource addVideoFromURL:info[UIImagePickerControllerMediaURL] completionBlock:completionBlock];
}
}
Expand Down Expand Up @@ -1466,20 +1455,30 @@ - (BOOL)isPresentedAsPopover
return NO;
}

- (void)registerForTraitObservation
{
__weak typeof(self) weakSelf = self;
[self registerForTraitChanges:@[UITraitPreferredContentSizeCategory.class]
withHandler:^(id<UITraitEnvironment> traitEnvironment, UITraitCollection *previousCollection) {
if ([weakSelf shouldShowCustomHeaderView]) {
// If there's a custom header, invalidate it so that it can adapt itself to dynamic type changes.
UICollectionViewFlowLayoutInvalidationContext *context = [UICollectionViewFlowLayoutInvalidationContext new];
[context invalidateSupplementaryElementsOfKind:UICollectionElementKindSectionHeader atIndexPaths:@[ [NSIndexPath indexPathForRow:0 inSection:0] ]];
[weakSelf.collectionView.collectionViewLayout invalidateLayout];
}
}];
}

- (void)registerForKeyboardNotifications
{
if (![self.parentViewController isKindOfClass:[WPInputMediaPickerViewController class]]) {
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(keyboardWillShowNotification:) name:UIKeyboardWillShowNotification object:nil];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(keyboardWillHideNotification:) name:UIKeyboardWillHideNotification object:nil];
}
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(keyboardWillShowNotification:) name:UIKeyboardWillShowNotification object:nil];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(keyboardWillHideNotification:) name:UIKeyboardWillHideNotification object:nil];
}

- (void)unregisterForKeyboardNotifications
{
if (![self.parentViewController isKindOfClass:[WPInputMediaPickerViewController class]]) {
[NSNotificationCenter.defaultCenter removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[NSNotificationCenter.defaultCenter removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
[NSNotificationCenter.defaultCenter removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[NSNotificationCenter.defaultCenter removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

- (void)keyboardWillShowNotification:(NSNotification *)notification
Expand Down

This file was deleted.