fix(store): scan all window scenes and fallback to app windows to reliably calculate appSafeAreaTop
This commit is contained in:
@@ -15,24 +15,49 @@ import UIKit
|
|||||||
import AppKit
|
import AppKit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !canImport(UIKit)
|
#if canImport(UIKit)
|
||||||
|
extension UIDevice {
|
||||||
|
static var appSafeAreaTop: CGFloat {
|
||||||
|
let scenes = UIApplication.shared.connectedScenes
|
||||||
|
.compactMap { $0 as? UIWindowScene }
|
||||||
|
let windows = scenes.flatMap { $0.windows }
|
||||||
|
if let maxTop = windows.map({ $0.safeAreaInsets.top }).max(), maxTop > 0 {
|
||||||
|
return maxTop
|
||||||
|
}
|
||||||
|
if let fallbackMaxTop = UIApplication.shared.windows.map({ $0.safeAreaInsets.top }).max(), fallbackMaxTop > 0 {
|
||||||
|
return fallbackMaxTop
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
struct UIDevice {
|
struct UIDevice {
|
||||||
static let topNotch = 0.0
|
static let topNotch: CGFloat = 0.0
|
||||||
static let bottomNotch = 0.0
|
static let bottomNotch: CGFloat = 0.0
|
||||||
|
static let appSafeAreaTop: CGFloat = 0.0
|
||||||
var modelName: String {
|
var modelName: String { "mac" }
|
||||||
"android"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !(canImport(LCEssentials) && os(iOS))
|
|
||||||
func printLog(title: String, msg: String) {
|
|
||||||
print("[\(title)] \(msg)")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func printError(title: String, msg: String) {
|
enum UIKeyboardType: Int {
|
||||||
print("[\(title)] \(msg)")
|
case `default` = 0
|
||||||
|
case asciiCapable = 1
|
||||||
|
case numbersAndPunctuation = 2
|
||||||
|
case URL = 3
|
||||||
|
case numberPad = 4
|
||||||
|
case phonePad = 10
|
||||||
|
case namePhonePad = 9
|
||||||
|
case emailAddress = 7
|
||||||
|
case decimalPad = 8
|
||||||
|
case twitter = 12
|
||||||
|
case webSearch = 13
|
||||||
|
case asciiCapableNumberPad = 14
|
||||||
|
}
|
||||||
|
|
||||||
|
extension View {
|
||||||
|
@ViewBuilder
|
||||||
|
func keyboardType(_ type: UIKeyboardType) -> some View {
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -41,8 +66,6 @@ func appReadClipboardText() -> String? {
|
|||||||
return UIPasteboard.general.string
|
return UIPasteboard.general.string
|
||||||
#elseif canImport(AppKit)
|
#elseif canImport(AppKit)
|
||||||
return NSPasteboard.general.string(forType: .string)
|
return NSPasteboard.general.string(forType: .string)
|
||||||
#elseif os(Android)
|
|
||||||
return UIPasteboard.general.string
|
|
||||||
#else
|
#else
|
||||||
return nil
|
return nil
|
||||||
#endif
|
#endif
|
||||||
@@ -54,8 +77,6 @@ func appWriteClipboardText(_ value: String) {
|
|||||||
#elseif canImport(AppKit)
|
#elseif canImport(AppKit)
|
||||||
NSPasteboard.general.clearContents()
|
NSPasteboard.general.clearContents()
|
||||||
NSPasteboard.general.setString(value, forType: .string)
|
NSPasteboard.general.setString(value, forType: .string)
|
||||||
#elseif os(Android)
|
|
||||||
UIPasteboard.general.string = value
|
|
||||||
#else
|
#else
|
||||||
_ = value
|
_ = value
|
||||||
#endif
|
#endif
|
||||||
@@ -103,42 +124,24 @@ extension View {
|
|||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
func appContentShape<S: Shape>(_ shape: S) -> some View {
|
func appContentShape<S: Shape>(_ shape: S) -> some View {
|
||||||
#if os(Android)
|
|
||||||
self
|
|
||||||
#else
|
|
||||||
self.contentShape(shape)
|
self.contentShape(shape)
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
func appBottomSafeAreaInset<Content: View>(@ViewBuilder content: () -> Content) -> some View {
|
func appBottomSafeAreaInset<Content: View>(@ViewBuilder content: () -> Content) -> some View {
|
||||||
#if os(Android)
|
|
||||||
self.overlay(alignment: .bottom) {
|
|
||||||
content()
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
self.safeAreaInset(edge: .bottom) {
|
self.safeAreaInset(edge: .bottom) {
|
||||||
content()
|
content()
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
func appLayoutPriority(_ value: Double) -> some View {
|
func appLayoutPriority(_ value: Double) -> some View {
|
||||||
#if os(Android)
|
|
||||||
self
|
|
||||||
#else
|
|
||||||
self.layoutPriority(value)
|
self.layoutPriority(value)
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
func appNamedCoordinateSpace(_ name: String) -> some View {
|
func appNamedCoordinateSpace(_ name: String) -> some View {
|
||||||
#if os(Android)
|
|
||||||
self
|
|
||||||
#else
|
|
||||||
self.coordinateSpace(name: name)
|
self.coordinateSpace(name: name)
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user