From 2e24ffef369451c7c98fcaa37a6aa7e46b4e5058 Mon Sep 17 00:00:00 2001 From: vlatri Date: Wed, 15 Jan 2020 12:55:33 +0200 Subject: [PATCH] Revert "Revert "Adds a sortOrder flag to sort by creation date on iOS (#1090)"" This reverts commit bc72e5b366b73891c601096fedc8aab16e5fcfb4. --- README.md | 1 + index.d.ts | 1 + ios/QBImagePicker/QBImagePicker/QBAssetsViewController.m | 8 ++++++++ ios/QBImagePicker/QBImagePicker/QBImagePickerController.h | 1 + ios/src/ImageCropPicker.m | 4 +++- 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c42512d3..885e5c79f 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ ImagePicker.clean().then(() => { | mediaType | string (default any) | Accepted mediaType for image selection, can be one of: 'photo', 'video', or 'any' | | showsSelectedCount (ios only) | bool (default true) | Whether to show the number of selected assets | | forceJpg (ios only) | bool (default false) | Whether to convert photos to JPG. This will also convert any Live Photo into its JPG representation | +| sortOrder (ios only) | string (default 'none', supported values: 'asc', 'desc', 'none') | Applies a sort order on the creation date on how media is displayed within the albums/detail photo views when opening the image picker | | showCropGuidelines (android only) | bool (default true) | Whether to show the 3x3 grid on top of the image during cropping | | showCropFrame (android only) | bool (default true) | Whether to show crop frame during cropping | | hideBottomControls (android only) | bool (default false) | Whether to display bottom controls | diff --git a/index.d.ts b/index.d.ts index 0d7e72b99..9d220d198 100644 --- a/index.d.ts +++ b/index.d.ts @@ -28,6 +28,7 @@ declare module "react-native-image-crop-picker" { mediaType?: string; showsSelectedCount?: boolean; forceJpg?: boolean; + sortOrder?: 'none' | 'asc' | 'desc'; showCropGuidelines?: boolean; hideBottomControls?: boolean; enableRotationGesture?: boolean; diff --git a/ios/QBImagePicker/QBImagePicker/QBAssetsViewController.m b/ios/QBImagePicker/QBImagePicker/QBAssetsViewController.m index fef0e126a..bb4cd6224 100644 --- a/ios/QBImagePicker/QBImagePicker/QBAssetsViewController.m +++ b/ios/QBImagePicker/QBImagePicker/QBAssetsViewController.m @@ -246,6 +246,14 @@ - (void)updateFetchRequest default: break; } + + if ([self.imagePickerController.sortOrder isEqualToString:@"asc"]) { + options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending: YES]]; + } + + if ([self.imagePickerController.sortOrder isEqualToString:@"desc"]) { + options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending: NO]]; + } self.fetchResult = [PHAsset fetchAssetsInAssetCollection:self.assetCollection options:options]; diff --git a/ios/QBImagePicker/QBImagePicker/QBImagePickerController.h b/ios/QBImagePicker/QBImagePicker/QBImagePickerController.h index e7547e597..6289eef8d 100644 --- a/ios/QBImagePicker/QBImagePicker/QBImagePickerController.h +++ b/ios/QBImagePicker/QBImagePicker/QBImagePickerController.h @@ -41,6 +41,7 @@ typedef NS_ENUM(NSUInteger, QBImagePickerMediaType) { @property (nonatomic, assign) BOOL allowsMultipleSelection; @property (nonatomic, assign) NSUInteger minimumNumberOfSelection; @property (nonatomic, assign) NSUInteger maximumNumberOfSelection; +@property (nonatomic, strong) NSString* sortOrder; @property (nonatomic, copy) NSString *prompt; @property (nonatomic, assign) BOOL showsNumberOfSelectedAssets; diff --git a/ios/src/ImageCropPicker.m b/ios/src/ImageCropPicker.m index e14fdb035..d91f6d178 100644 --- a/ios/src/ImageCropPicker.m +++ b/ios/src/ImageCropPicker.m @@ -91,6 +91,7 @@ - (instancetype)init @"mediaType": @"any", @"showsSelectedCount": @YES, @"forceJpg": @NO, + @"sortOrder": @"none", @"cropperCancelText": @"Cancel", @"cropperChooseText": @"Choose" }; @@ -319,6 +320,7 @@ - (BOOL)cleanTmpDirectory { imagePickerController.minimumNumberOfSelection = abs([[self.options objectForKey:@"minFiles"] intValue]); imagePickerController.maximumNumberOfSelection = abs([[self.options objectForKey:@"maxFiles"] intValue]); imagePickerController.showsNumberOfSelectedAssets = [[self.options objectForKey:@"showsSelectedCount"] boolValue]; + imagePickerController.sortOrder = [self.options objectForKey:@"sortOrder"]; NSArray *smartAlbums = [self.options objectForKey:@"smartAlbums"]; if (smartAlbums != nil) { @@ -611,7 +613,7 @@ - (void)qb_imagePickerController: [lock lock]; @autoreleasepool { UIImage *imgT = [UIImage imageWithData:imageData]; - + Boolean forceJpg = [[self.options valueForKey:@"forceJpg"] boolValue]; NSNumber *compressQuality = [self.options valueForKey:@"compressImageQuality"];