mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-28 12:15:37 +08:00
Ported source prop over to iOS WebView
Summary: public https://github.com/facebook/react-native/pull/5494 added a new `source` property to WebView on Android that provides a better API, as well as allowing for request headers to be set. This diff ports that functionality over to iOS, so we can have a consistent API cross-platform. I've also extended the API to include `method` (GET or POST) and `body` when setting the WebView content with a URI, and `baseUrl` when setting static HTML. Reviewed By: javache Differential Revision: D2884643 fb-gh-sync-id: 83f24494bdbb4e1408aa8f3b7428fee33888ae3a
This commit is contained in:
committed by
facebook-github-bot-1
parent
5ec1d354c2
commit
46106f756a
@@ -118,8 +118,31 @@ RCT_CUSTOM_CONVERTER(NSData *, NSData, [json dataUsingEncoding:NSUTF8StringEncod
|
||||
|
||||
+ (NSURLRequest *)NSURLRequest:(id)json
|
||||
{
|
||||
NSURL *URL = [self NSURL:json];
|
||||
return URL ? [NSURLRequest requestWithURL:URL] : nil;
|
||||
if ([json isKindOfClass:[NSString class]]) {
|
||||
NSURL *URL = [self NSURL:json];
|
||||
return URL ? [NSURLRequest requestWithURL:URL] : nil;
|
||||
}
|
||||
if ([json isKindOfClass:[NSDictionary class]]) {
|
||||
NSURL *URL = [self NSURL:json[@"uri"] ?: json[@"url"]];
|
||||
if (!URL) {
|
||||
return nil;
|
||||
}
|
||||
NSData *body = [self NSData:json[@"body"]];
|
||||
NSString *method = [self NSString:json[@"method"]].uppercaseString ?: @"GET";
|
||||
NSDictionary *headers = [self NSDictionary:json[@"headers"]];
|
||||
if ([method isEqualToString:@"GET"] && headers == nil && body == nil) {
|
||||
return [NSURLRequest requestWithURL:URL];
|
||||
}
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
|
||||
request.HTTPBody = body;
|
||||
request.HTTPMethod = method;
|
||||
request.allHTTPHeaderFields = headers;
|
||||
return [request copy];
|
||||
}
|
||||
if (json) {
|
||||
RCTLogConvertError(json, @"a valid URLRequest");
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (RCTFileURL *)RCTFileURL:(id)json
|
||||
|
||||
Reference in New Issue
Block a user