This commit is contained in:
Arkadiusz Fal 2022-06-30 10:05:32 +02:00
parent 485e1b060e
commit 117c4fc9b6
10 changed files with 58 additions and 25 deletions

View File

@ -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,17 +105,22 @@ final class NavigationModel: ObservableObject {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
recents.add(recent)
if navigationStyle == .sidebar {
navigation.sidebarSectionChanged.toggle()
navigation.tabSelection = .recentlyOpened(recent.tag)
} else {
navigation.presentingChannel = true
}
}
}
static func openChannelPlaylist(
_ playlist: ChannelPlaylist,
player: PlayerModel,
recents: RecentsModel,
navigation: NavigationModel
navigation: NavigationModel,
navigationStyle: NavigationStyle
) {
navigation.presentingChannel = false
navigation.presentingPlaylist = false
@ -128,11 +134,15 @@ final class NavigationModel: ObservableObject {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
recents.add(recent)
if navigationStyle == .sidebar {
navigation.sidebarSectionChanged.toggle()
navigation.tabSelection = .recentlyOpened(recent.tag)
} else {
navigation.presentingPlaylist = true
}
}
}
static func openSearchQuery(
_ searchQuery: String?,

View File

@ -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

View File

@ -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 {

View File

@ -256,7 +256,8 @@ struct CommentView: View {
comment.channel,
player: player,
recents: recents,
navigation: navigation
navigation: navigation,
navigationStyle: navigationStyle
)
}
}

View File

@ -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) {

View File

@ -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: {

View File

@ -307,7 +307,8 @@ struct VideoCell: View {
video.channel,
player: player,
recents: recents,
navigation: navigation
navigation: navigation,
navigationStyle: navigationStyle
)
} label: {
if badge {

View File

@ -17,7 +17,8 @@ struct ChannelCell: View {
channel,
player: player,
recents: recents,
navigation: navigation
navigation: navigation,
navigationStyle: navigationStyle
)
} label: {
content

View File

@ -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<AccountsModel> private var accounts
@EnvironmentObject<NavigationModel> private var navigation
@EnvironmentObject<PlayerControlsModel> private var playerControls
@ -11,9 +18,6 @@ struct ControlsBar: View {
@EnvironmentObject<RecentsModel> private var recents
@EnvironmentObject<SubscriptionsModel> 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")

View File

@ -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")