From e477d9062007cdd294ee81ee509dbf09e7549827 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Thu, 30 Jun 2022 10:05:32 +0200 Subject: [PATCH] Fix #190 --- Model/NavigationModel.swift | 26 +++++++++++++++++-------- Shared/Navigation/ContentView.swift | 13 ++++++++++++- Shared/OpenURLHandler.swift | 7 +++++-- Shared/Player/CommentView.swift | 3 ++- Shared/Player/VideoDetails.swift | 4 ++-- Shared/Search/SearchView.swift | 6 ++++-- Shared/Videos/VideoCell.swift | 3 ++- Shared/Views/ChannelCell.swift | 3 ++- Shared/Views/ControlsBar.swift | 15 ++++++++------ Shared/Views/VideoContextMenuView.swift | 3 ++- 10 files changed, 58 insertions(+), 25 deletions(-) diff --git a/Model/NavigationModel.swift b/Model/NavigationModel.swift index 6c4c81cd..cb36f296 100644 --- a/Model/NavigationModel.swift +++ b/Model/NavigationModel.swift @@ -86,7 +86,8 @@ final class NavigationModel: ObservableObject { _ channel: Channel, player: PlayerModel, recents: RecentsModel, - navigation: NavigationModel + navigation: NavigationModel, + navigationStyle: NavigationStyle ) { guard channel.id != Video.fixtureChannelID else { return @@ -104,9 +105,13 @@ final class NavigationModel: ObservableObject { DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { recents.add(recent) - navigation.sidebarSectionChanged.toggle() - navigation.tabSelection = .recentlyOpened(recent.tag) - navigation.presentingChannel = true + + if navigationStyle == .sidebar { + navigation.sidebarSectionChanged.toggle() + navigation.tabSelection = .recentlyOpened(recent.tag) + } else { + navigation.presentingChannel = true + } } } @@ -114,7 +119,8 @@ final class NavigationModel: ObservableObject { _ playlist: ChannelPlaylist, player: PlayerModel, recents: RecentsModel, - navigation: NavigationModel + navigation: NavigationModel, + navigationStyle: NavigationStyle ) { navigation.presentingChannel = false navigation.presentingPlaylist = false @@ -128,9 +134,13 @@ final class NavigationModel: ObservableObject { DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { recents.add(recent) - navigation.sidebarSectionChanged.toggle() - navigation.tabSelection = .recentlyOpened(recent.tag) - navigation.presentingPlaylist = true + + if navigationStyle == .sidebar { + navigation.sidebarSectionChanged.toggle() + navigation.tabSelection = .recentlyOpened(recent.tag) + } else { + navigation.presentingPlaylist = true + } } } diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift index ff5fd887..5e96e13a 100644 --- a/Shared/Navigation/ContentView.swift +++ b/Shared/Navigation/ContentView.swift @@ -87,7 +87,8 @@ struct ContentView: View { navigation: navigation, recents: recents, player: player, - search: search + search: search, + navigationStyle: navigationStyle ).handle($0) } .background( @@ -115,6 +116,16 @@ struct ContentView: View { .alert(isPresented: $navigation.presentingAlert) { navigation.alert } } + var navigationStyle: NavigationStyle { + #if os(iOS) + return horizontalSizeClass == .compact ? .tab : .sidebar + #elseif os(tvOS) + return .tab + #else + return .sidebar + #endif + } + func openWelcomeScreenIfAccountEmpty() { guard Defaults[.instances].isEmpty else { return diff --git a/Shared/OpenURLHandler.swift b/Shared/OpenURLHandler.swift index ee929b7a..13750fc6 100644 --- a/Shared/OpenURLHandler.swift +++ b/Shared/OpenURLHandler.swift @@ -10,6 +10,7 @@ struct OpenURLHandler { var recents: RecentsModel var player: PlayerModel var search: SearchModel + var navigationStyle = NavigationStyle.sidebar func handle(_ url: URL) { if accounts.current.isNil { @@ -132,7 +133,8 @@ struct OpenURLHandler { playlist, player: player, recents: recents, - navigation: navigation + navigation: navigation, + navigationStyle: navigationStyle ) } } else { @@ -163,7 +165,8 @@ struct OpenURLHandler { channel, player: player, recents: recents, - navigation: navigation + navigation: navigation, + navigationStyle: navigationStyle ) } } else { diff --git a/Shared/Player/CommentView.swift b/Shared/Player/CommentView.swift index 281178d7..201d343e 100644 --- a/Shared/Player/CommentView.swift +++ b/Shared/Player/CommentView.swift @@ -256,7 +256,8 @@ struct CommentView: View { comment.channel, player: player, recents: recents, - navigation: navigation + navigation: navigation, + navigationStyle: navigationStyle ) } } diff --git a/Shared/Player/VideoDetails.swift b/Shared/Player/VideoDetails.swift index 706b1743..a59b3e2b 100644 --- a/Shared/Player/VideoDetails.swift +++ b/Shared/Player/VideoDetails.swift @@ -55,12 +55,12 @@ struct VideoDetails: View { var body: some View { VStack(alignment: .leading, spacing: 0) { ControlsBar( + fullScreen: $fullScreen, presentingControls: false, backgroundEnabled: false, borderTop: false, detailsTogglePlayer: false, - detailsToggleFullScreen: true, - fullScreen: $fullScreen + detailsToggleFullScreen: true ) HStack(spacing: 4) { diff --git a/Shared/Search/SearchView.swift b/Shared/Search/SearchView.swift index d345b001..81454741 100644 --- a/Shared/Search/SearchView.swift +++ b/Shared/Search/SearchView.swift @@ -322,7 +322,8 @@ struct SearchView: View { channel, player: player, recents: recents, - navigation: navigation + navigation: navigation, + navigationStyle: navigationStyle ) case .playlist: guard let playlist = item.playlist else { @@ -333,7 +334,8 @@ struct SearchView: View { playlist, player: player, recents: recents, - navigation: navigation + navigation: navigation, + navigationStyle: navigationStyle ) } } label: { diff --git a/Shared/Videos/VideoCell.swift b/Shared/Videos/VideoCell.swift index b40f9b96..49510c28 100644 --- a/Shared/Videos/VideoCell.swift +++ b/Shared/Videos/VideoCell.swift @@ -307,7 +307,8 @@ struct VideoCell: View { video.channel, player: player, recents: recents, - navigation: navigation + navigation: navigation, + navigationStyle: navigationStyle ) } label: { if badge { diff --git a/Shared/Views/ChannelCell.swift b/Shared/Views/ChannelCell.swift index 24665c25..371a0e91 100644 --- a/Shared/Views/ChannelCell.swift +++ b/Shared/Views/ChannelCell.swift @@ -17,7 +17,8 @@ struct ChannelCell: View { channel, player: player, recents: recents, - navigation: navigation + navigation: navigation, + navigationStyle: navigationStyle ) } label: { content diff --git a/Shared/Views/ControlsBar.swift b/Shared/Views/ControlsBar.swift index 990e4f77..bc01034e 100644 --- a/Shared/Views/ControlsBar.swift +++ b/Shared/Views/ControlsBar.swift @@ -3,6 +3,13 @@ import SDWebImageSwiftUI import SwiftUI struct ControlsBar: View { + @Binding var fullScreen: Bool + + @State private var presentingShareSheet = false + @State private var shareURL: URL? + + @Environment(\.navigationStyle) private var navigationStyle + @EnvironmentObject private var accounts @EnvironmentObject private var navigation @EnvironmentObject private var playerControls @@ -11,9 +18,6 @@ struct ControlsBar: View { @EnvironmentObject private var recents @EnvironmentObject private var subscriptions - @State private var presentingShareSheet = false - @State private var shareURL: URL? - var presentingControls = true var backgroundEnabled = true var borderTop = true @@ -21,8 +25,6 @@ struct ControlsBar: View { var detailsTogglePlayer = true var detailsToggleFullScreen = false - @Binding var fullScreen: Bool - var body: some View { HStack(spacing: 0) { detailsButton @@ -170,7 +172,8 @@ struct ControlsBar: View { video.channel, player: model, recents: recents, - navigation: navigation + navigation: navigation, + navigationStyle: navigationStyle ) } label: { Label("\(video.author) Channel", systemImage: "rectangle.stack.fill.badge.person.crop") diff --git a/Shared/Views/VideoContextMenuView.swift b/Shared/Views/VideoContextMenuView.swift index 5082fbfb..7708bab5 100644 --- a/Shared/Views/VideoContextMenuView.swift +++ b/Shared/Views/VideoContextMenuView.swift @@ -197,7 +197,8 @@ struct VideoContextMenuView: View { video.channel, player: player, recents: recents, - navigation: navigation + navigation: navigation, + navigationStyle: navigationStyle ) } label: { Label("\(video.author) Channel", systemImage: "rectangle.stack.fill.badge.person.crop")