#import "RNCSafeAreaContext.h" #if __has_include() #define RCT_USE_CODEGEN 1 #else #define RCT_USE_CODEGEN 0 #endif #import #import #if RCT_USE_CODEGEN #import #endif #if RCT_USE_CODEGEN using namespace facebook::react; @interface RNCSafeAreaContext () @end #endif @implementation RNCSafeAreaContext RCT_EXPORT_MODULE() + (BOOL)requiresMainQueueSetup { return YES; } - (NSDictionary *)constantsToExport { return [self getConstants]; } - (NSDictionary *)getConstants { __block NSDictionary *constants; RCTUnsafeExecuteOnMainQueueSync(^{ UIWindow *window = RCTKeyWindow(); if (window == nil) { constants = @{@"initialWindowMetrics" : [NSNull null]}; return; } UIEdgeInsets safeAreaInsets = window.safeAreaInsets; constants = @{ @"initialWindowMetrics" : @{ @"insets" : @{ @"top" : @(safeAreaInsets.top), @"right" : @(safeAreaInsets.right), @"bottom" : @(safeAreaInsets.bottom), @"left" : @(safeAreaInsets.left), }, @"frame" : @{ @"x" : @(window.frame.origin.x), @"y" : @(window.frame.origin.y), @"width" : @(window.frame.size.width), @"height" : @(window.frame.size.height), }, } }; }); return constants; } #if RCT_USE_CODEGEN - (std::shared_ptr)getTurboModule:(const ObjCTurboModule::InitParams &)params { return std::make_shared(params); } #endif @end