diff --git a/pedi-foods/Sources/PediFoods/Support/PlatformCompat.swift b/pedi-foods/Sources/PediFoods/Support/PlatformCompat.swift index d14337d..3169da4 100644 --- a/pedi-foods/Sources/PediFoods/Support/PlatformCompat.swift +++ b/pedi-foods/Sources/PediFoods/Support/PlatformCompat.swift @@ -15,24 +15,49 @@ import UIKit import AppKit #endif -#if !canImport(UIKit) -struct UIDevice { - static let topNotch = 0.0 - static let bottomNotch = 0.0 - - var modelName: String { - "android" +#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 } } -#endif - -#if !(canImport(LCEssentials) && os(iOS)) -func printLog(title: String, msg: String) { - print("[\(title)] \(msg)") +#else +struct UIDevice { + static let topNotch: CGFloat = 0.0 + static let bottomNotch: CGFloat = 0.0 + static let appSafeAreaTop: CGFloat = 0.0 + var modelName: String { "mac" } } -func printError(title: String, msg: String) { - print("[\(title)] \(msg)") +enum UIKeyboardType: Int { + 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 @@ -41,8 +66,6 @@ func appReadClipboardText() -> String? { return UIPasteboard.general.string #elseif canImport(AppKit) return NSPasteboard.general.string(forType: .string) -#elseif os(Android) - return UIPasteboard.general.string #else return nil #endif @@ -54,8 +77,6 @@ func appWriteClipboardText(_ value: String) { #elseif canImport(AppKit) NSPasteboard.general.clearContents() NSPasteboard.general.setString(value, forType: .string) -#elseif os(Android) - UIPasteboard.general.string = value #else _ = value #endif @@ -103,42 +124,24 @@ extension View { @ViewBuilder func appContentShape(_ shape: S) -> some View { -#if os(Android) - self -#else self.contentShape(shape) -#endif } @ViewBuilder func appBottomSafeAreaInset(@ViewBuilder content: () -> Content) -> some View { -#if os(Android) - self.overlay(alignment: .bottom) { - content() - } -#else self.safeAreaInset(edge: .bottom) { content() } -#endif } @ViewBuilder func appLayoutPriority(_ value: Double) -> some View { -#if os(Android) - self -#else self.layoutPriority(value) -#endif } @ViewBuilder func appNamedCoordinateSpace(_ name: String) -> some View { -#if os(Android) - self -#else self.coordinateSpace(name: name) -#endif } }