1010#import  < UIKit/UIKit.h> 
1111
1212#import  < FBReactNativeSpec/FBReactNativeSpec.h> 
13+ #import  < React/RCTInitializing.h> 
1314#import  < React/RCTUtils.h> 
1415#import  < React/RCTVersion.h> 
1516
3940  }
4041}
4142
42- @interface  RCTPlatform  () <NativePlatformConstantsIOSSpec>
43+ @interface  RCTPlatform  () <NativePlatformConstantsIOSSpec, RCTInitializing >
4344@end 
4445
45- @implementation  RCTPlatform 
46+ @implementation  RCTPlatform  {
47+   ModuleConstants<JS::NativePlatformConstantsIOS::Constants> _constants;
48+ }
4649
4750RCT_EXPORT_MODULE (PlatformConstants)
4851
@@ -51,6 +54,29 @@ + (BOOL)requiresMainQueueSetup
5154  return  YES ;
5255}
5356
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+ 
5480- (dispatch_queue_t )methodQueue 
5581{
5682  return  dispatch_get_main_queue ();
@@ -59,35 +85,12 @@ - (dispatch_queue_t)methodQueue
5985//  TODO: Use the generated struct return type.
6086- (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)constantsToExport 
6187{
62-   return  (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)[ self   getConstants ] ;
88+   return  _constants ;
6389}
6490
6591- (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)getConstants 
6692{
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;
9194}
9295
9396- (std::shared_ptr<TurboModule>)getTurboModule : (const  ObjCTurboModule::InitParams &)params 
0 commit comments