Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Libraries/Image/RCTImageLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@
+ (void)loadImageWithTag:(NSString *)tag
callback:(void (^)(NSError *error, id /* UIImage or CAAnimation */ image))callback;

+ (BOOL)isSystemImageURI:(NSString *)uri;

@end
7 changes: 7 additions & 0 deletions Libraries/Image/RCTImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,11 @@ + (void)loadImageWithTag:(NSString *)imageTag callback:(void (^)(NSError *error,
}
}

+ (BOOL)isSystemImageURI:(NSString *)uri
{
return uri != nil && (
[uri hasPrefix:@"assets-library"] ||
[uri hasPrefix:@"ph://"]);
}

@end
43 changes: 37 additions & 6 deletions Libraries/Network/RCTDataManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "RCTConvert.h"
#import "RCTLog.h"
#import "RCTUtils.h"
#import "RCTImageLoader.h"

@implementation RCTDataManager

Expand All @@ -34,8 +35,43 @@ @implementation RCTDataManager
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
request.HTTPMethod = [RCTConvert NSString:query[@"method"]] ?: @"GET";
request.allHTTPHeaderFields = [RCTConvert NSDictionary:query[@"headers"]];
request.HTTPBody = [RCTConvert NSData:query[@"data"]];

if (query[@"data"] != [NSNull null]) {
NSDictionary *data = [RCTConvert NSDictionary:query[@"data"]];
NSData *body = [RCTConvert NSData:data[@"string"]];
if (body != nil) {
request.HTTPBody = body;
[RCTDataManager sendRequest:request responseSender:responseSender];
return;
}
NSString *uri = [RCTConvert NSString:data[@"uri"]];
if (uri != nil) {
if ([RCTImageLoader isSystemImageURI:uri]) {
[RCTImageLoader loadImageWithTag:(NSString *)uri callback:^(NSError *error, UIImage *image) {
if (error) {
RCTLogError(@"Error loading image URI: %@", error);
// We should really circle back to JS here and notify an error/abort on the request.
return;
}
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
request.HTTPBody = imageData;
[RCTDataManager sendRequest:request responseSender:responseSender];
}];
} else {
RCTLogError(@"Cannot resolve URI: %@", uri);
}
return;
}
}

// There was no data payload, or we couldn't understand it.
[RCTDataManager sendRequest:request responseSender:responseSender];
} else {
RCTLogError(@"unsupported query type %@", queryType);
}
}

+ (void)sendRequest:(NSURLRequest *)request responseSender:(RCTResponseSenderBlock)responseSender {
// Build data task
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *connectionError) {

Expand Down Expand Up @@ -71,11 +107,6 @@ @implementation RCTDataManager
}];

[task resume];

} else {

RCTLogError(@"unsupported query type %@", queryType);
}
}

@end
2 changes: 2 additions & 0 deletions Libraries/Network/RCTNetwork.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../React/**",
"$(SRCROOT)/../Image/**",
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
Expand All @@ -226,6 +227,7 @@
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../React/**",
"$(SRCROOT)/../Image/**",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also what's going on with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we need to add Libraries/Image/ to the header search path so we can #import "RCTImageLoader.h"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make sure it also works with our buck rules inside of fb

);
LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
Expand Down
11 changes: 7 additions & 4 deletions Libraries/Network/XMLHttpRequest.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ var XMLHttpRequestBase = require('XMLHttpRequestBase');
class XMLHttpRequest extends XMLHttpRequestBase {

sendImpl(method: ?string, url: ?string, headers: Object, data: any): void {
if (typeof data === 'string') {
data = {string: data};
}
RCTDataManager.queryData(
'http',
{
method: method,
url: url,
data: data,
headers: headers,
method,
url,
data,
headers,
},
// TODO: Do we need this? is it used anywhere?
'h' + crc32(method + '|' + url + '|' + data),
Expand Down