diff --git a/Libraries/Components/View/View.js b/Libraries/Components/View/View.js index ccad6cefa..45f553582 100644 --- a/Libraries/Components/View/View.js +++ b/Libraries/Components/View/View.js @@ -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 diff --git a/Libraries/Utilities/Platform.android.js b/Libraries/Utilities/Platform.android.js index 86861e4c7..4d75d775b 100644 --- a/Libraries/Utilities/Platform.android.js +++ b/Libraries/Utilities/Platform.android.js @@ -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, }; diff --git a/Libraries/Utilities/Platform.ios.js b/Libraries/Utilities/Platform.ios.js index 070bd2874..749ca34f9 100644 --- a/Libraries/Utilities/Platform.ios.js +++ b/Libraries/Utilities/Platform.ios.js @@ -14,6 +14,9 @@ var Platform = { OS: 'ios', + get Version() { + return require('NativeModules').IOSConstants.osVersion; + }, select: (obj: Object) => obj.ios, }; diff --git a/React/Base/RCTPlatform.h b/React/Base/RCTPlatform.h new file mode 100644 index 000000000..309c47995 --- /dev/null +++ b/React/Base/RCTPlatform.h @@ -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 + +#import "RCTBridgeModule.h" + +@interface RCTPlatform : NSObject + +@end diff --git a/React/Base/RCTPlatform.m b/React/Base/RCTPlatform.m new file mode 100644 index 000000000..609b62ba9 --- /dev/null +++ b/React/Base/RCTPlatform.m @@ -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 + +#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 *)constantsToExport +{ + UIDevice *device = [UIDevice currentDevice]; + return @{ + @"forceTouchAvailable": @(RCTForceTouchAvailable()), + @"osVersion": [device systemVersion], + @"interfaceIdiom": interfaceIdiom([device userInterfaceIdiom]), + }; +} + +@end diff --git a/React/React.xcodeproj/project.pbxproj b/React/React.xcodeproj/project.pbxproj index e19d10862..39be9325e 100644 --- a/React/React.xcodeproj/project.pbxproj +++ b/React/React.xcodeproj/project.pbxproj @@ -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 = ""; }; 3D37B5801D522B190042D5B5 /* RCTFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTFont.h; sourceTree = ""; }; 3D37B5811D522B190042D5B5 /* RCTFont.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTFont.mm; sourceTree = ""; }; + 3D7749421DC1065C007EC8D8 /* RCTPlatform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTPlatform.h; sourceTree = ""; }; + 3D7749431DC1065C007EC8D8 /* RCTPlatform.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTPlatform.m; sourceTree = ""; }; 3DB910701C74B21600838BBE /* RCTWebSocketProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTWebSocketProxy.h; sourceTree = ""; }; 3DB910711C74B21600838BBE /* RCTWebSocketProxyDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTWebSocketProxyDelegate.h; sourceTree = ""; }; 3DC724301D8BF99A00808C32 /* RCTJSCErrorHandling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTJSCErrorHandling.h; sourceTree = ""; }; @@ -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,8 +1151,10 @@ 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"; @@ -1154,6 +1162,7 @@ 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,8 +1204,10 @@ 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"; @@ -1204,6 +1215,7 @@ 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; diff --git a/React/Views/RCTViewManager.m b/React/Views/RCTViewManager.m index 51ef44a79..794f1b1e4 100644 --- a/React/Views/RCTViewManager.m +++ b/React/Views/RCTViewManager.m @@ -91,11 +91,6 @@ RCT_EXPORT_MODULE() return @[]; } -- (NSDictionary *)constantsToExport -{ - return @{@"forceTouchAvailable": @(RCTForceTouchAvailable())}; -} - - (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(__unused RCTShadowView *)shadowView { return nil;