inline a bunch of NativeModule requires

Reviewed By: shergin

Differential Revision: D4578180

fbshipit-source-id: 3764ffd32eb7e4698e928740bc72bbad02876894
This commit is contained in:
Aaron Chiu
2017-02-17 16:39:50 -08:00
committed by Facebook Github Bot
parent dc0df40770
commit 1fa95ed390
6 changed files with 32 additions and 35 deletions

View File

@@ -11,9 +11,9 @@
*/
'use strict';
var AlertIOS = require('AlertIOS');
var Platform = require('Platform');
var DialogModuleAndroid = require('NativeModules').DialogManagerAndroid;
const AlertIOS = require('AlertIOS');
const NativeModules = require('NativeModules');
const Platform = require('Platform');
import type { AlertType, AlertButtonStyle } from 'AlertIOS';
@@ -127,18 +127,18 @@ class AlertAndroid {
if (buttonPositive) {
config = {...config, buttonPositive: buttonPositive.text || '' };
}
DialogModuleAndroid.showAlert(
NativeModules.DialogModuleAndroid.showAlert(
config,
(errorMessage) => console.warn(errorMessage),
(action, buttonKey) => {
if (action !== DialogModuleAndroid.buttonClicked) {
if (action !== NativeModules.DialogModuleAndroid.buttonClicked) {
return;
}
if (buttonKey === DialogModuleAndroid.buttonNeutral) {
if (buttonKey === NativeModules.DialogModuleAndroid.buttonNeutral) {
buttonNeutral.onPress && buttonNeutral.onPress();
} else if (buttonKey === DialogModuleAndroid.buttonNegative) {
} else if (buttonKey === NativeModules.DialogModuleAndroid.buttonNegative) {
buttonNegative.onPress && buttonNegative.onPress();
} else if (buttonKey === DialogModuleAndroid.buttonPositive) {
} else if (buttonKey === NativeModules.DialogModuleAndroid.buttonPositive) {
buttonPositive.onPress && buttonPositive.onPress();
}
}

View File

@@ -10,14 +10,14 @@
*/
'use strict';
var DialogManager = require('NativeModules').DialogManagerAndroid;
var NativeModules = require('NativeModules');
function emptyCallback() {}
module.exports = {
alertWithArgs: function(args, callback) {
// TODO(5998984): Polyfill it correctly with DialogManagerAndroid
DialogManager.showAlert(
NativeModules.DialogManagerAndroid.showAlert(
args,
emptyCallback,
callback || emptyCallback);

View File

@@ -13,17 +13,17 @@
*/
'use strict';
import type { ResolvedAssetSource } from 'AssetSourceResolver';
const AssetRegistry = require('AssetRegistry');
const AssetSourceResolver = require('AssetSourceResolver');
const { SourceCode } = require('NativeModules');
const NativeModules = require('NativeModules');
import type { ResolvedAssetSource } from 'AssetSourceResolver';
let _customSourceTransformer, _serverURL, _bundleSourcePath;
function getDevServerURL(): ?string {
if (_serverURL === undefined) {
var scriptURL = SourceCode.scriptURL;
var scriptURL = NativeModules.SourceCode.scriptURL;
var match = scriptURL && scriptURL.match(/^https?:\/\/.*?\//);
if (match) {
// Bundle was loaded from network
@@ -38,7 +38,7 @@ function getDevServerURL(): ?string {
function getBundleSourcePath(): ?string {
if (_bundleSourcePath === undefined) {
const scriptURL = SourceCode.scriptURL;
const scriptURL = NativeModules.SourceCode.scriptURL;
if (!scriptURL) {
// scriptURL is falsy, we have nothing to go on here
_bundleSourcePath = null;

View File

@@ -11,12 +11,11 @@
*/
'use strict';
const DialogManagerAndroid = require('NativeModules').DialogManagerAndroid;
const Permissions = require('NativeModules').PermissionsAndroid;
const NativeModules = require('NativeModules');
type Rationale = {
title: string;
message: string;
title: string,
message: string,
}
type PermissionStatus = 'granted' | 'denied' | 'never_ask_again';
@@ -113,7 +112,7 @@ class PermissionsAndroid {
*/
checkPermission(permission: string) : Promise<boolean> {
console.warn('"PermissionsAndroid.checkPermission" is deprecated. Use "PermissionsAndroid.check" instead');
return Permissions.checkPermission(permission);
return NativeModules.PermissionsAndroid.checkPermission(permission);
}
/**
@@ -121,7 +120,7 @@ class PermissionsAndroid {
* permissions has been granted
*/
check(permission: string) : Promise<boolean> {
return Permissions.checkPermission(permission);
return NativeModules.PermissionsAndroid.checkPermission(permission);
}
/**
@@ -156,19 +155,19 @@ class PermissionsAndroid {
*/
async request(permission: string, rationale?: Rationale) : Promise<PermissionStatus> {
if (rationale) {
const shouldShowRationale = await Permissions.shouldShowRequestPermissionRationale(permission);
const shouldShowRationale = await NativeModules.PermissionsAndroid.shouldShowRequestPermissionRationale(permission);
if (shouldShowRationale) {
return new Promise((resolve, reject) => {
DialogManagerAndroid.showAlert(
NativeModules.DialogManagerAndroid.showAlert(
rationale,
() => reject(new Error('Error showing rationale')),
() => resolve(Permissions.requestPermission(permission))
() => resolve(NativeModules.PermissionsAndroid.requestPermission(permission))
);
});
}
}
return Permissions.requestPermission(permission);
return NativeModules.PermissionsAndroid.requestPermission(permission);
}
/**
@@ -177,7 +176,7 @@ class PermissionsAndroid {
* indicating whether the user allowed or denied the request
*/
requestMultiple(permissions: Array<string>) : Promise<{[permission: string]: PermissionStatus}> {
return Permissions.requestMultiplePermissions(permissions);
return NativeModules.PermissionsAndroid.requestMultiplePermissions(permissions);
}
}

View File

@@ -13,14 +13,13 @@
const BatchedBridge = require('BatchedBridge');
const BugReporting = require('BugReporting');
const NativeModules = require('NativeModules');
const ReactNative = require('ReactNative');
const infoLog = require('infoLog');
const invariant = require('fbjs/lib/invariant');
const renderApplication = require('renderApplication');
const { HeadlessJsTaskSupport } = require('NativeModules');
if (__DEV__) {
// In order to use Cmd+P to record/dump perf data, we need to make sure
// this module is available in the bundle
@@ -188,10 +187,10 @@ const AppRegistry = {
throw new Error(`No task registered for key ${taskKey}`);
}
taskProvider()(data)
.then(() => HeadlessJsTaskSupport.notifyTaskFinished(taskId))
.then(() => NativeModules.HeadlessJsTaskSupport.notifyTaskFinished(taskId))
.catch(reason => {
console.error(reason);
HeadlessJsTaskSupport.notifyTaskFinished(taskId);
NativeModules.HeadlessJsTaskSupport.notifyTaskFinished(taskId);
});
}

View File

@@ -13,13 +13,12 @@
*/
'use strict';
var NativeModules = require('NativeModules');
var RCTAsyncSQLiteStorage = NativeModules.AsyncSQLiteDBStorage;
var RCTAsyncRocksDBStorage = NativeModules.AsyncRocksDBStorage;
var RCTAsyncFileStorage = NativeModules.AsyncLocalStorage;
const NativeModules = require('NativeModules');
// Use RocksDB if available, then SQLite, then file storage.
var RCTAsyncStorage = RCTAsyncRocksDBStorage || RCTAsyncSQLiteStorage || RCTAsyncFileStorage;
const RCTAsyncStorage = NativeModules.AsyncSQLiteDBStorage ||
NativeModules.AsyncRocksDBStorage ||
NativeModules.AsyncLocalStorage;
/**
* @class