yattee/Shared/SafeArea.swift

26 lines
601 B
Swift
Raw Normal View History

2022-08-07 12:11:57 +00:00
import Foundation
import UIKit
struct SafeArea {
static var insets: UIEdgeInsets {
2022-08-13 14:12:45 +00:00
let keyWindow = scene?.windows.first { $0.isKeyWindow }
2022-08-07 12:11:57 +00:00
return keyWindow?.safeAreaInsets ?? .init()
}
2022-08-13 14:12:45 +00:00
2022-08-31 22:41:31 +00:00
static var verticalInset: Double {
insets.top + insets.bottom
}
static var horizontalInsets: Double {
insets.left + insets.right
}
2022-08-13 14:12:45 +00:00
static var scene: UIWindowScene? {
UIApplication.shared.connectedScenes
2022-08-13 14:46:45 +00:00
.filter { $0.activationState == .foregroundActive }
.compactMap { $0 as? UIWindowScene }
.first
2022-08-13 14:12:45 +00:00
}
2022-08-07 12:11:57 +00:00
}