Yandex Music client for Apple TV
tvOS 17+ SwiftUI client for the unofficial Yandex Music API: rotor stations with feedback, library, search, artist and album pages, synced lyrics, and system Now Playing integration.
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Everything that can be pushed onto a tab's navigation stack.
|
||||
enum MusicRoute: Hashable {
|
||||
case artist(Artist)
|
||||
case album(Album)
|
||||
}
|
||||
|
||||
extension View {
|
||||
/// Attach once per NavigationStack so artist and album links work anywhere
|
||||
/// inside that tab, including recursively (artist → album → artist → …).
|
||||
func musicDestinations() -> some View {
|
||||
navigationDestination(for: MusicRoute.self) { route in
|
||||
switch route {
|
||||
case let .artist(artist):
|
||||
ArtistView(artist: artist)
|
||||
case let .album(album):
|
||||
AlbumView(album: album)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Poster tile that pushes a route instead of running an action.
|
||||
struct PosterLink: View {
|
||||
let title: String
|
||||
let subtitle: String?
|
||||
let imageURL: URL?
|
||||
let route: MusicRoute
|
||||
var circular = false
|
||||
|
||||
var body: some View {
|
||||
NavigationLink(value: route) {
|
||||
CoverImage(url: imageURL, corner: circular ? 140 : 12)
|
||||
.frame(width: 280, height: 280)
|
||||
}
|
||||
.buttonStyle(circular ? AnyButtonStyle(CircleCardStyle()) : AnyButtonStyle(CardButtonStyle()))
|
||||
.overlay(alignment: circular ? .bottom : .bottomLeading) {
|
||||
VStack(alignment: circular ? .center : .leading, spacing: 2) {
|
||||
Text(title)
|
||||
.font(.caption)
|
||||
.lineLimit(1)
|
||||
if let subtitle, !subtitle.isEmpty {
|
||||
Text(subtitle)
|
||||
.font(.caption2)
|
||||
.foregroundStyle(.secondary)
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
.frame(width: 280, alignment: circular ? .center : .leading)
|
||||
.offset(y: 62)
|
||||
}
|
||||
.padding(.bottom, 70)
|
||||
}
|
||||
}
|
||||
|
||||
/// Type eraser so one view can pick between two button styles.
|
||||
struct AnyButtonStyle: ButtonStyle {
|
||||
private let makeBodyClosure: (Configuration) -> AnyView
|
||||
|
||||
init<S: ButtonStyle>(_ style: S) {
|
||||
makeBodyClosure = { AnyView(style.makeBody(configuration: $0)) }
|
||||
}
|
||||
|
||||
func makeBody(configuration: Configuration) -> some View {
|
||||
makeBodyClosure(configuration)
|
||||
}
|
||||
}
|
||||
|
||||
/// The stock tvOS card treatment, wrapped so it can be erased alongside others.
|
||||
struct CardButtonStyle: ButtonStyle {
|
||||
func makeBody(configuration: Configuration) -> some View {
|
||||
StyleBody(configuration: configuration)
|
||||
}
|
||||
|
||||
private struct StyleBody: View {
|
||||
@Environment(\.isFocused) private var isFocused
|
||||
let configuration: ButtonStyleConfiguration
|
||||
|
||||
var body: some View {
|
||||
configuration.label
|
||||
.overlay {
|
||||
if isFocused {
|
||||
RoundedRectangle(cornerRadius: 12)
|
||||
.strokeBorder(.white.opacity(0.95), lineWidth: 5)
|
||||
}
|
||||
}
|
||||
.scaleEffect(configuration.isPressed ? 0.97 : (isFocused ? 1.05 : 1))
|
||||
.animation(.spring(response: 0.3, dampingFraction: 0.7), value: isFocused)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Horizontal shelf used by the artist and album pages.
|
||||
struct Shelf<Content: View>: View {
|
||||
let title: String
|
||||
@ViewBuilder let content: Content
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 20) {
|
||||
Text(title).font(.title2.weight(.semibold))
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(alignment: .top, spacing: 60) {
|
||||
content
|
||||
}
|
||||
.padding(.vertical, 24)
|
||||
}
|
||||
.scrollClipDisabled()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies the focus shadow only while focused, so unfocused cells cost nothing.
|
||||
struct FocusShadow: ViewModifier {
|
||||
let active: Bool
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
if active {
|
||||
content.shadow(color: .black.opacity(0.5), radius: 24, y: 12)
|
||||
} else {
|
||||
content
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user