fix(android): isolate platform-specific shared ui code
This commit is contained in:
72
pedi-foods/Sources/PediFoods/Support/PlatformCompat.swift
Normal file
72
pedi-foods/Sources/PediFoods/Support/PlatformCompat.swift
Normal file
@@ -0,0 +1,72 @@
|
||||
import Foundation
|
||||
#if canImport(SwiftUI)
|
||||
import SwiftUI
|
||||
#endif
|
||||
|
||||
#if canImport(CoreGraphics)
|
||||
import CoreGraphics
|
||||
#endif
|
||||
|
||||
#if canImport(UIKit)
|
||||
import UIKit
|
||||
#endif
|
||||
|
||||
#if !canImport(UIKit)
|
||||
struct UIDevice {
|
||||
static let topNotch: CGFloat = 0
|
||||
static let bottomNotch: CGFloat = 0
|
||||
|
||||
var modelName: String {
|
||||
"android"
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !(canImport(LCEssentials) && os(iOS))
|
||||
func printLog(title: String, msg: String) {
|
||||
print("[\(title)] \(msg)")
|
||||
}
|
||||
|
||||
func printError(title: String, msg: String) {
|
||||
print("[\(title)] \(msg)")
|
||||
}
|
||||
#endif
|
||||
|
||||
extension View {
|
||||
@ViewBuilder
|
||||
func appInlineNavigationTitle() -> some View {
|
||||
#if os(macOS)
|
||||
self
|
||||
#else
|
||||
self.navigationBarTitleDisplayMode(.inline)
|
||||
#endif
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
func appHiddenNavigationBar() -> some View {
|
||||
#if os(macOS)
|
||||
self
|
||||
#else
|
||||
self
|
||||
.toolbar(.hidden, for: .navigationBar)
|
||||
.toolbarBackground(.hidden, for: .navigationBar)
|
||||
#endif
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
func appTopBarTrailingToolbar<Content: View>(@ViewBuilder content: () -> Content) -> some View {
|
||||
#if os(macOS)
|
||||
self.toolbar {
|
||||
ToolbarItem {
|
||||
content()
|
||||
}
|
||||
}
|
||||
#else
|
||||
self.toolbar {
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
content()
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user