Permalink
Browse files

Merge AndroidConstants and IOSConstants into PlatformConstants

Reviewed By: AaaChiuuu

Differential Revision: D4597790

fbshipit-source-id: 0a54598d6e9cadb75efff4ac17c13899d6785f9b
  • Loading branch information...
javache authored and facebook-github-bot committed Feb 22, 2017
1 parent 68135d9 commit dba133a29194e300e9a2e9e6753f9d4e3a13c194
@@ -39,8 +39,8 @@ const PropTypes = React.PropTypes;
const stylePropType = StyleSheetPropType(ViewStylePropTypes);
const forceTouchAvailable = (NativeModules.IOSConstants &&
NativeModules.IOSConstants.forceTouchAvailable) || false;
const forceTouchAvailable = (NativeModules.PlatformConstants &&
NativeModules.PlatformConstants.forceTouchAvailable) || false;
const statics = {
AccessibilityTraits,
@@ -12,10 +12,9 @@
'use strict';
if (__DEV__) {
var AppState = require('AppState');
var NativeModules = require('NativeModules');
var Platform = require('Platform');
var {connectToDevTools} = require('react-devtools-core');
const AppState = require('AppState');
const {PlatformConstants} = require('NativeModules');
const {connectToDevTools} = require('react-devtools-core');
connectToDevTools({
isAppActive() {
@@ -26,8 +25,8 @@ if (__DEV__) {
return AppState.currentState !== 'background';
},
// Special case: Genymotion is running on a different host.
host: (Platform.OS === 'android' && NativeModules.AndroidConstants) ?
NativeModules.AndroidConstants.ServerHost.split(':')[0] :
host: PlatformConstants && PlatformConstants.ServerHost ?
PlatformConstants.ServerHost.split(':')[0] :
'localhost',
// Read the optional global variable for backward compatibility.
// It was added in https://github.com/facebook/react-native/commit/bf2b435322e89d0aeee8792b1c6e04656c2719a0.
@@ -12,14 +12,16 @@
'use strict';
const NativeModules = require('NativeModules');
const Platform = {
OS: 'android',
get Version() {
const AndroidConstants = require('NativeModules').AndroidConstants;
return AndroidConstants && AndroidConstants.Version;
const constants = NativeModules.PlatformConstants;
return constants && constants.Version;
},
get isTesting(): boolean {
const constants = require('NativeModules').AndroidConstants;
const constants = NativeModules.PlatformConstants;
return constants && constants.isTesting;
},
select: (obj: Object) => 'android' in obj ? obj.android : obj.default,
@@ -12,18 +12,24 @@
'use strict';
const NativeModules = require('NativeModules');
const Platform = {
OS: 'ios',
get Version() {
const constants = require('NativeModules').IOSConstants;
return constants ? constants.osVersion : '';
const constants = NativeModules.PlatformConstants;
return constants && constants.osVersion;
},
get isPad() {
const constants = NativeModules.PlatformConstants;
return constants ? constants.interfaceIdiom === 'pad' : false;
},
get isTVOS() {
const constants = require('NativeModules').IOSConstants;
return constants ? (constants.interfaceIdiom === 'tv') : false;
const constants = NativeModules.PlatformConstants;
return constants ? constants.interfaceIdiom === 'tv' : false;
},
get isTesting(): boolean {
const constants = require('NativeModules').IOSConstants;
const constants = NativeModules.PlatformConstants;
return constants && constants.isTesting;
},
select: (obj: Object) => 'ios' in obj ? obj.ios : obj.default,
View
@@ -35,7 +35,7 @@ static BOOL isTestingEnvironment(void) {
return [environment[@"IS_TESTING"] boolValue];
}
RCT_EXPORT_MODULE(IOSConstants)
RCT_EXPORT_MODULE(PlatformConstants)
- (NSDictionary<NSString *, id> *)constantsToExport
{
@@ -22,14 +22,14 @@
/**
* Module that exposes Android Constants to JS.
*/
@ReactModule(name = "AndroidConstants")
@ReactModule(name = "PlatformConstants")
public class AndroidInfoModule extends BaseJavaModule {
private static final String IS_TESTING = "IS_TESTING";
@Override
public String getName() {
return "AndroidConstants";
return "PlatformConstants";
}
@Override

0 comments on commit dba133a

Please sign in to comment.