| 1 | #if DEBUG |
| 2 | @_spi(Fixtures) import CallsKit |
| 3 | import SwiftUI |
| 4 | |
| 5 | /// The call screen with no server behind it, for the UI test of its |
| 6 | /// controls and the snapshots taken there. Debug builds only; launched |
| 7 | /// with `-CallsCallFixture focus` (or grid, screen, notices), and |
| 8 | /// optionally `-CallsFixtureControls shown|hidden` to pin the controls, |
| 9 | /// `-CallsFixtureMore YES` to open the controls menu, `-CallsFixtureDark |
| 10 | /// YES`, `-CallsFixtureClassic YES`, `-CallsFixtureBackdrop black|white|busy` |
| 11 | /// for a frame in place of the stage, `-CallsFixtureStagePicture |
| 12 | /// black|white|busy` for a frame as the picture on the stage's tile (the |
| 13 | /// filmstrip and labels over it), `-CallsFixtureSelf |
| 14 | /// muted|cameraOff|sharing` for your own state, `-CallsFixtureSpeaking |
| 15 | /// silent|low|mid|high` for everyone's speaking glow, and |
| 16 | /// `-CallsFixtureNoGlass YES` for the material older systems draw in |
| 17 | /// place of Liquid Glass. For Speaker view (0.4.0): `-CallsFixtureLayout |
| 18 | /// speaker|grid` (the grid fixture is Grid unless it says), and |
| 19 | /// `-CallsFixtureSpeaker tom`, `-CallsFixturePinned li`, `-CallsFixtureLift |
| 20 | /// li` (a tile half way through a drag) and `-CallsFixtureOrder |
| 21 | /// li,tom,me,ana`. `-CallsFixtureRimGallery silent|low|mid|high` shows, |
| 22 | /// in place of any call, the warm rim on a name at that level over the |
| 23 | /// pictures it has to read on (`WarmRimGallery`, 0.4.3). |
| 24 | struct PhoneCallFixture: View { |
| 25 | static var requested: CallFixture? { |
| 26 | UserDefaults.standard.string(forKey: "CallsCallFixture").flatMap(CallFixture.init(rawValue:)) |
| 27 | } |
| 28 | static var rimGallery: FixtureSpeaking? { |
| 29 | UserDefaults.standard.string(forKey: "CallsFixtureRimGallery").flatMap(FixtureSpeaking.init(rawValue:)) |
| 30 | } |
| 31 | |
| 32 | let fixture: CallFixture |
| 33 | @StateObject private var call = Call(playAudio: false) |
| 34 | @State private var applied = false |
| 35 | |
| 36 | var body: some View { |
| 37 | let defaults = UserDefaults.standard |
| 38 | let pinned = defaults.string(forKey: "CallsFixtureControls").map { $0 == "shown" } |
| 39 | NavigationStack { |
| 40 | PhoneCall( |
| 41 | call: call, leave: {}, |
| 42 | style: defaults.bool(forKey: "CallsFixtureClassic") ? .classic : .fullWindow, |
| 43 | controlsShown: pinned, showingMore: defaults.bool(forKey: "CallsFixtureMore"), |
| 44 | grid: defaults.string(forKey: "CallsFixtureLayout").map { $0 == "grid" } ?? (fixture == .grid)) |
| 45 | } |
| 46 | .tint(CallsAppearance.accent) |
| 47 | .environment( |
| 48 | \.fixtureBackdrop, |
| 49 | defaults.string(forKey: "CallsFixtureBackdrop").flatMap(FixtureBackdrop.init(rawValue:))) |
| 50 | .environment( |
| 51 | \.fixtureStagePicture, |
| 52 | defaults.string(forKey: "CallsFixtureStagePicture").flatMap(FixtureBackdrop.init(rawValue:))) |
| 53 | .environment(\.callOverlayGlass, !defaults.bool(forKey: "CallsFixtureNoGlass")) |
| 54 | .preferredColorScheme(defaults.bool(forKey: "CallsFixtureDark") ? .dark : .light) |
| 55 | .onAppear { |
| 56 | guard !applied else { return } |
| 57 | applied = true |
| 58 | fixture.apply(to: call) |
| 59 | UserDefaults.standard.string(forKey: "CallsFixtureSelf") |
| 60 | .flatMap(FixtureSelf.init(rawValue:))?.apply(to: call) |
| 61 | UserDefaults.standard.string(forKey: "CallsFixtureSpeaking") |
| 62 | .flatMap(FixtureSpeaking.init(rawValue:))?.apply(to: call) |
| 63 | call.levels.speaker.showFixture(defaults.string(forKey: "CallsFixtureSpeaker")) |
| 64 | call.arrangement.showPinned(defaults.string(forKey: "CallsFixturePinned").map(StageItem.camera)) |
| 65 | call.arrangement.showLift(defaults.string(forKey: "CallsFixtureLift")) |
| 66 | call.arrangement.showOrder( |
| 67 | (defaults.string(forKey: "CallsFixtureOrder") ?? "").split(separator: ",").map(String.init)) |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | #endif |
| 72 | |