Created
January 12, 2021 21:26
-
-
Save schwjustin/f51a0d921b7b8e064005d8e85cce288d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import UIKit | |
var hasTopNotch: Bool { | |
if #available(iOS 11.0, *) { | |
// with notch: 44.0 on iPhone X, XS, XS Max, XR. | |
// without notch: 24.0 on iPad Pro 12.9" 3rd generation, 20.0 on iPhone 8 on iOS 12+. | |
return UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.safeAreaInsets.top ?? 0 > 24 | |
} else{ | |
return UIApplication.shared.delegate?.window??.safeAreaInsets.top ?? 0 > 24 | |
} | |
} | |
let top: CGFloat = hasTopNotch ? 44 : 24 | |
var hasBottomSafeAreaInsets: Bool { | |
if #available(iOS 11.0, *) { | |
// with home indicator: 34.0 on iPhone X, XS, XS Max, XR. | |
// with home indicator: 20.0 on iPad Pro 12.9" 3rd generation. | |
return UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.safeAreaInsets.bottom ?? 0 > 0 | |
} else { | |
return UIApplication.shared.delegate?.window??.safeAreaInsets.bottom ?? 0 > 0 | |
} | |
} | |
let bottom: CGFloat = hasBottomSafeAreaInsets ? 34 : 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment