mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 13:33:42 +00:00
Fix toolbar tabs
This commit is contained in:
parent
c31a5ee2e0
commit
414b6210c0
@ -4,8 +4,10 @@ import SwiftUI
|
||||
struct VideoDetailsOverlay: View {
|
||||
@EnvironmentObject<PlayerControlsModel> private var controls
|
||||
|
||||
@State private var detailsPage = VideoDetails.DetailsPage.queue
|
||||
|
||||
var body: some View {
|
||||
VideoDetails(sidebarQueue: .constant(false), fullScreen: fullScreenBinding)
|
||||
VideoDetails(page: $detailsPage, sidebarQueue: .constant(false), fullScreen: fullScreenBinding)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 4))
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ struct VideoDetails: View {
|
||||
case info, inspector, chapters, comments, related, queue
|
||||
}
|
||||
|
||||
@Binding var page: DetailsPage
|
||||
@Binding var sidebarQueue: Bool
|
||||
@Binding var fullScreen: Bool
|
||||
var bottomPadding = false
|
||||
@ -15,8 +16,6 @@ struct VideoDetails: View {
|
||||
@State private var subscribed = false
|
||||
@State private var subscriptionToggleButtonDisabled = false
|
||||
|
||||
@State private var page = DetailsPage.queue
|
||||
|
||||
@Environment(\.navigationStyle) private var navigationStyle
|
||||
#if os(iOS)
|
||||
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
||||
@ -84,7 +83,11 @@ struct VideoDetails: View {
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
page = sidebarQueue ? .inspector : .queue
|
||||
if video.isNil ||
|
||||
!VideoDetailsTool.find(for: page)!.isAvailable(for: video!, sidebarQueue: sidebarQueue)
|
||||
{
|
||||
page = .info
|
||||
}
|
||||
|
||||
guard video != nil, accounts.app.supportsSubscriptions else {
|
||||
subscribed = false
|
||||
@ -243,7 +246,7 @@ struct VideoDetails: View {
|
||||
|
||||
struct VideoDetails_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VideoDetails(sidebarQueue: .constant(true), fullScreen: .constant(false))
|
||||
VideoDetails(page: .constant(.info), sidebarQueue: .constant(true), fullScreen: .constant(false))
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,19 @@ import Defaults
|
||||
import Foundation
|
||||
|
||||
struct VideoDetailsTool: Identifiable {
|
||||
static let all = [
|
||||
Self(icon: "info.circle", name: "Info", page: .info),
|
||||
Self(icon: "wand.and.stars", name: "Inspector", page: .inspector),
|
||||
Self(icon: "bookmark", name: "Chapters", page: .chapters),
|
||||
Self(icon: "text.bubble", name: "Comments", page: .comments),
|
||||
Self(icon: "rectangle.stack.fill", name: "Related", page: .related),
|
||||
Self(icon: "list.number", name: "Queue", page: .queue)
|
||||
]
|
||||
|
||||
static func find(for page: VideoDetails.DetailsPage) -> Self? {
|
||||
all.first { $0.page == page }
|
||||
}
|
||||
|
||||
var id: String {
|
||||
page.rawValue
|
||||
}
|
||||
|
@ -7,14 +7,7 @@ struct VideoDetailsToolbar: View {
|
||||
@Binding var page: VideoDetails.DetailsPage
|
||||
var sidebarQueue: Bool
|
||||
|
||||
@State private var tools: [VideoDetailsTool] = [
|
||||
.init(icon: "info.circle", name: "Info", page: .info),
|
||||
.init(icon: "wand.and.stars", name: "Inspector", page: .inspector),
|
||||
.init(icon: "bookmark", name: "Chapters", page: .chapters),
|
||||
.init(icon: "text.bubble", name: "Comments", page: .comments),
|
||||
.init(icon: "rectangle.stack.fill", name: "Related", page: .related),
|
||||
.init(icon: "list.number", name: "Queue", page: .queue)
|
||||
]
|
||||
@State private var tools = VideoDetailsTool.all
|
||||
|
||||
@State private var activeTool: VideoDetailsTool?
|
||||
@State private var startedToolPosition: CGRect = .zero
|
||||
@ -34,6 +27,9 @@ struct VideoDetailsToolbar: View {
|
||||
}
|
||||
}
|
||||
.id(video?.id)
|
||||
.onAppear {
|
||||
activeTool = .find(for: page)
|
||||
}
|
||||
.onChange(of: page) { newValue in
|
||||
activeTool = tools.first { $0.id == newValue.rawValue }
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ struct VideoPlayerView: View {
|
||||
|
||||
@State private var playerSize: CGSize = .zero { didSet { updateSidebarQueue() } }
|
||||
@State private var hoveringPlayer = false
|
||||
@State private var detailsPage = VideoDetails.DetailsPage.queue
|
||||
@State private var fullScreenDetails = false
|
||||
@State private var sidebarQueue = defaultSidebarQueueValue
|
||||
|
||||
@ -339,7 +340,7 @@ struct VideoPlayerView: View {
|
||||
|
||||
#if !os(tvOS)
|
||||
if !fullScreenPlayer {
|
||||
VideoDetails(sidebarQueue: $sidebarQueue, fullScreen: $fullScreenDetails, bottomPadding: detailsNeedBottomPadding)
|
||||
VideoDetails(page: $detailsPage, sidebarQueue: $sidebarQueue, fullScreen: $fullScreenDetails, bottomPadding: detailsNeedBottomPadding)
|
||||
#if os(iOS)
|
||||
.ignoresSafeArea(.all, edges: .bottom)
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user