Permalink
Browse files

Move Platform constants to RCTPlatform

Reviewed By: majak

Differential Revision: D4081849

fbshipit-source-id: bee08af2f68dcc1af424f382f960ff897ba11945
  • Loading branch information...
javache authored and Facebook Github Bot committed Oct 27, 2016
1 parent a743fbe commit 384ea330c8960bcdbd4a1f7381e8b10feff2e283
@@ -13,11 +13,11 @@
const EdgeInsetsPropType = require('EdgeInsetsPropType');
const NativeMethodsMixin = require('react/lib/NativeMethodsMixin');
+const NativeModules = require('NativeModules');
const React = require('React');
const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
const ReactNativeViewAttributes = require('ReactNativeViewAttributes');
const StyleSheetPropType = require('StyleSheetPropType');
-const UIManager = require('UIManager');
const ViewStylePropTypes = require('ViewStylePropTypes');
const requireNativeComponent = require('requireNativeComponent');
@@ -53,8 +53,8 @@ const AccessibilityComponentType = [
'radiobutton_unchecked',
];
-const forceTouchAvailable = (UIManager.RCTView.Constants &&
- UIManager.RCTView.Constants.forceTouchAvailable) || false;
+const forceTouchAvailable = (NativeModules.IOSConstants &&
+ NativeModules.IOSConstants.forceTouchAvailable) || false;
const statics = {
AccessibilityTraits,
@@ -515,6 +515,7 @@ const RCTView = requireNativeComponent('RCTView', View, {
});
if (__DEV__) {
+ const UIManager = require('UIManager');
const viewConfig = UIManager.viewConfigs && UIManager.viewConfigs.RCTView || {};
for (const prop in viewConfig.nativeProps) {
const viewAny: any = View; // Appease flow
@@ -14,7 +14,9 @@
var Platform = {
OS: 'android',
- get Version() { return require('NativeModules').AndroidConstants.Version; },
+ get Version() {
+ return require('NativeModules').AndroidConstants.Version;
+ },
select: (obj: Object) => obj.android,
};
@@ -14,6 +14,9 @@
var Platform = {
OS: 'ios',
+ get Version() {
+ return require('NativeModules').IOSConstants.osVersion;
+ },
select: (obj: Object) => obj.ios,
};
View
@@ -0,0 +1,16 @@
+/**
+ * Copyright (c) 2015-present, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
+ */
+
+#import <Foundation/Foundation.h>
+
+#import "RCTBridgeModule.h"
+
+@interface RCTPlatform : NSObject <RCTBridgeModule>
+
+@end
View
@@ -0,0 +1,45 @@
+/**
+ * Copyright (c) 2015-present, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
+ */
+
+#import "RCTPlatform.h"
+
+#import <UIKit/UIKit.h>
+
+#import "RCTUtils.h"
+
+@implementation RCTPlatform
+
+static NSString *interfaceIdiom(UIUserInterfaceIdiom idiom) {
+ switch(idiom) {
+ case UIUserInterfaceIdiomPhone:
+ return @"phone";
+ case UIUserInterfaceIdiomPad:
+ return @"pad";
+ case UIUserInterfaceIdiomTV:
+ return @"tv";
+ case UIUserInterfaceIdiomCarPlay:
+ return @"carplay";
+ default:
+ return @"unknown";
+ }
+}
+
+RCT_EXPORT_MODULE(IOSConstants)
+
+- (NSDictionary<NSString *, id> *)constantsToExport
+{
+ UIDevice *device = [UIDevice currentDevice];
+ return @{
+ @"forceTouchAvailable": @(RCTForceTouchAvailable()),
+ @"osVersion": [device systemVersion],
+ @"interfaceIdiom": interfaceIdiom([device userInterfaceIdiom]),
+ };
+}
+
+@end
@@ -171,6 +171,7 @@
391E86A41C623EC800009732 /* RCTTouchEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 391E86A21C623EC800009732 /* RCTTouchEvent.m */; };
3D1E68DB1CABD13900DD7465 /* RCTDisplayLink.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D1E68D91CABD13900DD7465 /* RCTDisplayLink.m */; };
3D37B5821D522B190042D5B5 /* RCTFont.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3D37B5811D522B190042D5B5 /* RCTFont.mm */; };
+ 3D7749441DC1065C007EC8D8 /* RCTPlatform.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D7749431DC1065C007EC8D8 /* RCTPlatform.m */; };
3DC724321D8BF99A00808C32 /* RCTJSCErrorHandling.m in Sources */ = {isa = PBXBuildFile; fileRef = 3DC724311D8BF99A00808C32 /* RCTJSCErrorHandling.m */; };
3EDCA8A51D3591E700450C31 /* RCTErrorInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCA8A41D3591E700450C31 /* RCTErrorInfo.m */; };
58114A161AAE854800E7D092 /* RCTPicker.m in Sources */ = {isa = PBXBuildFile; fileRef = 58114A131AAE854800E7D092 /* RCTPicker.m */; };
@@ -384,6 +385,8 @@
3D1E68D91CABD13900DD7465 /* RCTDisplayLink.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTDisplayLink.m; sourceTree = "<group>"; };
3D37B5801D522B190042D5B5 /* RCTFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTFont.h; sourceTree = "<group>"; };
3D37B5811D522B190042D5B5 /* RCTFont.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTFont.mm; sourceTree = "<group>"; };
+ 3D7749421DC1065C007EC8D8 /* RCTPlatform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTPlatform.h; sourceTree = "<group>"; };
+ 3D7749431DC1065C007EC8D8 /* RCTPlatform.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTPlatform.m; sourceTree = "<group>"; };
3DB910701C74B21600838BBE /* RCTWebSocketProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTWebSocketProxy.h; sourceTree = "<group>"; };
3DB910711C74B21600838BBE /* RCTWebSocketProxyDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTWebSocketProxyDelegate.h; sourceTree = "<group>"; };
3DC724301D8BF99A00808C32 /* RCTJSCErrorHandling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTJSCErrorHandling.h; sourceTree = "<group>"; };
@@ -686,11 +689,6 @@
83CBBA491A601E3B00E9B192 /* Base */ = {
isa = PBXGroup;
children = (
- 3EDCA8A21D3591E700450C31 /* RCTErrorCustomizer.h */,
- 3EDCA8A31D3591E700450C31 /* RCTErrorInfo.h */,
- 3EDCA8A41D3591E700450C31 /* RCTErrorInfo.m */,
- 68EFE4ED1CF6EB3900A1DE13 /* RCTBundleURLProvider.m */,
- 68EFE4EC1CF6EB3000A1DE13 /* RCTBundleURLProvider.h */,
83CBBA4A1A601E3B00E9B192 /* RCTAssert.h */,
83CBBA4B1A601E3B00E9B192 /* RCTAssert.m */,
14C2CA771B3ACB0400E6CBB2 /* RCTBatchedBridge.m */,
@@ -700,11 +698,16 @@
1482F9E61B55B927000ADFF3 /* RCTBridgeDelegate.h */,
13AFBCA11C07287B00BBAEAA /* RCTBridgeMethod.h */,
830213F31A654E0800B993E6 /* RCTBridgeModule.h */,
+ 68EFE4EC1CF6EB3000A1DE13 /* RCTBundleURLProvider.h */,
+ 68EFE4ED1CF6EB3900A1DE13 /* RCTBundleURLProvider.m */,
83CBBACA1A6023D300E9B192 /* RCTConvert.h */,
83CBBACB1A6023D300E9B192 /* RCTConvert.m */,
13AF1F851AE6E777005F5298 /* RCTDefines.h */,
3D1E68D81CABD13900DD7465 /* RCTDisplayLink.h */,
3D1E68D91CABD13900DD7465 /* RCTDisplayLink.m */,
+ 3EDCA8A21D3591E700450C31 /* RCTErrorCustomizer.h */,
+ 3EDCA8A31D3591E700450C31 /* RCTErrorInfo.h */,
+ 3EDCA8A41D3591E700450C31 /* RCTErrorInfo.m */,
83CBBA651A601EF300E9B192 /* RCTEventDispatcher.h */,
83CBBA661A601EF300E9B192 /* RCTEventDispatcher.m */,
1436DD071ADE7AA000A5ED7D /* RCTFrameUpdate.h */,
@@ -734,6 +737,8 @@
13A6E20D1C19AA0C00845B82 /* RCTParserUtils.m */,
142014181B32094000CC17BA /* RCTPerformanceLogger.h */,
142014171B32094000CC17BA /* RCTPerformanceLogger.m */,
+ 3D7749421DC1065C007EC8D8 /* RCTPlatform.h */,
+ 3D7749431DC1065C007EC8D8 /* RCTPlatform.m */,
830A229C1A66C68A008503DA /* RCTRootView.h */,
830A229D1A66C68A008503DA /* RCTRootView.m */,
13AFBCA21C07287B00BBAEAA /* RCTRootViewDelegate.h */,
@@ -799,7 +804,7 @@
83CBB9F71A601CBA00E9B192 /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0610;
+ LastUpgradeCheck = 0800;
ORGANIZATIONNAME = Facebook;
TargetAttributes = {
2D2A28121D9B038B00D4039D = {
@@ -1047,6 +1052,7 @@
13B0801D1A69489C00A75B9A /* RCTNavItemManager.m in Sources */,
13A6E20E1C19AA0C00845B82 /* RCTParserUtils.m in Sources */,
13E067571A70F44B002CDEE1 /* RCTView.m in Sources */,
+ 3D7749441DC1065C007EC8D8 /* RCTPlatform.m in Sources */,
13AFBCA01C07247D00BBAEAA /* RCTMapOverlay.m in Sources */,
13D9FEEE1CDCD93000158BD7 /* RCTKeyboardObserver.m in Sources */,
B233E6EA1D2D845D00BC68BA /* RCTI18nManager.m in Sources */,
@@ -1145,15 +1151,18 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
+ GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
@@ -1195,15 +1204,18 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_NO_COMMON_BLOCKS = YES;
GCC_PREPROCESSOR_DEFINITIONS = "";
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
@@ -91,11 +91,6 @@ - (RCTShadowView *)shadowView
return @[];
}
-- (NSDictionary<NSString *, id> *)constantsToExport
-{
- return @{@"forceTouchAvailable": @(RCTForceTouchAvailable())};
-}
-
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(__unused RCTShadowView *)shadowView
{
return nil;

0 comments on commit 384ea33

Please sign in to comment.