Skip to content

Commit

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

* Removes extraneous sortOrder access
  • Loading branch information
migue1s authored and L-Yeiser committed Aug 1, 2019
1 parent 2f6ccb0 commit 0c6bc74
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 @@ -138,6 +138,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?: string;
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 @@ -242,6 +242,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 @@ -316,6 +317,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 @@ -607,7 +609,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 0c6bc74

Please sign in to comment.