diff --git a/Examples/UIExplorer/CameraRollView.ios.js b/Examples/UIExplorer/CameraRollView.ios.js index 87dd23e6d..74507aa2c 100644 --- a/Examples/UIExplorer/CameraRollView.ios.js +++ b/Examples/UIExplorer/CameraRollView.ios.js @@ -59,6 +59,16 @@ var propTypes = { * imagesPerRow: Number of images to be shown in each row. */ imagesPerRow: React.PropTypes.number, + + /** + * The asset type, one of 'Photos', 'Videos' or 'All' + */ + assetType: React.PropTypes.oneOf([ + 'Photos', + 'Videos', + 'All', + ]), + }; var CameraRollView = React.createClass({ @@ -69,6 +79,7 @@ var CameraRollView = React.createClass({ groupTypes: 'SavedPhotos', batchSize: 5, imagesPerRow: 1, + assetType: 'Photos', renderImage: function(asset) { var imageSize = 150; var imageStyle = [styles.image, {width: imageSize, height: imageSize}]; @@ -89,6 +100,7 @@ var CameraRollView = React.createClass({ assets: ([]: Array), groupTypes: this.props.groupTypes, lastCursor: (null : ?string), + assetType: this.props.assetType, noMore: false, loadingMore: false, dataSource: ds, @@ -124,7 +136,8 @@ var CameraRollView = React.createClass({ var fetchParams: Object = { first: this.props.batchSize, - groupTypes: this.props.groupTypes + groupTypes: this.props.groupTypes, + assetType: this.props.assetType, }; if (this.state.lastCursor) { fetchParams.after = this.state.lastCursor; diff --git a/Libraries/CameraRoll/CameraRoll.js b/Libraries/CameraRoll/CameraRoll.js index 0d008ae75..67fa50830 100644 --- a/Libraries/CameraRoll/CameraRoll.js +++ b/Libraries/CameraRoll/CameraRoll.js @@ -29,8 +29,16 @@ var GROUP_TYPES_OPTIONS = [ 'SavedPhotos', // default ]; +var ASSET_TYPE_OPTIONS = [ + 'All', + 'Videos', + 'Photos', // default +]; + + // Flow treats Object and Array as disjoint types, currently. deepFreezeAndThrowOnMutationInDev((GROUP_TYPES_OPTIONS: any)); +deepFreezeAndThrowOnMutationInDev((ASSET_TYPE_OPTIONS: any)); /** * Shape of the param arg for the `getPhotos` function. @@ -58,6 +66,11 @@ var getPhotosParamChecker = createStrictShapeTypeChecker({ * titles. */ groupName: ReactPropTypes.string, + + /** + * Specifies filter on asset type + */ + assetType: ReactPropTypes.oneOf(ASSET_TYPE_OPTIONS), }); /** @@ -94,6 +107,7 @@ var getPhotosReturnChecker = createStrictShapeTypeChecker({ class CameraRoll { static GroupTypesOptions: Array; + static AssetTypeOptions: Array; /** * Saves the image with tag `tag` to the camera roll. * @@ -154,5 +168,6 @@ class CameraRoll { } CameraRoll.GroupTypesOptions = GROUP_TYPES_OPTIONS; +CameraRoll.AssetTypeOptions = ASSET_TYPE_OPTIONS; module.exports = CameraRoll; diff --git a/Libraries/Image/RCTCameraRollManager.m b/Libraries/Image/RCTCameraRollManager.m index 8e6c8a532..d7b42f885 100644 --- a/Libraries/Image/RCTCameraRollManager.m +++ b/Libraries/Image/RCTCameraRollManager.m @@ -69,7 +69,9 @@ RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params 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"]) { @@ -93,7 +95,15 @@ RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params [[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:@"Photos"]) { + [group setAssetsFilter:ALAssetsFilter.allPhotos]; + } else if ([assetType isEqualToString:@"Videos"]) { + [group setAssetsFilter:ALAssetsFilter.allVideos]; + } else if ([assetType isEqualToString:@"All"]) { + [group setAssetsFilter:ALAssetsFilter.allAssets]; + } + [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stopAssets) { if (result) { NSString *uri = [(NSURL *)[result valueForProperty:ALAssetPropertyAssetURL] absoluteString];