Skip to content

Commit

Permalink
Switch Platform Constansts to use typedConstants structs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
osdnk authored and facebook-github-bot committed Aug 5, 2019
1 parent 306c8d6 commit 2956eb2
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions React/CoreModules/RCTPlatform.mm
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,28 @@ - (dispatch_queue_t)methodQueue
}

// TODO: Use the generated struct return type.
- (NSDictionary<NSString *, id> *)constantsToExport
- (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)constantsToExport
{
return [self getConstants];
return (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)[self getConstants];
}

// TODO: Use the generated struct return type.
- (NSDictionary<NSString *, id> *)getConstants
- (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)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<JS::NativePlatformConstantsIOS::Constants>({
.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<double>{} : [versions[@"prerelease"] doubleValue]
}),
});
}

- (std::shared_ptr<TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<JSCallInvoker>)jsInvoker
Expand Down

0 comments on commit 2956eb2

Please sign in to comment.