Skip to content

Commit 2956eb2

Browse files
osdnkfacebook-github-bot
authored andcommitted
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
1 parent 306c8d6 commit 2956eb2

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

React/CoreModules/RCTPlatform.mm

+17-12
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,28 @@ - (dispatch_queue_t)methodQueue
5050
}
5151

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

58-
// TODO: Use the generated struct return type.
59-
- (NSDictionary<NSString *, id> *)getConstants
58+
- (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)getConstants
6059
{
6160
UIDevice *device = [UIDevice currentDevice];
62-
return @{
63-
@"forceTouchAvailable": @(RCTForceTouchAvailable()),
64-
@"osVersion": [device systemVersion],
65-
@"systemName": [device systemName],
66-
@"interfaceIdiom": interfaceIdiom([device userInterfaceIdiom]),
67-
@"isTesting": @(RCTRunningInTestEnvironment()),
68-
@"reactNativeVersion": RCTGetReactNativeVersion(),
69-
};
61+
auto versions = RCTGetReactNativeVersion();
62+
return typedConstants<JS::NativePlatformConstantsIOS::Constants>({
63+
.forceTouchAvailable = @(RCTForceTouchAvailable()),
64+
.osVersion = [device systemVersion],
65+
.systemName = [device systemName],
66+
.interfaceIdiom = interfaceIdiom([device userInterfaceIdiom]),
67+
.isTesting = @(RCTRunningInTestEnvironment()),
68+
.reactNativeVersion = JS::NativePlatformConstantsIOS::ConstantsReactNativeVersion::Builder({
69+
.minor = [versions[@"minor"] doubleValue],
70+
.major = [versions[@"major"] doubleValue],
71+
.patch = [versions[@"patch"] doubleValue],
72+
.prerelease = [versions[@"prerelease"] isKindOfClass: [NSNull class]] ? folly::Optional<double>{} : [versions[@"prerelease"] doubleValue]
73+
}),
74+
});
7075
}
7176

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

0 commit comments

Comments
 (0)