|
5 | 5 | #import "WPMediaGroupPickerViewController.h" |
6 | 6 | #import "WPPHAssetDataSource.h" |
7 | 7 | #import "WPMediaCapturePresenter.h" |
8 | | -#import "WPInputMediaPickerViewController.h" |
9 | 8 | #import "WPCarouselAssetsViewController.h" |
10 | 9 | #import "UIViewController+MediaAdditions.h" |
11 | 10 |
|
12 | 11 | @import MobileCoreServices; |
13 | 12 | @import AVFoundation; |
| 13 | +@import UniformTypeIdentifiers; |
14 | 14 |
|
15 | 15 | static CGFloat const IPhoneSELandscapeWidth = 568.0f; |
16 | 16 | static CGFloat const IPhone7PortraitWidth = 375.0f; |
@@ -114,7 +114,8 @@ - (void)viewDidLoad |
114 | 114 | [self.view addGestureRecognizer:self.longPressGestureRecognizer]; |
115 | 115 |
|
116 | 116 | self.layout.sectionInsetReference = UICollectionViewFlowLayoutSectionInsetFromSafeArea; |
117 | | - |
| 117 | + [self registerForTraitObservation]; |
| 118 | + |
118 | 119 | [self refreshDataAnimated:NO]; |
119 | 120 | } |
120 | 121 |
|
@@ -317,18 +318,6 @@ - (void)viewDidDisappear:(BOOL)animated |
317 | 318 | [self unregisterForKeyboardNotifications]; |
318 | 319 | } |
319 | 320 |
|
320 | | -- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection |
321 | | -{ |
322 | | - [super traitCollectionDidChange:previousTraitCollection]; |
323 | | - |
324 | | - if ([self shouldShowCustomHeaderView]) { |
325 | | - // If there's a custom header, we'll invalidate it so that it can adapt itself to dynamic type changes. |
326 | | - UICollectionViewFlowLayoutInvalidationContext *context = [UICollectionViewFlowLayoutInvalidationContext new]; |
327 | | - [context invalidateSupplementaryElementsOfKind:UICollectionElementKindSectionHeader atIndexPaths:@[ [NSIndexPath indexPathForRow:0 inSection:0] ]]; |
328 | | - [self.collectionView.collectionViewLayout invalidateLayout]; |
329 | | - } |
330 | | -} |
331 | | - |
332 | 321 | - (UIViewController *)viewControllerToUseToPresent |
333 | 322 | { |
334 | 323 | // viewControllerToUseToPresent defaults to self but could be set to nil. Reset to self if needed. |
@@ -381,7 +370,6 @@ - (void)addCollectionViewToView |
381 | 370 | - (void)setupSearchBar |
382 | 371 | { |
383 | 372 | BOOL shouldShowSearchBar = self.options.showSearchBar && |
384 | | - ![self.parentViewController isKindOfClass:[WPInputMediaPickerViewController class]] && //Disable search bar on WPInputMediaPicker |
385 | 373 | [self.dataSource respondsToSelector:@selector(searchFor:)]; |
386 | 374 |
|
387 | 375 | if (shouldShowSearchBar && self.searchBar == nil) { |
@@ -999,7 +987,8 @@ - (void)configureBadgeViewForCell:(WPMediaCollectionViewCell *)cell withAsset:(i |
999 | 987 | NSString *uttype = [asset UTTypeIdentifier]; |
1000 | 988 |
|
1001 | 989 | if ([self.options.badgedUTTypes containsObject:uttype]) { |
1002 | | - NSString *tagName = (__bridge_transfer NSString *)(UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)uttype, kUTTagClassFilenameExtension)); |
| 990 | + UTType *type = [UTType typeWithIdentifier:uttype]; |
| 991 | + NSString *tagName = type.preferredFilenameExtension; |
1003 | 992 | cell.badgeView.label.text = [tagName uppercaseString]; |
1004 | 993 | cell.badgeView.hidden = NO; |
1005 | 994 | return; |
@@ -1274,12 +1263,12 @@ - (void)processMediaCaptured:(NSDictionary *)info |
1274 | 1263 | } |
1275 | 1264 | [self addMedia:media animated:YES]; |
1276 | 1265 | }; |
1277 | | - if ([info[UIImagePickerControllerMediaType] isEqual:(NSString *)kUTTypeImage]) { |
| 1266 | + if ([info[UIImagePickerControllerMediaType] isEqual:UTTypeImage.identifier]) { |
1278 | 1267 | UIImage *image = (UIImage *)info[UIImagePickerControllerOriginalImage]; |
1279 | 1268 | [self.dataSource addImage:image |
1280 | 1269 | metadata:info[UIImagePickerControllerMediaMetadata] |
1281 | 1270 | completionBlock:completionBlock]; |
1282 | | - } else if ([info[UIImagePickerControllerMediaType] isEqual:(NSString *)kUTTypeMovie]) { |
| 1271 | + } else if ([info[UIImagePickerControllerMediaType] isEqual:UTTypeMovie.identifier]) { |
1283 | 1272 | [self.dataSource addVideoFromURL:info[UIImagePickerControllerMediaURL] completionBlock:completionBlock]; |
1284 | 1273 | } |
1285 | 1274 | } |
@@ -1466,20 +1455,30 @@ - (BOOL)isPresentedAsPopover |
1466 | 1455 | return NO; |
1467 | 1456 | } |
1468 | 1457 |
|
| 1458 | +- (void)registerForTraitObservation |
| 1459 | +{ |
| 1460 | + __weak typeof(self) weakSelf = self; |
| 1461 | + [self registerForTraitChanges:@[UITraitPreferredContentSizeCategory.class] |
| 1462 | + withHandler:^(id<UITraitEnvironment> traitEnvironment, UITraitCollection *previousCollection) { |
| 1463 | + if ([weakSelf shouldShowCustomHeaderView]) { |
| 1464 | + // If there's a custom header, invalidate it so that it can adapt itself to dynamic type changes. |
| 1465 | + UICollectionViewFlowLayoutInvalidationContext *context = [UICollectionViewFlowLayoutInvalidationContext new]; |
| 1466 | + [context invalidateSupplementaryElementsOfKind:UICollectionElementKindSectionHeader atIndexPaths:@[ [NSIndexPath indexPathForRow:0 inSection:0] ]]; |
| 1467 | + [weakSelf.collectionView.collectionViewLayout invalidateLayout]; |
| 1468 | + } |
| 1469 | + }]; |
| 1470 | +} |
| 1471 | + |
1469 | 1472 | - (void)registerForKeyboardNotifications |
1470 | 1473 | { |
1471 | | - if (![self.parentViewController isKindOfClass:[WPInputMediaPickerViewController class]]) { |
1472 | | - [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(keyboardWillShowNotification:) name:UIKeyboardWillShowNotification object:nil]; |
1473 | | - [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(keyboardWillHideNotification:) name:UIKeyboardWillHideNotification object:nil]; |
1474 | | - } |
| 1474 | + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(keyboardWillShowNotification:) name:UIKeyboardWillShowNotification object:nil]; |
| 1475 | + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(keyboardWillHideNotification:) name:UIKeyboardWillHideNotification object:nil]; |
1475 | 1476 | } |
1476 | 1477 |
|
1477 | 1478 | - (void)unregisterForKeyboardNotifications |
1478 | 1479 | { |
1479 | | - if (![self.parentViewController isKindOfClass:[WPInputMediaPickerViewController class]]) { |
1480 | | - [NSNotificationCenter.defaultCenter removeObserver:self name:UIKeyboardWillShowNotification object:nil]; |
1481 | | - [NSNotificationCenter.defaultCenter removeObserver:self name:UIKeyboardWillHideNotification object:nil]; |
1482 | | - } |
| 1480 | + [NSNotificationCenter.defaultCenter removeObserver:self name:UIKeyboardWillShowNotification object:nil]; |
| 1481 | + [NSNotificationCenter.defaultCenter removeObserver:self name:UIKeyboardWillHideNotification object:nil]; |
1483 | 1482 | } |
1484 | 1483 |
|
1485 | 1484 | - (void)keyboardWillShowNotification:(NSNotification *)notification |
|
0 commit comments