10
10
#import < UIKit/UIKit.h>
11
11
12
12
#import < FBReactNativeSpec/FBReactNativeSpec.h>
13
+ #import < React/RCTInitializing.h>
13
14
#import < React/RCTUtils.h>
14
15
#import < React/RCTVersion.h>
15
16
39
40
}
40
41
}
41
42
42
- @interface RCTPlatform () <NativePlatformConstantsIOSSpec>
43
+ @interface RCTPlatform () <NativePlatformConstantsIOSSpec, RCTInitializing >
43
44
@end
44
45
45
- @implementation RCTPlatform
46
+ @implementation RCTPlatform {
47
+ ModuleConstants<JS::NativePlatformConstantsIOS::Constants> _constants;
48
+ }
46
49
47
50
RCT_EXPORT_MODULE (PlatformConstants)
48
51
@@ -51,6 +54,29 @@ + (BOOL)requiresMainQueueSetup
51
54
return YES ;
52
55
}
53
56
57
+ - (void )initialize
58
+ {
59
+ UIDevice *device = [UIDevice currentDevice ];
60
+ auto versions = RCTGetReactNativeVersion ();
61
+ _constants = typedConstants<JS::NativePlatformConstantsIOS::Constants>({
62
+ .forceTouchAvailable = RCTForceTouchAvailable () ? true : false ,
63
+ .osVersion = [device systemVersion ],
64
+ .systemName = [device systemName ],
65
+ .interfaceIdiom = interfaceIdiom ([device userInterfaceIdiom ]),
66
+ .isTesting = RCTRunningInTestEnvironment () ? true : false ,
67
+ .reactNativeVersion = JS::NativePlatformConstantsIOS::ConstantsReactNativeVersion::Builder (
68
+ {.minor = [versions[@" minor" ] doubleValue ],
69
+ .major = [versions[@" major" ] doubleValue ],
70
+ .patch = [versions[@" patch" ] doubleValue ],
71
+ .prerelease = [versions[@" prerelease" ] isKindOfClass: [NSNull class ]] ? nullptr : versions[@" prerelease" ]}),
72
+ #if TARGET_OS_MACCATALYST
73
+ .isMacCatalyst = true ,
74
+ #else
75
+ .isMacCatalyst = false ,
76
+ #endif
77
+ });
78
+ }
79
+
54
80
- (dispatch_queue_t )methodQueue
55
81
{
56
82
return dispatch_get_main_queue ();
@@ -59,35 +85,12 @@ - (dispatch_queue_t)methodQueue
59
85
// TODO: Use the generated struct return type.
60
86
- (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)constantsToExport
61
87
{
62
- return (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)[ self getConstants ] ;
88
+ return _constants ;
63
89
}
64
90
65
91
- (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)getConstants
66
92
{
67
- __block ModuleConstants<JS::NativePlatformConstantsIOS::Constants> constants;
68
- RCTUnsafeExecuteOnMainQueueSync (^{
69
- UIDevice *device = [UIDevice currentDevice ];
70
- auto versions = RCTGetReactNativeVersion ();
71
- constants = typedConstants<JS::NativePlatformConstantsIOS::Constants>({
72
- .forceTouchAvailable = RCTForceTouchAvailable () ? true : false ,
73
- .osVersion = [device systemVersion ],
74
- .systemName = [device systemName ],
75
- .interfaceIdiom = interfaceIdiom ([device userInterfaceIdiom ]),
76
- .isTesting = RCTRunningInTestEnvironment () ? true : false ,
77
- .reactNativeVersion = JS::NativePlatformConstantsIOS::ConstantsReactNativeVersion::Builder (
78
- {.minor = [versions[@" minor" ] doubleValue ],
79
- .major = [versions[@" major" ] doubleValue ],
80
- .patch = [versions[@" patch" ] doubleValue ],
81
- .prerelease = [versions[@" prerelease" ] isKindOfClass: [NSNull class ]] ? nullptr : versions[@" prerelease" ]}),
82
- #if TARGET_OS_MACCATALYST
83
- .isMacCatalyst = true ,
84
- #else
85
- .isMacCatalyst = false ,
86
- #endif
87
- });
88
- });
89
-
90
- return constants;
93
+ return _constants;
91
94
}
92
95
93
96
- (std::shared_ptr<TurboModule>)getTurboModule : (const ObjCTurboModule::InitParams &)params
0 commit comments