Added stubs for some native modules

Reviewed By: javache

Differential Revision: D5111649

fbshipit-source-id: eef2f84556611dec01978d845b89fa145ec5d4db
This commit is contained in:
Alex Dvornikov
2017-06-01 08:20:57 -07:00
committed by Facebook Github Bot
parent bd5051adeb
commit a93b7a2da0
7 changed files with 170 additions and 63 deletions

View File

@@ -11,7 +11,7 @@
*/
'use strict';
const FormData = require('FormData');
const MissingNativeEventEmitterShim = require('MissingNativeEventEmitterShim');
const NativeEventEmitter = require('NativeEventEmitter');
const RCTNetworkingNative = require('NativeModules').Networking;
const convertRequestBody = require('convertRequestBody');
@@ -20,6 +20,8 @@ import type {RequestBody} from 'convertRequestBody';
class RCTNetworking extends NativeEventEmitter {
isAvailable: boolean = true;
constructor() {
super(RCTNetworkingNative);
}
@@ -58,4 +60,31 @@ class RCTNetworking extends NativeEventEmitter {
}
}
module.exports = new RCTNetworking();
if (__DEV__ && !RCTNetworkingNative) {
class MissingNativeRCTNetworkingShim extends MissingNativeEventEmitterShim {
constructor() {
super('RCTAppState', 'AppState');
}
sendRequest(...args: Array<any>) {
this.throwMissingNativeModule();
}
abortRequest(...args: Array<any>) {
this.throwMissingNativeModule();
}
clearCookies(...args: Array<any>) {
this.throwMissingNativeModule();
}
}
// This module depends on the native `RCTNetworkingNative` module. If you don't include it,
// `RCTNetworking.isAvailable` will return `false`, and any method calls will throw.
// We reassign the class variable to keep the autodoc generator happy.
RCTNetworking = new MissingNativeRCTNetworkingShim();
} else {
RCTNetworking = new RCTNetworking();
}
module.exports = RCTNetworking;