From 81c289a9cde3e6f8d401d948843a274c85a56b85 Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Sat, 14 Nov 2015 10:25:00 -0800 Subject: [PATCH] Replaced RCTSparseArray with NSDictionary Reviewed By: jspahrsummers Differential Revision: D2651920 fb-gh-sync-id: 953e2ea33abfc7a3a553da95b13e9ab2bccc5a1c --- RCTCameraRollManager.m | 77 +++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/RCTCameraRollManager.m b/RCTCameraRollManager.m index e2044f03c..b1c285186 100644 --- a/RCTCameraRollManager.m +++ b/RCTCameraRollManager.m @@ -46,7 +46,7 @@ RCT_ENUM_CONVERTER(ALAssetsGroupType, (@{ + (ALAssetsFilter *)ALAssetsFilter:(id)json { - static NSDictionary *options; + static NSDictionary *options; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ options = @{ @@ -102,29 +102,31 @@ RCT_EXPORT_METHOD(saveImageWithTag:(NSString *)imageTag }]; } -- (void)callCallback:(RCTResponseSenderBlock)callback - withAssets:(NSArray *)assets - hasNextPage:(BOOL)hasNextPage +static void RCTCallCallback(RCTResponseSenderBlock callback, + NSArray *> *assets, + BOOL hasNextPage) { if (!assets.count) { callback(@[@{ - @"edges": assets, - @"page_info": @{ - @"has_next_page": @NO} - }]); + @"edges": assets, + @"page_info": @{ + @"has_next_page": @NO, + } + }]); return; } callback(@[@{ - @"edges": assets, - @"page_info": @{ - @"start_cursor": assets[0][@"node"][@"image"][@"uri"], - @"end_cursor": assets[assets.count - 1][@"node"][@"image"][@"uri"], - @"has_next_page": @(hasNextPage)} - }]); + @"edges": assets, + @"page_info": @{ + @"start_cursor": assets[0][@"node"][@"image"][@"uri"], + @"end_cursor": assets[assets.count - 1][@"node"][@"image"][@"uri"], + @"has_next_page": @(hasNextPage), + } + }]); } RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params - callback:(RCTResponseSenderBlock)callback + successCallback:(RCTResponseSenderBlock)successCallback errorCallback:(RCTResponseErrorBlock)errorCallback) { NSUInteger first = [RCTConvert NSInteger:params[@"first"]]; @@ -136,7 +138,7 @@ RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params BOOL __block foundAfter = NO; BOOL __block hasNextPage = NO; BOOL __block calledCallback = NO; - NSMutableArray *assets = [NSMutableArray new]; + NSMutableArray *> *assets = [NSMutableArray new]; [_bridge.assetsLibrary enumerateGroupsWithTypes:groupTypes usingBlock:^(ALAssetsGroup *group, BOOL *stopGroups) { if (group && (groupName == nil || [groupName isEqualToString:[group valueForProperty:ALAssetsGroupPropertyName]])) { @@ -156,7 +158,7 @@ RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params *stopGroups = YES; hasNextPage = YES; RCTAssert(calledCallback == NO, @"Called the callback before we finished processing the results."); - [self callCallback:callback withAssets:assets hasNextPage:hasNextPage]; + RCTCallCallback(successCallback, assets, hasNextPage); calledCallback = YES; return; } @@ -164,33 +166,32 @@ RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params CLLocation *loc = [result valueForProperty:ALAssetPropertyLocation]; NSDate *date = [result valueForProperty:ALAssetPropertyDate]; [assets addObject:@{ - @"node": @{ - @"type": [result valueForProperty:ALAssetPropertyType], - @"group_name": [group valueForProperty:ALAssetsGroupPropertyName], - @"image": @{ - @"uri": uri, - @"height": @(dimensions.height), - @"width": @(dimensions.width), - @"isStored": @YES, - }, - @"timestamp": @(date.timeIntervalSince1970), - @"location": loc ? - @{ - @"latitude": @(loc.coordinate.latitude), - @"longitude": @(loc.coordinate.longitude), - @"altitude": @(loc.altitude), - @"heading": @(loc.course), - @"speed": @(loc.speed), - } : @{}, - } - }]; + @"node": @{ + @"type": [result valueForProperty:ALAssetPropertyType], + @"group_name": [group valueForProperty:ALAssetsGroupPropertyName], + @"image": @{ + @"uri": uri, + @"height": @(dimensions.height), + @"width": @(dimensions.width), + @"isStored": @YES, + }, + @"timestamp": @(date.timeIntervalSince1970), + @"location": loc ? @{ + @"latitude": @(loc.coordinate.latitude), + @"longitude": @(loc.coordinate.longitude), + @"altitude": @(loc.altitude), + @"heading": @(loc.course), + @"speed": @(loc.speed), + } : @{}, + } + }]; } }]; } else { // Sometimes the enumeration continues even if we set stop above, so we guard against calling the callback // multiple times here. if (!calledCallback) { - [self callCallback:callback withAssets:assets hasNextPage:hasNextPage]; + RCTCallCallback(successCallback, assets, hasNextPage); calledCallback = YES; } }