jellyflood/Shared/Coordinators/Tabs/MainTabView.swift

60 lines
1.8 KiB
Swift

//
// Swiftfin is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2025 Jellyfin & Jellyfin Contributors
//
import Factory
import SwiftUI
// TODO: move popup to router
// - or, make tab view environment object
// TODO: fix weird tvOS icon rendering
struct MainTabView: View {
@Injected(\.sessionManager)
private var sessionManager
@StateObject
private var tabCoordinator: TabCoordinator
init() {
let sessionManager = Container.shared.sessionManager()
_tabCoordinator = StateObject(wrappedValue: TabCoordinator(sessionManager: sessionManager))
}
@ViewBuilder
var body: some View {
TabView(selection: $tabCoordinator.selectedTabID) {
ForEach(tabCoordinator.tabs, id: \.item.id) { tab in
NavigationInjectionView(
coordinator: tab.coordinator
) {
tab.item.content
}
.environmentObject(tabCoordinator)
.environment(\.tabItemSelected, tab.publisher)
.tabItem {
Label(
tab.item.title,
systemImage: tab.item.systemImage
)
.labelStyle(tab.item.labelStyle)
.symbolRenderingMode(.monochrome)
.eraseToAnyView()
}
.tag(tab.item.id)
}
}
.onReceive(sessionManager.$jellyfinSession) { _ in
tabCoordinator.refreshTabs()
}
.onReceive(sessionManager.$xtreamSession) { _ in
tabCoordinator.refreshTabs()
}
}
}