jellyflood/JellyfinPlayer tvOS/MainTabView.swift

76 lines
2.4 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 2021 Aiden Vigue & Jellyfin Contributors
*/
import Foundation
import SwiftUI
struct MainTabView: View {
@State private var tabSelection: Tab = .home
@StateObject private var viewModel = MainTabViewModel()
@State private var backdropAnim: Bool = true
@State private var lastBackdropAnim: Bool = false
var body: some View {
ZStack {
// please do not touch my magical crossfading. i will wave my magical github wand and cry
if viewModel.lastBackgroundURL != nil {
ImageView(src: viewModel.lastBackgroundURL!, bh: viewModel.backgroundBlurHash)
.frame(minWidth: 100, maxWidth: .infinity, minHeight: 100, maxHeight: .infinity)
.opacity(lastBackdropAnim ? 0.4 : 0)
}
if viewModel.backgroundURL != nil {
ImageView(src: viewModel.backgroundURL!, bh: viewModel.backgroundBlurHash)
.frame(minWidth: 100, maxWidth: .infinity, minHeight: 100, maxHeight: .infinity)
.opacity(backdropAnim ? 0.4 : 0)
.onChange(of: viewModel.backgroundURL) { _ in
lastBackdropAnim = true
backdropAnim = false
withAnimation(.linear(duration: 0.33)) {
lastBackdropAnim = false
backdropAnim = true
}
}
}
TabView(selection: $tabSelection) {
HomeView()
.offset(y: -20)
.tabItem {
Text(Tab.home.localized)
Image(systemName: "house")
}
.tag(Tab.home)
Text("Library")
.tabItem {
Text(Tab.allMedia.localized)
Image(systemName: "folder")
}
.tag(Tab.allMedia)
}
}
}
}
extension MainTabView {
enum Tab: String {
case home
case allMedia
var localized: String {
switch self {
case .home:
return "Home"
case .allMedia:
return "All Media"
}
}
}
}