mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 09:45:04 +00:00
Allow RCTPhotoLibraryImageLoader to handle assets-library request
Reviewed By: javache Differential Revision: D3503380 fbshipit-source-id: 8f8eb545343738906e44ee01aa4ba23755a209c7
This commit is contained in:
parent
dc3fce06ea
commit
98f06c8876
@ -24,7 +24,11 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
- (BOOL)canLoadImageURL:(NSURL *)requestURL
|
||||
{
|
||||
return [requestURL.scheme caseInsensitiveCompare:@"ph"] == NSOrderedSame;
|
||||
if (![PHAsset class]) {
|
||||
return NO;
|
||||
}
|
||||
return [requestURL.scheme caseInsensitiveCompare:@"assets-library"] == NSOrderedSame ||
|
||||
[requestURL.scheme caseInsensitiveCompare:@"ph"] == NSOrderedSame;
|
||||
}
|
||||
|
||||
- (RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
|
||||
@ -38,10 +42,17 @@ RCT_EXPORT_MODULE()
|
||||
// The 'ph://' prefix is used by FBMediaKit to differentiate between
|
||||
// assets-library. It is prepended to the local ID so that it is in the
|
||||
// form of an, NSURL which is what assets-library uses.
|
||||
NSString *phAssetID = [imageURL.absoluteString substringFromIndex:@"ph://".length];
|
||||
PHFetchResult *results = [PHAsset fetchAssetsWithLocalIdentifiers:@[phAssetID] options:nil];
|
||||
NSString *assetID = @"";
|
||||
PHFetchResult *results;
|
||||
if ([imageURL.scheme caseInsensitiveCompare:@"assets-library"] == NSOrderedSame) {
|
||||
assetID = [imageURL absoluteString];
|
||||
results = [PHAsset fetchAssetsWithALAssetURLs:@[imageURL] options:nil];
|
||||
} else {
|
||||
assetID = [imageURL.absoluteString substringFromIndex:@"ph://".length];
|
||||
results = [PHAsset fetchAssetsWithLocalIdentifiers:@[assetID] options:nil];
|
||||
}
|
||||
if (results.count == 0) {
|
||||
NSString *errorText = [NSString stringWithFormat:@"Failed to fetch PHAsset with local identifier %@ with no error message.", phAssetID];
|
||||
NSString *errorText = [NSString stringWithFormat:@"Failed to fetch PHAsset with local identifier %@ with no error message.", assetID];
|
||||
completionHandler(RCTErrorWithMessage(errorText), nil);
|
||||
return ^{};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user