diff --git a/Libraries/Network/NativeNetworkingAndroid.js b/Libraries/Network/NativeNetworkingAndroid.js new file mode 100644 index 00000000000..6db46cef70f --- /dev/null +++ b/Libraries/Network/NativeNetworkingAndroid.js @@ -0,0 +1,38 @@ +/** + * 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. + * + * @flow + * @format + */ + +'use strict'; + +import type {TurboModule} from 'RCTExport'; +import * as TurboModuleRegistry from 'TurboModuleRegistry'; + +type Header = [string, string]; + +export interface Spec extends TurboModule { + +sendRequest: ( + method: string, + url: string, + requestId: number, + headers: Array
, + data: Object, + responseType: Object, // TODO: Use stricter type. + useIncrementalUpdates: boolean, + timeout: number, + withCredentials: boolean, + ) => void; + +abortRequest: (requestId: number) => void; + +clearCookies: (callback: (result: boolean) => mixed) => void; + + // RCTEventEmitter + +addListener: (eventName: string) => void; + +removeListeners: (count: number) => void; +} + +export default TurboModuleRegistry.getEnforcing('Networking'); diff --git a/Libraries/Network/NativeNetworkingIOS.js b/Libraries/Network/NativeNetworkingIOS.js new file mode 100644 index 00000000000..f61b3520a0e --- /dev/null +++ b/Libraries/Network/NativeNetworkingIOS.js @@ -0,0 +1,38 @@ +/** + * 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. + * + * @flow + * @format + */ + +'use strict'; + +import type {TurboModule} from 'RCTExport'; +import * as TurboModuleRegistry from 'TurboModuleRegistry'; + +export interface Spec extends TurboModule { + +sendRequest: ( + query: {| + method: string, + url: string, + data: Object, + headers: Object, + responseType: Object, // TODO: Use stricter type. + incrementalUpdates: boolean, + timeout: number, + withCredentials: boolean, + |}, + callback: (requestId: number) => mixed, + ) => void; + +abortRequest: (requestId: number) => void; + +clearCookies: (callback: (result: boolean) => mixed) => void; + + // RCTEventEmitter + +addListener: (eventName: string) => void; + +removeListeners: (count: number) => void; +} + +export default TurboModuleRegistry.getEnforcing('Networking'); diff --git a/Libraries/Network/RCTNetworking.android.js b/Libraries/Network/RCTNetworking.android.js index 89435e2714c..c809b8dcdd3 100644 --- a/Libraries/Network/RCTNetworking.android.js +++ b/Libraries/Network/RCTNetworking.android.js @@ -13,8 +13,7 @@ // Do not require the native RCTNetworking module directly! Use this wrapper module instead. // It will add the necessary requestId, so that you don't have to generate it yourself. const NativeEventEmitter = require('../EventEmitter/NativeEventEmitter'); -const RCTNetworkingNative = require('../BatchedBridge/NativeModules') - .Networking; +import NativeNetworkingAndroid from './NativeNetworkingAndroid'; const convertRequestBody = require('./convertRequestBody'); import type {RequestBody} from './convertRequestBody'; @@ -42,7 +41,7 @@ function generateRequestId(): number { */ class RCTNetworking extends NativeEventEmitter { constructor() { - super(RCTNetworkingNative); + super(NativeNetworkingAndroid); } sendRequest( @@ -54,7 +53,7 @@ class RCTNetworking extends NativeEventEmitter { responseType: 'text' | 'base64', incrementalUpdates: boolean, timeout: number, - callback: (requestId: number) => any, + callback: (requestId: number) => mixed, withCredentials: boolean, ) { const body = convertRequestBody(data); @@ -65,7 +64,7 @@ class RCTNetworking extends NativeEventEmitter { })); } const requestId = generateRequestId(); - RCTNetworkingNative.sendRequest( + NativeNetworkingAndroid.sendRequest( method, url, requestId, @@ -80,11 +79,11 @@ class RCTNetworking extends NativeEventEmitter { } abortRequest(requestId: number) { - RCTNetworkingNative.abortRequest(requestId); + NativeNetworkingAndroid.abortRequest(requestId); } clearCookies(callback: (result: boolean) => any) { - RCTNetworkingNative.clearCookies(callback); + NativeNetworkingAndroid.clearCookies(callback); } } diff --git a/Libraries/Network/RCTNetworking.ios.js b/Libraries/Network/RCTNetworking.ios.js index 6905142cbff..62f4f26b789 100644 --- a/Libraries/Network/RCTNetworking.ios.js +++ b/Libraries/Network/RCTNetworking.ios.js @@ -11,8 +11,7 @@ 'use strict'; const NativeEventEmitter = require('../EventEmitter/NativeEventEmitter'); -const RCTNetworkingNative = require('../BatchedBridge/NativeModules') - .Networking; +import NativeNetworkingIOS from './NativeNetworkingIOS'; const convertRequestBody = require('./convertRequestBody'); import type {RequestBody} from './convertRequestBody'; @@ -21,7 +20,7 @@ import type {NativeResponseType} from './XMLHttpRequest'; class RCTNetworking extends NativeEventEmitter { constructor() { - super(RCTNetworkingNative); + super(NativeNetworkingIOS); } sendRequest( @@ -33,11 +32,11 @@ class RCTNetworking extends NativeEventEmitter { responseType: NativeResponseType, incrementalUpdates: boolean, timeout: number, - callback: (requestId: number) => any, + callback: (requestId: number) => mixed, withCredentials: boolean, ) { const body = convertRequestBody(data); - RCTNetworkingNative.sendRequest( + NativeNetworkingIOS.sendRequest( { method, url, @@ -53,11 +52,11 @@ class RCTNetworking extends NativeEventEmitter { } abortRequest(requestId: number) { - RCTNetworkingNative.abortRequest(requestId); + NativeNetworkingIOS.abortRequest(requestId); } - clearCookies(callback: (result: boolean) => any) { - RCTNetworkingNative.clearCookies(callback); + clearCookies(callback: (result: boolean) => mixed) { + NativeNetworkingIOS.clearCookies(callback); } }