Fix: Set image loader module name synchronously

Summary: Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24290066

fbshipit-source-id: e2bad9ed8c126c7b49356bc7a2c1114160149fd3
This commit is contained in:
Paige Sun 2020-10-14 11:23:04 -07:00 коммит произвёл Facebook GitHub Bot
Родитель cd6ebcdd82
Коммит 38eb3f8dcb
1 изменённых файлов: 7 добавлений и 8 удалений

Просмотреть файл

@ -49,6 +49,13 @@ using namespace facebook::react;
auto sharedCancelationFunction = SharedFunction<>(); auto sharedCancelationFunction = SharedFunction<>();
imageRequest.setCancelationFunction(sharedCancelationFunction); imageRequest.setCancelationFunction(sharedCancelationFunction);
NSURLRequest *request = NSURLRequestFromImageSource(imageSource);
BOOL hasModuleName = [self->_imageLoader respondsToSelector:@selector(loaderModuleNameForRequestUrl:)];
NSString *moduleName = hasModuleName ? [self->_imageLoader loaderModuleNameForRequestUrl:request.URL] : nil;
std::string moduleCString =
std::string([moduleName UTF8String], [moduleName lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
telemetry->setLoaderModuleName(moduleCString);
/* /*
* Even if an image is being loaded asynchronously on some other background thread, some other preparation * Even if an image is being loaded asynchronously on some other background thread, some other preparation
* work (such as creating an `NSURLRequest` object and some obscure logic inside `RCTImageLoader`) can take a couple * work (such as creating an `NSURLRequest` object and some obscure logic inside `RCTImageLoader`) can take a couple
@ -60,14 +67,6 @@ using namespace facebook::react;
* T46024425 for more details. * T46024425 for more details.
*/ */
dispatch_async(_backgroundSerialQueue, ^{ dispatch_async(_backgroundSerialQueue, ^{
NSURLRequest *request = NSURLRequestFromImageSource(imageSource);
BOOL hasModuleName = [self->_imageLoader respondsToSelector:@selector(loaderModuleNameForRequestUrl:)];
NSString *moduleName = hasModuleName ? [self->_imageLoader loaderModuleNameForRequestUrl:request.URL] : nil;
std::string moduleCString =
std::string([moduleName UTF8String], [moduleName lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
telemetry->setLoaderModuleName(moduleCString);
auto completionBlock = ^(NSError *error, UIImage *image, id metadata) { auto completionBlock = ^(NSError *error, UIImage *image, id metadata) {
auto observerCoordinator = weakObserverCoordinator.lock(); auto observerCoordinator = weakObserverCoordinator.lock();
if (!observerCoordinator) { if (!observerCoordinator) {