#import "RNCSafeAreaContext.h" #import #import #ifdef RCT_NEW_ARCH_ENABLED #import #endif #ifdef RCT_NEW_ARCH_ENABLED 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; } #ifdef RCT_NEW_ARCH_ENABLED - (std::shared_ptr)getTurboModule:(const ObjCTurboModule::InitParams &)params { return std::make_shared(params); } #endif @end