mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-26 13:25:51 +08:00
[Image] Add examples to UIExplorer, fix some bugs
Summary: Add two simple examples.  Also: - do not start the task at DownloadTaskWrapper (it starts from ImageDowloader if image isn't cached yet); - fire `onLoadAbor`t event; - send more readable `error.localizedDescription` with `onLoadError`; - rename `onLoaded` to `onLoadEnd` Closes https://github.com/facebook/react-native/pull/1987 Github Author: Dmitriy Loktev <unknownliveid@hotmail.com>
This commit is contained in:
@@ -66,7 +66,6 @@ static void *const RCTDownloadTaskWrapperProgressBlockKey = (void *)&RCTDownload
|
||||
task.rct_completionBlock = completionBlock;
|
||||
task.rct_progressBlock = progressBlock;
|
||||
|
||||
[task resume];
|
||||
return task;
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ CGRect RCTClipRect(CGSize, CGFloat, CGSize, CGFloat, UIViewContentMode);
|
||||
runBlocks(NO, response, data, error);
|
||||
}
|
||||
|
||||
if (response) {
|
||||
if (response && !error) {
|
||||
RCTImageDownloader *strongSelf = weakSelf;
|
||||
NSCachedURLResponse *cachedResponse = [[NSCachedURLResponse alloc] initWithResponse:response data:data userInfo:nil storagePolicy:NSURLCacheStorageAllowed];
|
||||
[strongSelf->_cache storeCachedResponse:cachedResponse forRequest:request];
|
||||
|
||||
@@ -86,6 +86,8 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
|
||||
{
|
||||
if (![_imageURL isEqual:imageURL] && _downloadToken) {
|
||||
[_imageDownloader cancelDownload:_downloadToken];
|
||||
NSDictionary *event = @{ @"target": self.reactTag };
|
||||
[_eventDispatcher sendInputEventWithName:@"loadAbort" body:event];
|
||||
_downloadToken = nil;
|
||||
}
|
||||
|
||||
@@ -146,7 +148,7 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
|
||||
loadEndHandler();
|
||||
});
|
||||
} else if (error) {
|
||||
errorHandler([error description]);
|
||||
errorHandler([error localizedDescription]);
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
@@ -170,7 +172,7 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
|
||||
loadEndHandler();
|
||||
});
|
||||
} else if (error) {
|
||||
errorHandler([error description]);
|
||||
errorHandler([error localizedDescription]);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ RCT_CUSTOM_VIEW_PROPERTY(tintColor, UIColor, RCTNetworkImageView)
|
||||
return @{
|
||||
@"loadStart": @{ @"registrationName": @"onLoadStart" },
|
||||
@"loadProgress": @{ @"registrationName": @"onLoadProgress" },
|
||||
@"loaded": @{ @"registrationName": @"onLoaded" },
|
||||
@"loaded": @{ @"registrationName": @"onLoadEnd" },
|
||||
@"loadError": @{ @"registrationName": @"onLoadError" },
|
||||
@"loadAbort": @{ @"registrationName": @"onLoadAbort" },
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user