oficina / meet Public

Clone
git clone https://amadan.net/oficina/meet

Plain git — no account needed to clone.

Download

Download this file

1import SwiftUI
2
3/// Spec §15.19: the mark a video tile carries while its peer is muted.
4/// A slashed microphone and the word beside it, so the state is a shape
5/// and a word and never a colour. The tile folds it into its own
6/// accessibility label, so this hides itself from assistive technology
7/// rather than being read twice.
8public struct MutedBadge: View {
9 public init() {}
10 public var body: some View {
11 Label("Muted", systemImage: "mic.slash.fill")
12 .font(.caption.bold()).foregroundStyle(.white)
13 .padding(.horizontal, 8).padding(.vertical, 4)
14 .callOverlaySurface(Capsule())
15 .accessibilityHidden(true)
16 }
17}
18
19/// Spec §15.30: the quiet mark beside a person's name while this app asks
20/// them for less video. A word, never a colour; the tile's own label says
21/// "low bandwidth", so this hides itself from assistive technology.
22public struct LowBandwidthBadge: View {
23 var compact = false
24 public init(compact: Bool = false) { self.compact = compact }
25 public var body: some View {
26 Group {
27 if compact {
28 Image(systemName: "wifi.exclamationmark")
29 } else {
30 Label(VideoAdapt.badgeWord, systemImage: "wifi.exclamationmark")
31 }
32 }
33 .font(.caption.weight(.semibold)).foregroundStyle(.white)
34 .padding(.horizontal, 7).padding(.vertical, 3)
35 .callOverlaySurface(Capsule())
36 .help("Calls is asking for less video while the connection is weak")
37 .accessibilityHidden(true)
38 .accessibilityIdentifier("lowBandwidth")
39 }
40}
41
42/// What a tile's accessibility label says: the name, and "muted" when it
43/// is. Shared by the Mac and iPhone tiles so VoiceOver hears one phrase.
44public func tileAccessibilityLabel(_ label: String, muted: Bool) -> String {
45 muted ? "\(label), muted" : label
46}
47
48/// The full-window call's name label: small, and carrying the muted mark
49/// inside it — shape and word, as §15.19 has it — rather than in a
50/// second badge, so a tile keeps one quiet
51/// label in its corner that can stay while the controls come and go.
52/// Hidden from assistive technology, as the tile's own label says both.
53///
54/// A narrow tile (a filmstrip thumbnail, most of all on an iPhone held
55/// upright) has no room for "Ana García | Muted": there the word goes and
56/// the slashed microphone stays, and the name gives up its end to an
57/// ellipsis rather than running off the tile (0.4.1). The tile's own
58/// accessibility label still says "muted".
59public struct TileNameLabel: View {
60 let label: String
61 let muted: Bool
62 public init(label: String, muted: Bool) {
63 self.label = label
64 self.muted = muted
65 }
66 public var body: some View {
67 ViewThatFits(in: .horizontal) {
68 row(word: true).fixedSize()
69 row(word: false).fixedSize(horizontal: false, vertical: true)
70 }
71 .font(.caption.weight(.semibold)).foregroundStyle(.white)
72 .padding(.horizontal, 7).padding(.vertical, 3)
73 // The overlay's glass, as the controls have: white on it is 6.2:1
74 // even over a white wall.
75 .callOverlaySurface(Capsule())
76 .accessibilityHidden(true)
77 }
78
79 private func row(word: Bool) -> some View {
80 HStack(spacing: 5) {
81 Text(label).lineLimit(1).truncationMode(.tail)
82 if muted {
83 Group {
84 if word {
85 Label("Muted", systemImage: "mic.slash.fill").labelStyle(.titleAndIcon)
86 } else {
87 Image(systemName: "mic.slash.fill")
88 }
89 }
90 .padding(.leading, 5)
91 .overlay(alignment: .leading) {
92 Rectangle().fill(.white.opacity(0.5)).frame(width: 1, height: 10)
93 }
94 .fixedSize()
95 .layoutPriority(1)
96 }
97 }
98 }
99}
100
101/// What a tile shows where its picture is not: a symbol, and the words
102/// for it when there is room. Centred in the whole tile, as FaceTime has
103/// it, with the name label over the tile's bottom edge (2026-10-05, Paul:
104/// "Vertical centering here too"; until then, from 0.4.1, it was centred
105/// in the space above the label, which left it high). Only if the tile is
106/// so short that the centred placeholder would reach the label is it
107/// moved up, by no more than that (`PlaceholderPlacement`). On a tile too
108/// short for the words between the label and the top, the symbol stands
109/// alone, then smaller. The tile's accessibility value carries the words
110/// either way.
111public struct TilePlaceholder: View {
112 let symbol: String
113 let words: String?
114 let iconFont: Font
115 let wordsFont: Font
116 let spacing: CGFloat
117 let reserve: CGFloat
118
119 public init(
120 symbol: String, words: String?, iconFont: Font = .largeTitle, wordsFont: Font = .callout,
121 spacing: CGFloat = 12, reserve: CGFloat
122 ) {
123 self.symbol = symbol
124 self.words = words
125 self.iconFont = iconFont
126 self.wordsFont = wordsFont
127 self.spacing = spacing
128 self.reserve = reserve
129 }
130
131 public var body: some View {
132 PlaceholderLayout(reserve: reserve) {
133 ViewThatFits(in: .vertical) {
134 if let words {
135 VStack(spacing: spacing) {
136 Image(systemName: symbol).font(iconFont)
137 Text(words).font(wordsFont).multilineTextAlignment(.center).lineLimit(2)
138 .padding(.horizontal, 12)
139 }
140 }
141 Image(systemName: symbol).font(iconFont)
142 Image(systemName: symbol).font(.body)
143 }
144 }
145 .foregroundStyle(.white.opacity(0.8))
146 .accessibilityHidden(true)
147 }
148}
149
150/// Where a tile's placeholder goes, apart from any view so tests hold it:
151/// centred in the tile, unless that would bring it within `gap` of the
152/// label block at the bottom, when it rises just clear of it, and never
153/// above the tile's top.
154public enum PlaceholderPlacement {
155 /// Air kept between the placeholder and the top of the label block.
156 public static let gap: CGFloat = 4
157
158 /// The height the placeholder may take and still clear the label: what
159 /// chooses between the words, the symbol, and the smaller symbol.
160 public static func room(tile: CGFloat, reserve: CGFloat) -> CGFloat {
161 max(0, tile - clearance(reserve))
162 }
163
164 /// The placeholder's top, from the tile's top, for content `height` tall.
165 public static func top(tile: CGFloat, content height: CGFloat, reserve: CGFloat) -> CGFloat {
166 let centred = (tile - height) / 2
167 let clear = tile - clearance(reserve) - height
168 return max(0, min(centred, clear))
169 }
170
171 static func clearance(_ reserve: CGFloat) -> CGFloat { reserve > 0 ? reserve + gap : 0 }
172}
173
174/// Fills the tile and puts its one subview where `PlaceholderPlacement`
175/// says, offered the height it may take so `ViewThatFits` chooses what
176/// fits there.
177struct PlaceholderLayout: Layout {
178 let reserve: CGFloat
179 func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
180 proposal.replacingUnspecifiedDimensions()
181 }
182 func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
183 guard let content = subviews.first else { return }
184 let room = PlaceholderPlacement.room(tile: bounds.height, reserve: reserve)
185 let size = content.sizeThatFits(ProposedViewSize(width: bounds.width, height: room))
186 let top = PlaceholderPlacement.top(tile: bounds.height, content: size.height, reserve: reserve)
187 content.place(
188 at: CGPoint(x: bounds.midX, y: bounds.minY + top), anchor: .top,
189 proposal: ProposedViewSize(width: bounds.width, height: size.height))
190 }
191}
192
193/// A tile's name label block, measured, so its placeholder can keep
194/// clear of it (see `TilePlaceholder`).
195extension View {
196 /// Reports this view's height as the tile's label block.
197 public func tileLabelBlock(_ height: Binding<CGFloat>) -> some View {
198 onGeometryChange(for: CGFloat.self) { $0.size.height } action: { height.wrappedValue = $0 }
199 }
200}
201