69 lines
1.8 KiB
Swift
69 lines
1.8 KiB
Swift
import Commanding
|
|||
|
|
import SwiftUI
|
||
|
|
import WidgetKit
|
||
|
|
|
||
|
|
/// The label naming the current state of the recording flow, next to an icon matching that state: a microphone while recording,
|
||
|
|
/// a pause symbol while paused, and a send symbol while the recorded input is being processed.
|
||
|
|
struct RecordingStateLabel: View {
|
||
|
|
|
||
|
|
// MARK: Properties
|
||
|
|
|
||
|
|
/// The dynamic content of the Live Activity to render.
|
||
|
|
let state: RecordingActivityAttributes.ContentState
|
||
|
|
|
||
|
|
// MARK: Body
|
||
|
|
|
||
|
|
var body: some View {
|
||
|
|
Label {
|
||
|
|
switch state.state {
|
||
|
|
case .recording:
|
||
|
|
Text(.viewRecordingStateLabelStateRecording)
|
||
|
|
case .paused:
|
||
|
|
Text(.viewRecordingStateLabelStatePaused)
|
||
|
|
case .processing:
|
||
|
|
Text(.viewRecordingStateLabelStateProcessing)
|
||
|
|
}
|
||
|
|
} icon: {
|
||
|
|
switch state.state {
|
||
|
|
case .recording:
|
||
|
|
Image.Symbol.microphone
|
||
|
|
.foregroundStyle(.yellow)
|
||
|
|
case .paused:
|
||
|
|
Image.Symbol.pause
|
||
|
|
.foregroundStyle(.yellow)
|
||
|
|
case .processing:
|
||
|
|
Image.Symbol.send
|
||
|
|
.foregroundStyle(.green)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
.font(.body)
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
// MARK: - Previews
|
||
|
|
|
||
|
|
#Preview(
|
||
|
|
"Recording State label",
|
||
|
|
as: .dynamicIsland(.expanded),
|
||
|
|
using: RecordingActivityAttributes()
|
||
|
|
) {
|
||
|
|
RecordingLiveActivity()
|
||
|
|
} contentStates: {
|
||
|
|
RecordingActivityAttributes.ContentState(
|
||
|
|
state: .recording,
|
||
|
|
anchor: .now,
|
||
|
|
elapsed: 0
|
||
|
|
)
|
||
|
|
RecordingActivityAttributes.ContentState(
|
||
|
|
state: .paused,
|
||
|
|
anchor: nil,
|
||
|
|
elapsed: 325
|
||
|
|
)
|
||
|
|
RecordingActivityAttributes.ContentState(
|
||
|
|
state: .processing,
|
||
|
|
anchor: nil,
|
||
|
|
elapsed: 325
|
||
|
|
)
|
||
|
|
}
|