mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Make RCTNetworking TurboModule-compatible
Summary: See title. Changelog: [iOS][Added] - Make RCTNetworking TurboModule-compatible Reviewed By: PeteTheHeat Differential Revision: D18087243 fbshipit-source-id: 81bbf77d603e96fa94ad219e5ed68f42bb7e7dc5
This commit is contained in:
committed by
Facebook Github Bot
parent
1d315608ef
commit
ffb8191a51
@@ -1813,7 +1813,7 @@ namespace JS {
|
||||
NSString *url() const;
|
||||
id<NSObject> data() const;
|
||||
id<NSObject> headers() const;
|
||||
id<NSObject> responseType() const;
|
||||
NSString *responseType() const;
|
||||
bool incrementalUpdates() const;
|
||||
double timeout() const;
|
||||
bool withCredentials() const;
|
||||
@@ -3490,10 +3490,10 @@ inline id<NSObject> JS::NativeNetworkingIOS::SpecSendRequestQuery::headers() con
|
||||
id const p = _v[@"headers"];
|
||||
return p;
|
||||
}
|
||||
inline id<NSObject> JS::NativeNetworkingIOS::SpecSendRequestQuery::responseType() const
|
||||
inline NSString *JS::NativeNetworkingIOS::SpecSendRequestQuery::responseType() const
|
||||
{
|
||||
id const p = _v[@"responseType"];
|
||||
return p;
|
||||
return RCTBridgingToString(p);
|
||||
}
|
||||
inline bool JS::NativeNetworkingIOS::SpecSendRequestQuery::incrementalUpdates() const
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ export interface Spec extends TurboModule {
|
||||
url: string,
|
||||
data: Object,
|
||||
headers: Object,
|
||||
responseType: Object, // TODO: Use stricter type.
|
||||
responseType: string,
|
||||
incrementalUpdates: boolean,
|
||||
timeout: number,
|
||||
withCredentials: boolean,
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated by an internal plugin build system
|
||||
*/
|
||||
|
||||
#ifdef RN_DISABLE_OSS_PLUGIN_HEADER
|
||||
|
||||
// FB Internal: FBRCTNetworkPlugins.h is autogenerated by the build system.
|
||||
#import <React/FBRCTNetworkPlugins.h>
|
||||
|
||||
#else
|
||||
|
||||
// OSS-compatibility layer
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wreturn-type-c-linkage"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// RCTTurboModuleManagerDelegate should call this to resolve module classes.
|
||||
Class RCTNetworkClassProvider(const char *name);
|
||||
|
||||
// Lookup functions
|
||||
Class RCTNetworkingCls(void) __attribute__((used));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#endif // RN_DISABLE_OSS_PLUGIN_HEADER
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated by an internal plugin build system
|
||||
*/
|
||||
|
||||
#ifndef RN_DISABLE_OSS_PLUGIN_HEADER
|
||||
|
||||
// OSS-compatibility layer
|
||||
|
||||
#import "RCTNetworkPlugins.h"
|
||||
|
||||
#import <string>
|
||||
#import <unordered_map>
|
||||
|
||||
Class RCTNetworkClassProvider(const char *name) {
|
||||
static std::unordered_map<std::string, Class (*)(void)> sCoreModuleClassMap = {
|
||||
{"Networking", RCTNetworkingCls},
|
||||
};
|
||||
|
||||
auto p = sCoreModuleClassMap.find(name);
|
||||
if (p != sCoreModuleClassMap.end()) {
|
||||
auto classFunc = p->second;
|
||||
return classFunc();
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
#endif // RN_DISABLE_OSS_PLUGIN_HEADER
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#import <mutex>
|
||||
|
||||
#import <FBReactNativeSpec/FBReactNativeSpec.h>
|
||||
#import <React/RCTAssert.h>
|
||||
#import <React/RCTConvert.h>
|
||||
#import <React/RCTEventDispatcher.h>
|
||||
@@ -18,11 +19,13 @@
|
||||
|
||||
#import <React/RCTHTTPRequestHandler.h>
|
||||
|
||||
#import "RCTNetworkPlugins.h"
|
||||
|
||||
typedef RCTURLRequestCancellationBlock (^RCTHTTPQueryResult)(NSError *error, NSDictionary<NSString *, id> *result);
|
||||
|
||||
NSString *const RCTNetworkingPHUploadHackScheme = @"ph-upload";
|
||||
|
||||
@interface RCTNetworking ()
|
||||
@interface RCTNetworking () <NativeNetworkingIOSSpec>
|
||||
|
||||
- (RCTURLRequestCancellationBlock)processDataForHTTPQuery:(NSDictionary<NSString *, id> *)data
|
||||
callback:(RCTHTTPQueryResult)callback;
|
||||
@@ -664,15 +667,26 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
#pragma mark - JS API
|
||||
|
||||
RCT_EXPORT_METHOD(sendRequest:(NSDictionary *)query
|
||||
responseSender:(RCTResponseSenderBlock)responseSender)
|
||||
RCT_EXPORT_METHOD(sendRequest:(JS::NativeNetworkingIOS::SpecSendRequestQuery &)query
|
||||
callback:(RCTResponseSenderBlock)responseSender)
|
||||
{
|
||||
NSDictionary *queryDict = @{
|
||||
@"method": query.method(),
|
||||
@"url": query.url(),
|
||||
@"data": query.data(),
|
||||
@"headers": query.headers(),
|
||||
@"responseType": query.responseType(),
|
||||
@"incrementalUpdates": @(query.incrementalUpdates()),
|
||||
@"timeout": @(query.timeout()),
|
||||
@"withCredentials": @(query.withCredentials()),
|
||||
};
|
||||
|
||||
// TODO: buildRequest returns a cancellation block, but there's currently
|
||||
// no way to invoke it, if, for example the request is cancelled while
|
||||
// loading a large file to build the request body
|
||||
[self buildRequest:query completionBlock:^(NSURLRequest *request) {
|
||||
NSString *responseType = [RCTConvert NSString:query[@"responseType"]];
|
||||
BOOL incrementalUpdates = [RCTConvert BOOL:query[@"incrementalUpdates"]];
|
||||
[self buildRequest:queryDict completionBlock:^(NSURLRequest *request) {
|
||||
NSString *responseType = [RCTConvert NSString:queryDict[@"responseType"]];
|
||||
BOOL incrementalUpdates = [RCTConvert BOOL:queryDict[@"incrementalUpdates"]];
|
||||
[self sendRequest:request
|
||||
responseType:responseType
|
||||
incrementalUpdates:incrementalUpdates
|
||||
@@ -680,10 +694,10 @@ RCT_EXPORT_METHOD(sendRequest:(NSDictionary *)query
|
||||
}];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(abortRequest:(nonnull NSNumber *)requestID)
|
||||
RCT_EXPORT_METHOD(abortRequest:(double)requestID)
|
||||
{
|
||||
[_tasksByRequestID[requestID] cancel];
|
||||
[_tasksByRequestID removeObjectForKey:requestID];
|
||||
[_tasksByRequestID[[NSNumber numberWithDouble:requestID]] cancel];
|
||||
[_tasksByRequestID removeObjectForKey:[NSNumber numberWithDouble:requestID]];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(clearCookies:(RCTResponseSenderBlock)responseSender)
|
||||
@@ -700,6 +714,12 @@ RCT_EXPORT_METHOD(clearCookies:(RCTResponseSenderBlock)responseSender)
|
||||
responseSender(@[@YES]);
|
||||
}
|
||||
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:
|
||||
(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
|
||||
{
|
||||
return std::make_shared<facebook::react::NativeNetworkingIOSSpecJSI>(self, jsInvoker);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTBridge (RCTNetworking)
|
||||
@@ -710,3 +730,7 @@ RCT_EXPORT_METHOD(clearCookies:(RCTResponseSenderBlock)responseSender)
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Class RCTNetworkingCls(void) {
|
||||
return RCTNetworking.class;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ else
|
||||
source[:tag] = "v#{version}"
|
||||
end
|
||||
|
||||
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
||||
folly_version = '2018.10.22.00'
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "React-RCTNetwork"
|
||||
s.version = version
|
||||
@@ -24,10 +27,20 @@ Pod::Spec.new do |s|
|
||||
s.license = package["license"]
|
||||
s.author = "Facebook, Inc. and its affiliates"
|
||||
s.platforms = { :ios => "9.0", :tvos => "9.2" }
|
||||
s.compiler_flags = folly_compiler_flags + ' -Wno-nullability-completeness'
|
||||
s.source = source
|
||||
s.source_files = "*.{m,mm}"
|
||||
s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs"
|
||||
s.header_dir = "RCTNetwork"
|
||||
s.pod_target_xcconfig = {
|
||||
"USE_HEADERMAP" => "YES",
|
||||
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
|
||||
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Folly\""
|
||||
}
|
||||
|
||||
s.dependency "Folly", folly_version
|
||||
s.dependency "FBReactNativeSpec", version
|
||||
s.dependency "RCTTypeSafety", version
|
||||
s.dependency "ReactCommon/turbomodule/core", version
|
||||
s.dependency "React-Core/RCTNetworkHeaders", version
|
||||
end
|
||||
|
||||
@@ -226,7 +226,11 @@ PODS:
|
||||
- React-RCTLinking (1000.0.0):
|
||||
- React-Core/RCTLinkingHeaders (= 1000.0.0)
|
||||
- React-RCTNetwork (1000.0.0):
|
||||
- FBReactNativeSpec (= 1000.0.0)
|
||||
- Folly (= 2018.10.22.00)
|
||||
- RCTTypeSafety (= 1000.0.0)
|
||||
- React-Core/RCTNetworkHeaders (= 1000.0.0)
|
||||
- ReactCommon/turbomodule/core (= 1000.0.0)
|
||||
- React-RCTPushNotification (1000.0.0):
|
||||
- React-Core/RCTPushNotificationHeaders (= 1000.0.0)
|
||||
- React-RCTSettings (1000.0.0):
|
||||
@@ -387,7 +391,7 @@ SPEC CHECKSUMS:
|
||||
React-RCTBlob: 8df793b30385b7ffe7e6703651043bad369cd756
|
||||
React-RCTImage: 3ee9a6cd02c7741ebe3a001d51a18c349019778f
|
||||
React-RCTLinking: d7d7f792e63a8d57380cecbb9b7a3b31f92d1bb6
|
||||
React-RCTNetwork: c8f9d40297f35ea3792ea81866f33e8b45c25935
|
||||
React-RCTNetwork: 156d1edeff084555eb31ba35d4cee6bc76c91908
|
||||
React-RCTPushNotification: acffa8af6a20e6d41b041a8c4cb4bea0de9df0dd
|
||||
React-RCTSettings: 8138286da8de74839cb436dd37704ed64d4bfe78
|
||||
React-RCTTest: d148e0657ce77ffd43a10325c284f47f25fb0532
|
||||
|
||||
Reference in New Issue
Block a user