diff --git a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h index 17f2f980169..5a47f0af21b 100644 --- a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h +++ b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h @@ -1813,7 +1813,7 @@ namespace JS { NSString *url() const; id data() const; id headers() const; - id responseType() const; + NSString *responseType() const; bool incrementalUpdates() const; double timeout() const; bool withCredentials() const; @@ -3490,10 +3490,10 @@ inline id JS::NativeNetworkingIOS::SpecSendRequestQuery::headers() con id const p = _v[@"headers"]; return p; } -inline id 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 { diff --git a/Libraries/Network/NativeNetworkingIOS.js b/Libraries/Network/NativeNetworkingIOS.js index 85a6cffbd22..59b3da849a9 100644 --- a/Libraries/Network/NativeNetworkingIOS.js +++ b/Libraries/Network/NativeNetworkingIOS.js @@ -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, diff --git a/Libraries/Network/RCTNetworkPlugins.h b/Libraries/Network/RCTNetworkPlugins.h new file mode 100644 index 00000000000..cad0c011b17 --- /dev/null +++ b/Libraries/Network/RCTNetworkPlugins.h @@ -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 + +#else + +// OSS-compatibility layer + +#import + +#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 diff --git a/Libraries/Network/RCTNetworkPlugins.mm b/Libraries/Network/RCTNetworkPlugins.mm new file mode 100644 index 00000000000..2a221ac9640 --- /dev/null +++ b/Libraries/Network/RCTNetworkPlugins.mm @@ -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 +#import + +Class RCTNetworkClassProvider(const char *name) { + static std::unordered_map 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 diff --git a/Libraries/Network/RCTNetworking.mm b/Libraries/Network/RCTNetworking.mm index a2219a26c38..36383741fc7 100644 --- a/Libraries/Network/RCTNetworking.mm +++ b/Libraries/Network/RCTNetworking.mm @@ -8,6 +8,7 @@ #import +#import #import #import #import @@ -18,11 +19,13 @@ #import +#import "RCTNetworkPlugins.h" + typedef RCTURLRequestCancellationBlock (^RCTHTTPQueryResult)(NSError *error, NSDictionary *result); NSString *const RCTNetworkingPHUploadHackScheme = @"ph-upload"; -@interface RCTNetworking () +@interface RCTNetworking () - (RCTURLRequestCancellationBlock)processDataForHTTPQuery:(NSDictionary *)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)getTurboModuleWithJsInvoker: + (std::shared_ptr)jsInvoker +{ + return std::make_shared(self, jsInvoker); +} + @end @implementation RCTBridge (RCTNetworking) @@ -710,3 +730,7 @@ RCT_EXPORT_METHOD(clearCookies:(RCTResponseSenderBlock)responseSender) } @end + +Class RCTNetworkingCls(void) { + return RCTNetworking.class; +} diff --git a/Libraries/Network/React-RCTNetwork.podspec b/Libraries/Network/React-RCTNetwork.podspec index 279b001c452..3802adc1ae1 100644 --- a/Libraries/Network/React-RCTNetwork.podspec +++ b/Libraries/Network/React-RCTNetwork.podspec @@ -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 diff --git a/RNTester/Podfile.lock b/RNTester/Podfile.lock index 99ac57d30dc..61475b7ecd7 100644 --- a/RNTester/Podfile.lock +++ b/RNTester/Podfile.lock @@ -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