Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions Libraries/CameraRoll/CameraRoll.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ var getPhotosParamChecker = createStrictShapeTypeChecker({
* titles.
*/
groupName: ReactPropTypes.string,

/**
* Specifies filter on asset type, like 'all', 'photos' or 'videos'
*/
assetType: ReactPropTypes.string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make it ReactPropTypes.oneOf(['all', 'photos', 'videos']) instead of writing it in the comments. The comment can say that all is the default

});

/**
Expand Down
14 changes: 12 additions & 2 deletions Libraries/Image/RCTCameraRollManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ - (void)getPhotos:(NSDictionary *)params callback:(RCTResponseSenderBlock)callba
NSString *afterCursor = params[@"after"];
NSString *groupTypesStr = params[@"groupTypes"];
NSString *groupName = params[@"groupName"];
NSString *assetType = params[@"assetType"];
ALAssetsGroupType groupTypes;

if ([groupTypesStr isEqualToString:@"Album"]) {
groupTypes = ALAssetsGroupAlbum;
} else if ([groupTypesStr isEqualToString:@"All"]) {
Expand All @@ -83,15 +85,23 @@ - (void)getPhotos:(NSDictionary *)params callback:(RCTResponseSenderBlock)callba
} else {
groupTypes = ALAssetsGroupSavedPhotos;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to remove the trailing whitespace.

BOOL __block foundAfter = NO;
BOOL __block hasNextPage = NO;
BOOL __block calledCallback = NO;
NSMutableArray *assets = [[NSMutableArray alloc] init];

[[RCTImageLoader assetsLibrary] enumerateGroupsWithTypes:groupTypes usingBlock:^(ALAssetsGroup *group, BOOL *stopGroups) {
if (group && (groupName == nil || [groupName isEqualToString:[group valueForProperty:ALAssetsGroupPropertyName]])) {
[group setAssetsFilter:ALAssetsFilter.allPhotos];

if (assetType == nil || [assetType isEqualToString:@"all"]) {
[group setAssetsFilter:ALAssetsFilter.allAssets];
} else if ([assetType isEqualToString:@"photos"]) {
[group setAssetsFilter:ALAssetsFilter.allPhotos];
} else if ([assetType isEqualToString:@"videos"]) {
[group setAssetsFilter:ALAssetsFilter.allVideos];
}

[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stopAssets) {
if (result) {
NSString *uri = [(NSURL *)[result valueForProperty:ALAssetPropertyAssetURL] absoluteString];
Expand Down