UIScreen+screenSize.swift (1679B)
1 /* 2 * This file is part of GNU Taler, ©2022-25 Taler Systems S.A. 3 * See LICENSE.md 4 */ 5 /** 6 * @author Marc Stibane 7 */ 8 import SwiftUI 9 10 extension UIScreen { 11 static var screenWidth: CGFloat { UIScreen.main.bounds.size.width } 12 static var screenHeight: CGFloat { UIScreen.main.bounds.size.height } 13 static var screenSize: CGSize { UIScreen.main.bounds.size } 14 static var hasFaceID: Bool { 15 let size = screenSize // aspect ratio is 2.16 16 if size.width > size.height { // landscape 17 return size.width/size.height > 2 18 } else { // portrait 19 return size.height/size.width > 2 20 } 21 } 22 static var hasTouchID: Bool { 23 let size = screenSize // aspect ratio is 1.77 24 if size.width > size.height { // landscape 25 return size.width/size.height < 2 26 } else { // portrait 27 return size.height/size.width < 2 28 } 29 } 30 static var hasNotch: Bool { 31 let insets = UIApplication.shared.keyWindow?.safeAreaInsets 32 let bottom = insets?.bottom ?? 0 33 return bottom > 0 34 } 35 static var hasIsland: Bool { 36 let insets = UIApplication.shared.keyWindow?.safeAreaInsets 37 let left = insets?.left ?? 0 38 let bottom = insets?.bottom ?? 0 39 /// Portrait: 15PM 59,0,34 XS 38,0,29 8plus 20,0,0 40 /// Landscape: 0,59,21 0,38,21 0,0,0 41 return bottom > 30 || left > 50 42 } 43 static var horzInsets: CGFloat { 44 let insets = UIApplication.shared.keyWindow?.safeAreaInsets 45 let left = insets?.left ?? 0 46 return left 47 } 48 }