import SwiftUI struct MyWaveView: View { @EnvironmentObject private var player: PlayerController @EnvironmentObject private var state: AppState @State private var stations: [Station] = [] @State private var isLoading = true @State private var showSignOut = false // Six across, as asked; the cards size themselves to the columns. private let columns = Array(repeating: GridItem(.flexible(), spacing: 28), count: 6) var body: some View { NavigationStack { content .musicDestinations() } .task { await load() } } private var content: some View { ScrollView { VStack(alignment: .leading, spacing: 44) { header WaveHeroButton { player.startRotor(station: "user:onyourwave", name: "Моя волна") } if isLoading { LoadingState(text: "Загружаем станции…").frame(height: 300) } else if !stations.isEmpty { VStack(alignment: .leading, spacing: 24) { Text("Станции") .font(.title2.weight(.semibold)) LazyVGrid(columns: columns, spacing: 40) { ForEach(stations, id: \.id) { station in CardButton( title: station.name ?? station.id.tag, subtitle: nil, imageURL: YMImage.url(station.icon?.imageUrl, size: 200), width: 250 ) { player.startRotor( station: station.id.stringValue, name: station.name ?? station.id.tag ) } } } } } } .padding(.vertical, 40) } } private var header: some View { HStack(alignment: .firstTextBaseline) { Text("Волна") .font(.system(size: 56, weight: .bold)) Spacer() if showSignOut { Button("Выйти", role: .destructive) { state.signOut() } } else { Button { showSignOut = true } label: { Label( state.accountName.isEmpty ? "Аккаунт" : state.accountName, systemImage: "person.crop.circle" ) .font(.callout) } .buttonStyle(.plain) } } } private func load() async { isLoading = true defer { isLoading = false } do { let dashboard = try await YMClient.shared.rotorDashboard() var all = dashboard.stations.map(\.station) if let list = try? await YMClient.shared.rotorStations() { let known = Set(all.map(\.id.stringValue)) all += list.map(\.station).filter { !known.contains($0.id.stringValue) } } stations = all } catch { log.error("\(error.localizedDescription)") } } } /// The one thing people actually come to this screen for, so it gets to be big. struct WaveHeroButton: View { let action: () -> Void var body: some View { Button(action: action) { EmptyView() } .buttonStyle(WaveHeroStyle()) } } private struct WaveHeroStyle: 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 { ZStack(alignment: .leading) { LinearGradient( colors: [ Color(red: 0.42, green: 0.16, blue: 0.62), Color(red: 0.75, green: 0.22, blue: 0.35), Color(red: 0.95, green: 0.62, blue: 0.13), ], startPoint: .topLeading, endPoint: .bottomTrailing ) HStack(spacing: 40) { VStack(alignment: .leading, spacing: 14) { Label("Радио", systemImage: "dot.radiowaves.left.and.right") .font(.caption.weight(.semibold)) .foregroundStyle(.white.opacity(0.85)) .padding(.horizontal, 16) .padding(.vertical, 8) .background(.white.opacity(0.18), in: Capsule()) Text("Моя волна") .font(.system(size: 68, weight: .heavy)) .foregroundStyle(.white) Text("Бесконечный поток под ваш вкус") .font(.title3) .foregroundStyle(.white.opacity(0.8)) .fixedSize(horizontal: false, vertical: true) } Spacer(minLength: 0) EqualizerBars(animating: isFocused) .frame(width: 180, height: 130) ZStack { Circle() .fill(.white) .frame(width: 110, height: 110) Image(systemName: "play.fill") .font(.system(size: 42, weight: .bold)) .foregroundStyle(Color(red: 0.42, green: 0.16, blue: 0.62)) } } .padding(.horizontal, 56) .padding(.vertical, 48) } .frame(height: 300) .clipShape(RoundedRectangle(cornerRadius: 28)) .overlay { if isFocused { RoundedRectangle(cornerRadius: 28).strokeBorder(.white.opacity(0.9), lineWidth: 5) } } // Shadow only while focused, and no scaling: both are offscreen // render passes on a card this large, and scaling a focused view is // what makes tvOS swap in a snapshot of the screen. .modifier(FocusShadow(active: isFocused)) .opacity(configuration.isPressed ? 0.85 : 1) .animation(.easeOut(duration: 0.15), value: isFocused) } } } /// Five bars that idle flat and start dancing once the card takes focus. struct EqualizerBars: View { let animating: Bool private let heights: [CGFloat] = [0.45, 0.95, 0.65, 1.0, 0.55] var body: some View { TimelineView(.animation(minimumInterval: 1.0 / 20, paused: !animating)) { timeline in let t = timeline.date.timeIntervalSinceReferenceDate GeometryReader { geo in HStack(alignment: .center, spacing: 14) { ForEach(heights.indices, id: \.self) { index in let phase = t * 2.4 + Double(index) * 0.7 // At rest the bars still read as an equaliser, just frozen. let wobble = animating ? (sin(phase) * 0.35 + 0.65) : 0.75 Capsule() .fill(.white.opacity(0.9)) .frame(height: geo.size.height * heights[index] * wobble) } } .frame(width: geo.size.width, height: geo.size.height, alignment: .center) } } } }