yattee/Model/NavigationState.swift

58 lines
1.3 KiB
Swift
Raw Normal View History

2021-07-11 20:52:49 +00:00
import Foundation
import SwiftUI
final class NavigationState: ObservableObject {
@Published var tabSelection: TabSelection = .subscriptions
@Published var showingChannel = false
@Published var channel: Channel?
@Published var showingVideoDetails = false
2021-07-18 22:32:46 +00:00
@Published var showingVideo = false
2021-07-11 20:52:49 +00:00
@Published var video: Video?
2021-07-18 22:32:46 +00:00
@Published var returnToDetails = false
2021-07-11 20:52:49 +00:00
func openChannel(_ channel: Channel) {
2021-07-18 22:32:46 +00:00
returnToDetails = false
2021-07-11 20:52:49 +00:00
self.channel = channel
showingChannel = true
}
func closeChannel() {
showingChannel = false
channel = nil
}
func openVideoDetails(_ video: Video) {
self.video = video
showingVideoDetails = true
}
func closeVideoDetails() {
showingVideoDetails = false
video = nil
}
2021-07-18 22:32:46 +00:00
func playVideo(_ video: Video) {
self.video = video
showingVideo = true
}
func showVideoDetailsIfNeeded() {
showingVideoDetails = returnToDetails
returnToDetails = false
}
2021-07-11 20:52:49 +00:00
var tabSelectionOptionalBinding: Binding<TabSelection?> {
Binding<TabSelection?>(
get: {
self.tabSelection
},
set: {
self.tabSelection = $0 ?? .subscriptions
}
)
}
}