UNPKG

2.42 kBPlain TextView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#import "RCTPlatform.h"
9
10#import <UIKit/UIKit.h>
11
12#import <FBReactNativeSpec/FBReactNativeSpec.h>
13#import <React/RCTUtils.h>
14#import <React/RCTVersion.h>
15
16#import "CoreModulesPlugins.h"
17
18using namespace facebook::react;
19
20static NSString *interfaceIdiom(UIUserInterfaceIdiom idiom) {
21 switch(idiom) {
22 case UIUserInterfaceIdiomPhone:
23 return @"phone";
24 case UIUserInterfaceIdiomPad:
25 return @"pad";
26 case UIUserInterfaceIdiomTV:
27 return @"tv";
28 case UIUserInterfaceIdiomCarPlay:
29 return @"carplay";
30 default:
31 return @"unknown";
32 }
33}
34
35@interface RCTPlatform () <NativePlatformConstantsIOSSpec>
36@end
37
38@implementation RCTPlatform
39
40RCT_EXPORT_MODULE(PlatformConstants)
41
42+ (BOOL)requiresMainQueueSetup
43{
44 return YES;
45}
46
47- (dispatch_queue_t)methodQueue
48{
49 return dispatch_get_main_queue();
50}
51
52// TODO: Use the generated struct return type.
53- (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)constantsToExport
54{
55 return (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)[self getConstants];
56}
57
58- (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)getConstants
59{
60 UIDevice *device = [UIDevice currentDevice];
61 auto versions = RCTGetReactNativeVersion();
62 return typedConstants<JS::NativePlatformConstantsIOS::Constants>({
63 .forceTouchAvailable = RCTForceTouchAvailable() ? true : false,
64 .osVersion = [device systemVersion],
65 .systemName = [device systemName],
66 .interfaceIdiom = interfaceIdiom([device userInterfaceIdiom]),
67 .isTesting = RCTRunningInTestEnvironment() ? true : false,
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 });
75}
76
77- (std::shared_ptr<TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<JSCallInvoker>)jsInvoker
78{
79 return std::make_shared<NativePlatformConstantsIOSSpecJSI>(self, jsInvoker);
80}
81
82@end
83
84Class RCTPlatformCls(void) {
85 return RCTPlatform.class;
86}