SPB Git

Repository Public

RootView.swift 3.4 KB 96 lines swift

1//2//  Food-Ka iOS v23//  File: FoodKa/App/RootView.swift4//  Description: onglets adaptatifs (barre d'onglets sur iPhone, barre latérale sur iPad) et destinations partagées.5//6//  Author: Simon-Pierre Boucher7//  Contact: contact@spboucher.ai8//910import SwiftUI1112struct RootView: View {13    @Environment(AppModel.self) private var model14    @Environment(GroceryList.self) private var list15    @Environment(Library.self) private var library1617    var body: some View {18        @Bindable var model = model19        TabView(selection: $model.tab) {20            Tab("Accueil", image: "ic-tablette", value: AppTab.home) {21                stack(.home) { HomeView() }22            }23            Tab("Soldes", image: "ic-solde-verifie", value: AppTab.deals) {24                stack(.deals) { DealsView() }25            }26            Tab("Liste", image: "ic-panier", value: AppTab.basket) {27                stack(.basket) { BasketView() }28            }29            .badge(list.remaining)30            Tab("Marché", image: "ic-historique", value: AppTab.market) {31                stack(.market) { MarketView() }32            }33            Tab("Suivis", image: "ic-favori", value: AppTab.followed) {34                stack(.followed) { FollowedView() }35            }36            .badge(library.drops.count)37        }38        .tabViewStyle(.sidebarAdaptable)39        .overlay(alignment: .bottom) { toast }40        .animation(.snappy, value: model.toast)41        .fullScreenCover(isPresented: $model.storeMode) {42            StoreModeView()43                .environment(model).environment(list)44                .preferredColorScheme(model.appearance.scheme)45        }46    }4748    private func stack<Content: View>(_ tab: AppTab, @ViewBuilder _ content: () -> Content) -> some View {49        NavigationStack(path: model.path(for: tab)) {50            content()51                .navigationDestination(for: Route.self) { route in52                    destination(route)53                }54        }55    }5657    @ViewBuilder58    private func destination(_ route: Route) -> some View {59        switch route {60        case .product(let id): ProductView(id: id)61        case .search(let f): SearchView(filters: f)62        case .categories: CategoriesView()63        case .deals: DealsView(root: false)64        case .flyers: FlyersView()65        case .flyer(let store): FlyerView(store: store)66        case .stores: StoresView()67        case .store(let id): StoreView(id: id)68        case .index: IndexView()69        case .movements: MovementsView()70        case .recents: RecentsView()71        case .settings: SettingsView()72        case .about: AboutView()73        case .privacy: PrivacyView()74        case .method: MethodView()75        }76    }7778    @ViewBuilder79    private var toast: some View {80        if let text = model.toast {81            HStack(spacing: 10) {82                BrandSymbol(style: .mono(Theme.bg)).frame(width: 18, height: 18)83                Text(text)84            }85            .font(.subheadline.weight(.medium))86            .foregroundStyle(Theme.bg)87            .padding(.horizontal, 16).padding(.vertical, 12)88            .background(Theme.ink, in: RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))89            .padding(.bottom, 72)90            .transition(.move(edge: .bottom).combined(with: .opacity))91            .accessibilityAddTraits(.isStaticText)92            .accessibilityIdentifier("toast")93        }94    }95}96
Files main
Menu

Theme