RNCSafeAreaViewManager.m 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #import "RNCSafeAreaViewManager.h"
  2. #import "RNCSafeAreaView.h"
  3. @implementation RNCSafeAreaViewManager
  4. RCT_EXPORT_MODULE(RNCSafeAreaView)
  5. RCT_EXPORT_VIEW_PROPERTY(onInsetsChange, RCTBubblingEventBlock)
  6. + (BOOL)requiresMainQueueSetup
  7. {
  8. return YES;
  9. }
  10. - (UIView *)view
  11. {
  12. return [RNCSafeAreaView new];
  13. }
  14. - (NSDictionary *)constantsToExport
  15. {
  16. if (@available(iOS 11.0, *)) {
  17. UIWindow* window = [[UIApplication sharedApplication] keyWindow];
  18. UIEdgeInsets safeAreaInsets = window.safeAreaInsets;
  19. return @{
  20. @"initialWindowMetrics": @{
  21. @"insets": @{
  22. @"top": @(safeAreaInsets.top),
  23. @"right": @(safeAreaInsets.right),
  24. @"bottom": @(safeAreaInsets.bottom),
  25. @"left": @(safeAreaInsets.left),
  26. },
  27. @"frame": @{
  28. @"x": @(window.frame.origin.x),
  29. @"y": @(window.frame.origin.y),
  30. @"width": @(window.frame.size.width),
  31. @"height": @(window.frame.size.height),
  32. },
  33. }
  34. };
  35. } else {
  36. return @{ @"initialWindowSafeAreaInsets": [NSNull null] };
  37. }
  38. }
  39. @end