krz/moonrise

Night-sky companion for iPhone, Apple Watch and Vision Pro: what's up tonight, the Moon, planets, launches and missions, and a Library of the solar system. SwiftUI app with a Cloudflare Workers backend. astronomy cloudflare-workers ios night-sky space swiftui visionos watchos

App/Sources/Intents/AnswerSnippet.swift

44 lines · 1787 bytes

 1import Answers
 2import SkyRenderer
 3import SwiftUI
 4
 5/// Result view for Siri and Shortcuts, in the Today sheet's style: section label, hairline, label/value grid.
 6struct AnswerSnippet: View {
 7    var heading: String
 8    var lead: String?
 9    var rows: [AnswerRow]
10    var footnote: String?
11    var moon: (fraction: Double, waxing: Bool)?
12
13    private let ink = Color(red: 0.95, green: 0.95, blue: 0.93)
14    private let accent = Color(red: 0.88, green: 0.24, blue: 0.19)
15
16    var body: some View {
17        VStack(alignment: .leading, spacing: 8) {
18            Text(heading).font(.caption2.weight(.medium)).textCase(.uppercase).tracking(0.8).dimmed(0.6)
19            if let lead { Text(lead).font(.subheadline) }
20            Rectangle().fill(ink.opacity(0.25)).frame(height: 0.5)
21            HStack(alignment: .center, spacing: 16) {
22                if let moon { MoonDisc(fraction: moon.fraction, waxing: moon.waxing).frame(width: 52) }
23                Grid(alignment: .leading, horizontalSpacing: 16, verticalSpacing: 6) {
24                    ForEach(rows, id: \.self) { row in
25                        GridRow {
26                            Text(row.label).dimmed(0.7)
27                            Text(row.value).monospacedDigit().foregroundStyle(row.alert ? accent : ink)
28                        }
29                        .font(.subheadline)
30                    }
31                }
32            }
33            if let footnote {
34                Rectangle().fill(ink.opacity(0.25)).frame(height: 0.5)
35                Text(footnote).font(.caption2.monospacedDigit()).dimmed(0.6)
36            }
37        }
38        .frame(maxWidth: .infinity, alignment: .leading)
39        .padding(16)
40        .foregroundStyle(ink)
41        .background(Color.black)
42        .environment(\.colorScheme, .dark)
43    }
44}