#if DEBUG @_spi(Fixtures) import CallsKit import SwiftUI /// The call screen with no server behind it, for the UI test of its /// controls and the snapshots taken there. Debug builds only; launched /// with `-CallsCallFixture focus` (or grid, screen, notices), and /// optionally `-CallsFixtureControls shown|hidden` to pin the controls, /// `-CallsFixtureMore YES` to open the controls menu, `-CallsFixtureDark /// YES`, `-CallsFixtureClassic YES`, `-CallsFixtureBackdrop black|white|busy` /// for a frame in place of the stage, `-CallsFixtureStagePicture /// black|white|busy` for a frame as the picture on the stage's tile (the /// filmstrip and labels over it), `-CallsFixtureSelf /// muted|cameraOff|sharing` for your own state, `-CallsFixtureSpeaking /// silent|low|mid|high` for everyone's speaking glow, and /// `-CallsFixtureNoGlass YES` for the material older systems draw in /// place of Liquid Glass. For Speaker view (0.4.0): `-CallsFixtureLayout /// speaker|grid` (the grid fixture is Grid unless it says), and /// `-CallsFixtureSpeaker tom`, `-CallsFixturePinned li`, `-CallsFixtureLift /// li` (a tile half way through a drag) and `-CallsFixtureOrder /// li,tom,me,ana`. `-CallsFixtureRimGallery silent|low|mid|high` shows, /// in place of any call, the warm rim on a name at that level over the /// pictures it has to read on (`WarmRimGallery`, 0.4.3). struct PhoneCallFixture: View { static var requested: CallFixture? { UserDefaults.standard.string(forKey: "CallsCallFixture").flatMap(CallFixture.init(rawValue:)) } static var rimGallery: FixtureSpeaking? { UserDefaults.standard.string(forKey: "CallsFixtureRimGallery").flatMap(FixtureSpeaking.init(rawValue:)) } let fixture: CallFixture @StateObject private var call = Call(playAudio: false) @State private var applied = false var body: some View { let defaults = UserDefaults.standard let pinned = defaults.string(forKey: "CallsFixtureControls").map { $0 == "shown" } NavigationStack { PhoneCall( call: call, leave: {}, style: defaults.bool(forKey: "CallsFixtureClassic") ? .classic : .fullWindow, controlsShown: pinned, showingMore: defaults.bool(forKey: "CallsFixtureMore"), grid: defaults.string(forKey: "CallsFixtureLayout").map { $0 == "grid" } ?? (fixture == .grid)) } .tint(CallsAppearance.accent) .environment( \.fixtureBackdrop, defaults.string(forKey: "CallsFixtureBackdrop").flatMap(FixtureBackdrop.init(rawValue:))) .environment( \.fixtureStagePicture, defaults.string(forKey: "CallsFixtureStagePicture").flatMap(FixtureBackdrop.init(rawValue:))) .environment(\.callOverlayGlass, !defaults.bool(forKey: "CallsFixtureNoGlass")) .preferredColorScheme(defaults.bool(forKey: "CallsFixtureDark") ? .dark : .light) .onAppear { guard !applied else { return } applied = true fixture.apply(to: call) UserDefaults.standard.string(forKey: "CallsFixtureSelf") .flatMap(FixtureSelf.init(rawValue:))?.apply(to: call) UserDefaults.standard.string(forKey: "CallsFixtureSpeaking") .flatMap(FixtureSpeaking.init(rawValue:))?.apply(to: call) call.levels.speaker.showFixture(defaults.string(forKey: "CallsFixtureSpeaker")) call.arrangement.showPinned(defaults.string(forKey: "CallsFixturePinned").map(StageItem.camera)) call.arrangement.showLift(defaults.string(forKey: "CallsFixtureLift")) call.arrangement.showOrder( (defaults.string(forKey: "CallsFixtureOrder") ?? "").split(separator: ",").map(String.init)) } } } #endif