mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Browser player bar as overlay
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
import Foundation
|
||||
import SDWebImageSwiftUI
|
||||
import SwiftUI
|
||||
|
||||
struct BrowserPlayerControls<Content: View, Toolbar: View>: View {
|
||||
enum Context {
|
||||
case browser, player
|
||||
}
|
||||
|
||||
let content: Content
|
||||
let toolbar: Toolbar?
|
||||
|
||||
init(
|
||||
context _: Context? = nil,
|
||||
@ViewBuilder toolbar: @escaping () -> Toolbar? = { nil },
|
||||
@ViewBuilder content: @escaping () -> Content
|
||||
) {
|
||||
self.content = content()
|
||||
self.toolbar = toolbar()
|
||||
}
|
||||
|
||||
init(
|
||||
context: Context? = nil,
|
||||
@ViewBuilder content: @escaping () -> Content
|
||||
) where Toolbar == EmptyView {
|
||||
self.init(context: context, toolbar: { EmptyView() }, content: content)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
#if os(tvOS)
|
||||
return content
|
||||
#else
|
||||
// TODO: remove
|
||||
#if DEBUG
|
||||
if #available(iOS 15.0, macOS 12.0, *) {
|
||||
Self._printChanges()
|
||||
}
|
||||
#endif
|
||||
|
||||
return ZStack(alignment: .bottomLeading) {
|
||||
content
|
||||
.frame(maxHeight: .infinity)
|
||||
|
||||
#if !os(tvOS)
|
||||
VStack(spacing: 0) {
|
||||
#if os(iOS)
|
||||
toolbar
|
||||
.frame(height: 35)
|
||||
.frame(maxWidth: .infinity)
|
||||
.borderTop(height: 0.4, color: Color("ControlsBorderColor"))
|
||||
.modifier(ControlBackgroundModifier())
|
||||
#endif
|
||||
|
||||
ControlsBar(fullScreen: .constant(false))
|
||||
.edgesIgnoringSafeArea(.bottom)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
struct PlayerControlsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
BrowserPlayerControls(context: .player, toolbar: {
|
||||
Button("Button") {}
|
||||
}) {
|
||||
BrowserPlayerControls {
|
||||
VStack {
|
||||
Spacer()
|
||||
TextField("A", text: .constant("abc"))
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
.offset(y: -100)
|
||||
}
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
@@ -38,14 +38,10 @@ struct ChannelPlaylistView: View {
|
||||
var body: some View {
|
||||
if navigationStyle == .tab {
|
||||
NavigationView {
|
||||
BrowserPlayerControls {
|
||||
content
|
||||
}
|
||||
}
|
||||
} else {
|
||||
BrowserPlayerControls {
|
||||
content
|
||||
}
|
||||
} else {
|
||||
content
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -42,14 +42,10 @@ struct ChannelVideosView: View {
|
||||
var body: some View {
|
||||
if navigationStyle == .tab {
|
||||
NavigationView {
|
||||
BrowserPlayerControls {
|
||||
content
|
||||
}
|
||||
}
|
||||
} else {
|
||||
BrowserPlayerControls {
|
||||
content
|
||||
}
|
||||
} else {
|
||||
content
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -52,39 +52,37 @@ struct PlaylistVideosView: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
BrowserPlayerControls {
|
||||
VerticalCells(items: contentItems)
|
||||
.onAppear {
|
||||
guard contentItems.isEmpty else { return }
|
||||
resource?.load()
|
||||
}
|
||||
.onChange(of: model.reloadPlaylists) { _ in
|
||||
resource?.load()
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("\(playlist.title) Playlist")
|
||||
#endif
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem(placement: playlistButtonsPlacement) {
|
||||
HStack {
|
||||
FavoriteButton(item: FavoriteItem(section: .channelPlaylist(playlist.id, playlist.title)))
|
||||
VerticalCells(items: contentItems)
|
||||
.onAppear {
|
||||
guard contentItems.isEmpty else { return }
|
||||
resource?.load()
|
||||
}
|
||||
.onChange(of: model.reloadPlaylists) { _ in
|
||||
resource?.load()
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("\(playlist.title) Playlist")
|
||||
#endif
|
||||
.toolbar {
|
||||
ToolbarItem(placement: playlistButtonsPlacement) {
|
||||
HStack {
|
||||
FavoriteButton(item: FavoriteItem(section: .channelPlaylist(playlist.id, playlist.title)))
|
||||
|
||||
Button {
|
||||
player.play(videos)
|
||||
} label: {
|
||||
Label("Play All", systemImage: "play")
|
||||
}
|
||||
.contextMenu {
|
||||
Button {
|
||||
player.play(videos, shuffling: true)
|
||||
player.play(videos)
|
||||
} label: {
|
||||
Label("Shuffle All", systemImage: "shuffle")
|
||||
Label("Play All", systemImage: "play")
|
||||
}
|
||||
.contextMenu {
|
||||
Button {
|
||||
player.play(videos, shuffling: true)
|
||||
} label: {
|
||||
Label("Shuffle All", systemImage: "shuffle")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var playlistButtonsPlacement: ToolbarItemPlacement {
|
||||
|
@@ -15,24 +15,20 @@ struct PopularView: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
BrowserPlayerControls {
|
||||
VerticalCells(items: videos)
|
||||
.onAppear {
|
||||
resource?.addObserver(store)
|
||||
resource?.loadIfNeeded()
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("Popular")
|
||||
#endif
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.background(
|
||||
Button("Refresh") {
|
||||
resource?.load()
|
||||
VerticalCells(items: videos)
|
||||
.onAppear {
|
||||
resource?.addObserver(store)
|
||||
resource?.loadIfNeeded()
|
||||
}
|
||||
.keyboardShortcut("r")
|
||||
.opacity(0)
|
||||
)
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("Popular")
|
||||
.background(
|
||||
Button("Refresh") {
|
||||
resource?.load()
|
||||
}
|
||||
.keyboardShortcut("r")
|
||||
.opacity(0)
|
||||
)
|
||||
#endif
|
||||
#if os(iOS)
|
||||
.refreshControl { refreshControl in
|
||||
|
@@ -61,10 +61,8 @@ struct SignInRequiredView<Content: View>: View {
|
||||
|
||||
struct SignInRequiredView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
BrowserPlayerControls {
|
||||
SignInRequiredView(title: "Subscriptions") {
|
||||
Text("Only when signed in")
|
||||
}
|
||||
SignInRequiredView(title: "Subscriptions") {
|
||||
Text("Only when signed in")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user