From 3661d060802d25a49a9eb5624e86ae12931d7716 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Thu, 22 Dec 2022 19:35:36 +0100 Subject: [PATCH] Hide unavailable tools in local video details --- Shared/Constants.swift | 2 +- .../Player/Video Details/VideoDetails.swift | 38 +++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Shared/Constants.swift b/Shared/Constants.swift index 0e7ce2d4..bbcecebf 100644 --- a/Shared/Constants.swift +++ b/Shared/Constants.swift @@ -37,7 +37,7 @@ struct Constants { #endif } - static var descriptionVisibility: Bool { + static var detailsVisibility: Bool { #if os(iOS) false #else diff --git a/Shared/Player/Video Details/VideoDetails.swift b/Shared/Player/Video Details/VideoDetails.swift index 94122028..f30bb54d 100644 --- a/Shared/Player/Video Details/VideoDetails.swift +++ b/Shared/Player/Video Details/VideoDetails.swift @@ -31,7 +31,7 @@ struct VideoDetails: View { var bottomPadding = false @State private var detailsSize = CGSize.zero - @State private var descriptionVisibility = Constants.descriptionVisibility + @State private var detailsVisibility = Constants.detailsVisibility @State private var subscribed = false @State private var subscriptionToggleButtonDisabled = false @State private var page = DetailsPage.info @@ -67,6 +67,9 @@ struct VideoDetails: View { .animation(nil, value: player.currentItem) pageView + #if os(iOS) + .opacity(detailsVisibility ? 1 : 0) + #endif } .overlay(GeometryReader { proxy in Color.clear @@ -118,21 +121,31 @@ struct VideoDetails: View { .frame(width: 200, alignment: .leading) .transaction { t in t.animation = nil } } - .animation(nil, value: descriptionVisibility) + .animation(nil, value: detailsVisibility) .modifier(SettingsPickerModifier()) .offset(x: 15, y: 5) - .opacity(descriptionVisibility ? 1 : 0) #endif } var pagePicker: some View { Picker("Page", selection: $page) { - ForEach(DetailsPage.allCases, id: \.rawValue) { page in + ForEach(DetailsPage.allCases.filter { pageAvailable($0) }, id: \.rawValue) { page in Label(page.title, systemImage: page.systemImageName).tag(page) } } } + func pageAvailable(_ page: DetailsPage) -> Bool { + guard let video else { return false } + + switch page { + case .inspector: + return true + default: + return !video.isLocal + } + } + var pageView: some View { ZStack(alignment: .topLeading) { switch page { @@ -143,9 +156,6 @@ struct VideoDetails: View { HStack { videoProperties .frame(maxWidth: .infinity, alignment: .trailing) - #if os(iOS) - .opacity(descriptionVisibility ? 1 : 0) - #endif } .padding(.bottom, 12) @@ -155,11 +165,9 @@ struct VideoDetails: View { .progressViewStyle(.circular) } .frame(maxWidth: .infinity) - .opacity(descriptionVisibility ? 1 : 0) } else if video.description != nil, !video.description!.isEmpty { VideoDescription(video: video, detailsSize: detailsSize) #if os(iOS) - .opacity(descriptionVisibility ? 1 : 0) .padding(.bottom, player.playingFullScreen ? 10 : SafeArea.insets.bottom) #endif } else if !video.isLocal { @@ -172,13 +180,21 @@ struct VideoDetails: View { .padding(.bottom, 60) } } + .onAppear { + if video != nil, !pageAvailable(page) { + page = .inspector + } + } #if os(iOS) .onAppear { if fullScreen { - descriptionVisibility = true + if let video, video.isLocal { + page = .inspector + } + detailsVisibility = true return } - Delay.by(0.4) { withAnimation(.easeIn(duration: 0.25)) { self.descriptionVisibility = true } } + Delay.by(0.4) { withAnimation(.easeIn(duration: 0.25)) { self.detailsVisibility = true } } } #endif .transition(.opacity)