Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Revert "Revert "Adds a sortOrder flag to sort by creation date on iOS (
Browse files Browse the repository at this point in the history
…ivpusic#1090)""

This reverts commit bc72e5b.
  • Loading branch information
vlatri committed Jan 15, 2020
1 parent 9a5dedf commit afe947c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ declare module "react-native-image-crop-picker" {
mediaType?: 'photo' | 'video' | 'any';
showsSelectedCount?: boolean;
forceJpg?: boolean;
sortOrder?: 'none' | 'asc' | 'desc';
showCropGuidelines?: boolean;
hideBottomControls?: boolean;
enableRotationGesture?: boolean;
Expand Down
8 changes: 8 additions & 0 deletions ios/QBImagePicker/QBImagePicker/QBAssetsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
1 change: 1 addition & 0 deletions ios/QBImagePicker/QBImagePicker/QBImagePickerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion ios/src/ImageCropPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ - (instancetype)init
@"mediaType": @"any",
@"showsSelectedCount": @YES,
@"forceJpg": @NO,
@"sortOrder": @"none",
@"cropperCancelText": @"Cancel",
@"cropperChooseText": @"Choose"
};
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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"];
Expand Down

0 comments on commit afe947c

Please sign in to comment.