From 2956eb266f1edad09165baf7c5db832c170ad41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Osadnik?= Date: Mon, 5 Aug 2019 04:14:30 -0700 Subject: [PATCH] Switch Platform Constansts to use typedConstants structs Summary: It's actually the first module in OSS which is typed with taking advantages of codegen. Reviewed By: RSNara Differential Revision: D16620334 fbshipit-source-id: 65d6656506f2a4c68d493939ecfa65ba975abead --- React/CoreModules/RCTPlatform.mm | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/React/CoreModules/RCTPlatform.mm b/React/CoreModules/RCTPlatform.mm index 69cae85879d52b..675e9a4aa80f71 100644 --- a/React/CoreModules/RCTPlatform.mm +++ b/React/CoreModules/RCTPlatform.mm @@ -50,23 +50,28 @@ - (dispatch_queue_t)methodQueue } // TODO: Use the generated struct return type. -- (NSDictionary *)constantsToExport +- (ModuleConstants)constantsToExport { - return [self getConstants]; + return (ModuleConstants)[self getConstants]; } -// TODO: Use the generated struct return type. -- (NSDictionary *)getConstants +- (ModuleConstants)getConstants { UIDevice *device = [UIDevice currentDevice]; - return @{ - @"forceTouchAvailable": @(RCTForceTouchAvailable()), - @"osVersion": [device systemVersion], - @"systemName": [device systemName], - @"interfaceIdiom": interfaceIdiom([device userInterfaceIdiom]), - @"isTesting": @(RCTRunningInTestEnvironment()), - @"reactNativeVersion": RCTGetReactNativeVersion(), - }; + auto versions = RCTGetReactNativeVersion(); + return typedConstants({ + .forceTouchAvailable = @(RCTForceTouchAvailable()), + .osVersion = [device systemVersion], + .systemName = [device systemName], + .interfaceIdiom = interfaceIdiom([device userInterfaceIdiom]), + .isTesting = @(RCTRunningInTestEnvironment()), + .reactNativeVersion = JS::NativePlatformConstantsIOS::ConstantsReactNativeVersion::Builder({ + .minor = [versions[@"minor"] doubleValue], + .major = [versions[@"major"] doubleValue], + .patch = [versions[@"patch"] doubleValue], + .prerelease = [versions[@"prerelease"] isKindOfClass: [NSNull class]] ? folly::Optional{} : [versions[@"prerelease"] doubleValue] + }), + }); } - (std::shared_ptr)getTurboModuleWithJsInvoker:(std::shared_ptr)jsInvoker