PulseCanvas / app · pulsecanvas.ai / mobile / MobilePresentation.swift
| 1 | import SwiftUI |
| 2 | |
| 3 | struct MobilePresentation: View { |
| 4 | @ObservedObject var editor: MobileEditor |
| 5 | @ObservedObject var audio: AudioController |
| 6 | @ObservedObject var radio: RadioController |
| 7 | @ObservedObject var render: RenderState |
| 8 | @ObservedObject private var library = ProjectMPresets.shared |
| 9 | @State private var showsControls = true |
| 10 | init(editor: MobileEditor) { self.editor = editor; audio = editor.audio; radio = editor.radio; render = editor.currentRender } |
| 11 | private var autoHide: Bool { audio.isPlaying && showsControls } |
| 12 | var body: some View { |
| 13 | GeometryReader { geometry in |
| 14 | ZStack(alignment: .bottom) { |
| 15 | Color.black.ignoresSafeArea() |
| 16 | VisualizerView(state: render).ignoresSafeArea() |
| 17 | .accessibilityElement(children: .ignore).accessibilityLabel("Full-screen visualization") |
| 18 | .accessibilityValue(editor.library.sceneNames[render.scene]) |
| 19 | .accessibilityIdentifier("mobilePresentationPreview") |
| 20 | .modifier(MobileVisualizerSwipe { editor.randomizePreviewVisualizer() }) |
| 21 | .modifier(VisualizerFavoriteGesture(favorite: editor.favoritePreviewVisualizer, singleTap: { showsControls.toggle() })) |
| 22 | if showsControls { |
| 23 | VStack(spacing: 8) { |
| 24 | HStack(spacing: 8) { |
| 25 | Button { library.toggleFavorite(render.scene, appearance: VisualPreset(render: render)) } label: { |
| 26 | Image(systemName: library.isFavorite(render.scene) ? "heart.fill" : "heart") |
| 27 | }.accessibilityLabel("Favorite visualizer") |
| 28 | .accessibilityIdentifier("presentationVisualizerFavorite") |
| 29 | .accessibilityValue(library.isFavorite(render.scene) ? "Favorited" : "Not favorited") |
| 30 | Text(library.sceneNames[render.scene]).font(.headline).lineLimit(1) |
| 31 | .accessibilityIdentifier("presentationVisualizerTitle") |
| 32 | Spacer(minLength: 0) |
| 33 | Button { editor.presenting = false } label: { Image(systemName: "xmark") }.accessibilityLabel("Close") |
| 34 | } |
| 35 | if editor.selectedTab == 1 { |
| 36 | ViewThatFits(in: .horizontal) { |
| 37 | HStack(spacing: 12) { |
| 38 | songHeading |
| 39 | MobileRadioStationPicker(radio: radio, identifier: "presentationStationPicker").frame(maxWidth: 200) |
| 40 | transport |
| 41 | } |
| 42 | VStack(spacing: 8) { |
| 43 | songHeading |
| 44 | HStack(spacing: 8) { |
| 45 | MobileRadioStationPicker(radio: radio, identifier: "presentationStationPicker").frame(maxWidth: 180) |
| 46 | Spacer(minLength: 0) |
| 47 | transport |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | } else { |
| 52 | HStack { |
| 53 | Text(audio.title).font(.subheadline).lineLimit(1) |
| 54 | Spacer(minLength: 0) |
| 55 | transport |
| 56 | } |
| 57 | } |
| 58 | }.buttonStyle(MobileButton()) |
| 59 | .padding(.leading, max(12, geometry.safeAreaInsets.leading)) |
| 60 | .padding(.trailing, max(12, geometry.safeAreaInsets.trailing)) |
| 61 | .padding(.top, 8).padding(.bottom, max(8, geometry.safeAreaInsets.bottom)) |
| 62 | .background(.ultraThinMaterial) |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | .tint(MobileTheme.accent).statusBarHidden() |
| 67 | .task(id: autoHide) { |
| 68 | guard autoHide else { return } |
| 69 | do { try await Task.sleep(for: .seconds(4)) } catch { return } |
| 70 | if autoHide { showsControls = false } |
| 71 | } |
| 72 | } |
| 73 | private var songHeading: some View { |
| 74 | HStack(spacing: 8) { |
| 75 | if let track = radio.currentTrack, radio.canFavoriteCurrentSong { |
| 76 | Button { radio.toggleFavoriteSong(track) } label: { |
| 77 | Image(systemName: radio.isFavoriteSong(track) ? "heart.fill" : "heart") |
| 78 | }.accessibilityLabel("Favorite song") |
| 79 | .accessibilityIdentifier("presentationSongFavorite") |
| 80 | .accessibilityValue(radio.isFavoriteSong(track) ? "Favorited" : "Not favorited") |
| 81 | } |
| 82 | Text(radio.currentTrack?.title ?? "PulseCanvas Radio").font(.subheadline).lineLimit(1) |
| 83 | .frame(maxWidth: .infinity, alignment: .leading) |
| 84 | .accessibilityIdentifier("presentationSongTitle") |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | private var transport: some View { |
| 89 | HStack(spacing: 8) { |
| 90 | Button { editor.randomizePreviewVisualizer() } label: { Image(systemName: "shuffle") }.accessibilityLabel("Randomize") |
| 91 | if editor.selectedTab == 1 { |
| 92 | Button { radio.next() } label: { Label("Next", systemImage: "forward.end.fill") } |
| 93 | .accessibilityLabel("Next song").accessibilityIdentifier("presentationNextSong") |
| 94 | .disabled(!radio.isActive || radio.isLoading) |
| 95 | } |
| 96 | Button { if editor.selectedTab == 1 { if radio.isActive { radio.togglePlayback() } else { radio.start() } } else { audio.playPause() } } label: { |
| 97 | Image(systemName: audio.isPlaying ? "pause.fill" : "play.fill").frame(width: 30) |
| 98 | }.accessibilityLabel(audio.isPlaying ? "Pause" : "Play").accessibilityIdentifier("presentationPlayback") |
| 99 | }.fixedSize(horizontal: true, vertical: false) |
| 100 | } |
| 101 | |
| 102 | } |