You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.6 KiB

#import "RNCSafeAreaContext.h"
#if __has_include(<safeareacontext/safeareacontext.h>)
#define RCT_USE_CODEGEN 1
#else
#define RCT_USE_CODEGEN 0
#endif
#import <React/RCTUtils.h>
#import <UIKit/UIKit.h>
#if RCT_USE_CODEGEN
#import <safeareacontext/safeareacontext.h>
#endif
#if RCT_USE_CODEGEN
using namespace facebook::react;
@interface RNCSafeAreaContext () <NativeSafeAreaContextSpec>
@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<TurboModule>)getTurboModule:(const ObjCTurboModule::InitParams &)params
{
return std::make_shared<NativeSafeAreaContextSpecJSI>(params);
}
#endif
@end