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
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ struct TermsOfUseView: View {
|
||||
.background((colorScheme == .dark ? Color.black : AppColors.backgroundLight).ignoresSafeArea())
|
||||
.navigationTitle("Termos de Uso")
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.appInlineNavigationTitle()
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ struct PrivacyPolicyView: View {
|
||||
.background((colorScheme == .dark ? Color.black : AppColors.backgroundLight).ignoresSafeArea())
|
||||
.navigationTitle("Privacidade")
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.appInlineNavigationTitle()
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ struct AddAddressFormView: View {
|
||||
.padding(.top, 0)
|
||||
}
|
||||
.navigationBarBackButtonHidden(true)
|
||||
.toolbar(.hidden, for: .navigationBar)
|
||||
.appHiddenNavigationBar()
|
||||
.onAppear {
|
||||
populateFromExistingAddressIfNeeded()
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ struct AddressesView: View {
|
||||
|
||||
}
|
||||
.navigationBarBackButtonHidden(true)
|
||||
.toolbar(.hidden, for: .navigationBar)
|
||||
.appHiddenNavigationBar()
|
||||
.sheet(isPresented: $openAddAddressForm) {
|
||||
NavigationStack {
|
||||
AddAddressFormView(existingAddress: editingAddress) { updatedAddresses, wasEditing in
|
||||
|
||||
@@ -119,7 +119,7 @@ struct CheckoutView: View {
|
||||
}
|
||||
.background(AppColors.backgroundLight)
|
||||
.navigationTitle("Finalizar Pedido")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.appInlineNavigationTitle()
|
||||
.safeAreaInset(edge: .bottom) {
|
||||
bottomBar
|
||||
}
|
||||
@@ -659,7 +659,7 @@ struct PaymentPixView: View {
|
||||
}
|
||||
.background(AppColors.backgroundLight)
|
||||
.navigationTitle("Pagamento via PIX")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.appInlineNavigationTitle()
|
||||
.task {
|
||||
tracker.onOrderUpdated = { updated in
|
||||
latestOrder = updated
|
||||
@@ -851,7 +851,7 @@ struct PaymentCardView: View {
|
||||
}
|
||||
.background(AppColors.backgroundLight)
|
||||
.navigationTitle("Pagamento")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.appInlineNavigationTitle()
|
||||
.task {
|
||||
tracker.onOrderUpdated = { updated in
|
||||
latestOrder = updated
|
||||
@@ -879,8 +879,7 @@ struct PaymentCardView: View {
|
||||
.font(AppTypography.caption)
|
||||
.foregroundStyle(AppColors.textMuted)
|
||||
TextField(placeholder, text: text)
|
||||
.textInputAutocapitalization(.never)
|
||||
.disableAutocorrection(true)
|
||||
.appNoAutoCap()
|
||||
.padding(.horizontal, 12)
|
||||
.frame(height: 46)
|
||||
.background(AppColors.backgroundLight)
|
||||
|
||||
@@ -23,7 +23,7 @@ struct OrderDetailsView: View {
|
||||
}
|
||||
.background(AppColors.backgroundLight)
|
||||
.navigationTitle("Detalhes do Pedido")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.appInlineNavigationTitle()
|
||||
.safeAreaInset(edge: .bottom) {
|
||||
VStack {
|
||||
reorderButton
|
||||
|
||||
@@ -43,7 +43,7 @@ struct OrderTrackingView: View {
|
||||
}
|
||||
.background(AppColors.backgroundLight)
|
||||
.navigationTitle("Pedido \(displayOrderTitle)")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.appInlineNavigationTitle()
|
||||
.alert("Motivo do cancelamento", isPresented: $showCancellationReason) {
|
||||
Button("Fechar", role: .cancel) {}
|
||||
} message: {
|
||||
|
||||
@@ -39,7 +39,7 @@ struct OrdersView: View {
|
||||
}
|
||||
.background(AppColors.backgroundLight)
|
||||
.navigationTitle("Meus Pedidos")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.appInlineNavigationTitle()
|
||||
.task {
|
||||
await loadOrdersIfNeeded()
|
||||
await refreshStoreRatings()
|
||||
|
||||
@@ -78,12 +78,10 @@ struct PizzaFlavorAddonsSheet: View {
|
||||
}
|
||||
.background(AppColors.backgroundLight.ignoresSafeArea())
|
||||
.navigationTitle("Adicionais")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
Button("Concluir") { dismiss() }
|
||||
.foregroundStyle(AppColors.primary)
|
||||
}
|
||||
.appInlineNavigationTitle()
|
||||
.appTopBarTrailingToolbar {
|
||||
Button("Concluir") { dismiss() }
|
||||
.foregroundStyle(AppColors.primary)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -292,12 +292,10 @@ struct PizzaProductDetailSheet: View {
|
||||
}
|
||||
.background(AppColors.backgroundLight.ignoresSafeArea())
|
||||
.navigationTitle("Monte sua pizza")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
Button("Fechar") { dismiss() }
|
||||
.foregroundStyle(AppColors.primary)
|
||||
}
|
||||
.appInlineNavigationTitle()
|
||||
.appTopBarTrailingToolbar {
|
||||
Button("Fechar") { dismiss() }
|
||||
.foregroundStyle(AppColors.primary)
|
||||
}
|
||||
.onAppear {
|
||||
applyAutoSelections()
|
||||
|
||||
@@ -222,12 +222,10 @@ struct ProductDetailSheet: View {
|
||||
}
|
||||
.background(AppColors.backgroundLight.ignoresSafeArea())
|
||||
.navigationTitle("Detalhes")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
Button("Fechar") { dismiss() }
|
||||
.foregroundStyle(AppColors.primary)
|
||||
}
|
||||
.appInlineNavigationTitle()
|
||||
.appTopBarTrailingToolbar {
|
||||
Button("Fechar") { dismiss() }
|
||||
.foregroundStyle(AppColors.primary)
|
||||
}
|
||||
.onAppear {
|
||||
let existing = currentQuantityForItemId(cartItemId)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import SwiftUI
|
||||
#if canImport(LCEssentials) && os(iOS)
|
||||
import LCEssentials
|
||||
#endif
|
||||
#if canImport(UIKit)
|
||||
import UIKit
|
||||
#endif
|
||||
|
||||
@@ -67,7 +67,7 @@ struct MyReviewsView: View {
|
||||
}
|
||||
.background(AppColors.backgroundLight)
|
||||
.navigationTitle("Minhas Avaliações")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.appInlineNavigationTitle()
|
||||
.navigationDestination(item: $selectedDraft) { draft in
|
||||
OrderReviewView(draft: draft) {
|
||||
Task { await loadReviewsFromBackend(forceRefresh: true) }
|
||||
@@ -451,7 +451,7 @@ struct OrderReviewView: View {
|
||||
}
|
||||
.background(AppColors.backgroundLight)
|
||||
.navigationTitle("Avaliar Pedido")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.appInlineNavigationTitle()
|
||||
.onAppear {
|
||||
if let cachedReview = SessionStateStore.loadOrderReview(orderId: draft.orderId) {
|
||||
existingReview = cachedReview
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import SwiftUI
|
||||
#if canImport(LCEssentials) && os(iOS)
|
||||
import LCEssentials
|
||||
#endif
|
||||
#if canImport(UIKit)
|
||||
import UIKit
|
||||
#endif
|
||||
@@ -74,8 +76,7 @@ struct StoreDetailView: View {
|
||||
}
|
||||
}
|
||||
.navigationBarBackButtonHidden(true)
|
||||
.toolbar(.hidden, for: .navigationBar)
|
||||
.toolbarBackground(.hidden, for: .navigationBar)
|
||||
.appHiddenNavigationBar()
|
||||
.task {
|
||||
guard didLoad == false else { return }
|
||||
didLoad = true
|
||||
|
||||
@@ -33,7 +33,7 @@ struct UserProfileView: View {
|
||||
}
|
||||
.background(AppColors.backgroundLight)
|
||||
.navigationTitle("Meu Perfil")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.appInlineNavigationTitle()
|
||||
.onAppear {
|
||||
hydrateFromAppState()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user