1 import ExpoModulesCore 2 3 public class RNCSafeAreaProviderManager: Module { 4 public func definition() -> ModuleDefinition { 5 Name("RNCSafeAreaProvider") 6 Constants([ 7 "initialWindowMetrics": self.initialWindowMetrics 8 ]) 9 10 View(SafeAreaProvider.self) { 11 Events("onInsetsChange") 12 } 13 } 14 15 private var initialWindowMetrics: [String: Any]? { 16 guard let window = UIApplication.shared.keyWindow else { 17 return [:] 18 } 19 20 if #available(iOS 11.0, *) { 21 let safeAreaInsets = window.safeAreaInsets 22 23 return [ 24 "insets": [ 25 "top": safeAreaInsets.top, 26 "right": safeAreaInsets.right, 27 "bottom": safeAreaInsets.bottom, 28 "left": safeAreaInsets.left 29 ], 30 "frame": [ 31 "x": window.frame.origin.x, 32 "y": window.frame.origin.y, 33 "width": window.frame.size.width, 34 "height": window.frame.size.height 35 ] 36 ] 37 } 38 39 return [ 40 "insets": [ 41 "top": 20, 42 "right": 0, 43 "bottom": 0, 44 "left": 0 45 ], 46 "frame": [ 47 "x": window.frame.origin.x, 48 "y": window.frame.origin.y, 49 "width": window.frame.size.width, 50 "height": window.frame.size.height 51 ] 52 ] 53 } 54 } 55