From 442dd268733cc1a3ff899f89b7ac2d2e9d5c93b2 Mon Sep 17 00:00:00 2001 From: Peter Argany Date: Mon, 13 Jan 2020 22:52:07 -0800 Subject: [PATCH] Fix error in RCTImageLoader in bridgeless mode Summary: Bridgeless mode hasn't been able to load random images. I was able to repro this 100% with base64 images. Loading these images hits a particular flow in `RCTImageLoader` which relies on the bridge to access `RCTNetworking`. This diff uses the TM Lookup Delegate as a fallback. Changelog: [iOS][Internal] Fix error in RCTImageLoader in bridgeless mode Reviewed By: sammy-SC Differential Revision: D19331467 fbshipit-source-id: 8239ee258425da4ed8cb9f6dcdcd7f37c162eb19 --- Libraries/Image/RCTImageLoader.mm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Libraries/Image/RCTImageLoader.mm b/Libraries/Image/RCTImageLoader.mm index efa84842206..fd436da4285 100644 --- a/Libraries/Image/RCTImageLoader.mm +++ b/Libraries/Image/RCTImageLoader.mm @@ -99,6 +99,7 @@ static uint64_t monotonicTimeGetCurrentNanoseconds(void) @synthesize maxConcurrentLoadingTasks = _maxConcurrentLoadingTasks; @synthesize maxConcurrentDecodingTasks = _maxConcurrentDecodingTasks; @synthesize maxConcurrentDecodingBytes = _maxConcurrentDecodingBytes; +@synthesize turboModuleLookupDelegate = _turboModuleLookupDelegate; RCT_EXPORT_MODULE() @@ -583,7 +584,8 @@ static UIImage *RCTResizeImageIfNeeded(UIImage *image, completionBlock:(void (^)(NSError *error, id imageOrData, NSURLResponse *response))completionHandler { // Check if networking module is available - if (RCT_DEBUG && ![_bridge respondsToSelector:@selector(networking)]) { + if (RCT_DEBUG && ![_bridge respondsToSelector:@selector(networking)] + && ![_turboModuleLookupDelegate moduleForName:"RCTNetworking"]) { RCTLogError(@"No suitable image URL loader found for %@. You may need to " " import the RCTNetwork library in order to load images.", request.URL.absoluteString); @@ -591,6 +593,9 @@ static UIImage *RCTResizeImageIfNeeded(UIImage *image, } RCTNetworking *networking = [_bridge networking]; + if (!networking) { + networking = [_turboModuleLookupDelegate moduleForName:"RCTNetworking"]; + } // Check if networking module can load image if (RCT_DEBUG && ![networking canHandleRequest:request]) {