react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Image] RTCImageLoader can not support custom URL schema

Open rqwj opened this issue 11 years ago • 5 comments

It seems that RTCImageLoader can only support 'assets-library', 'ph' and 'http' as the URL schema. I want to use a custom schema such as 'myimagelib' to activate my own NSURLProtocol to do something with the data before it is returned.

below is my solution, add some codes to RCTImageLoader

static NSMutableSet *schemaSet;

  • (void)registerCustomSchema:(NSString*)schema { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ schemaSet = [[NSMutableSet alloc] init]; });

    [schemaSet addObject:schema]; }

  • (BOOL)isSchemaRegistered:(NSString*)imageTag { for (NSString *schema in schemaSet) { if ([imageTag hasPrefix:schema]) { return YES; } } return NO; }

  • (void)loadImageWithTag:(NSString *)imageTag callback:(void (^)(NSError *error, id image))callback { .... } else if ([imageTag hasPrefix:@"http"] || [self isSchemaRegistered:imageTag]) { NSURL *url = [NSURL URLWithString:imageTag]; .... }

rqwj avatar Jul 08 '15 16:07 rqwj

I'm mid-way through refactoring the network layer to support this, but it's not quite there yet I'm afraid.

We do now support custom protocol handlers for HTTPRequests via the RCTURLRequestHandler protocol, but the RCTImageLoader doesn't use that system yet.

nicklockwood avatar Jul 09 '15 15:07 nicklockwood

I see. I will use a tricky scheme like "http-xxx://" as the solution temporarily.

your baby is so cute : )

rqwj avatar Jul 14 '15 03:07 rqwj

@ide @brentvatne this seems old enough that this is likely landed by now.

browniefed avatar Sep 13 '15 20:09 browniefed

Yeah, RCTImageLoader now supports arbitrary protocols and image formats via a plugin system.

nicklockwood avatar Sep 13 '15 20:09 nicklockwood

I'm trying to support a bespoke url scheme. Is it possible now? Is there any documentation?

npomfret avatar May 08 '17 14:05 npomfret