2026-07-06 03:43:25 +02:00
|
|
|
import Commanding
|
|
|
|
|
import SwiftUI
|
|
|
|
|
import WidgetKit
|
|
|
|
|
|
|
|
|
|
/// The Lock Screen banner of the recording Live Activity: a centered stack of the timer of the elapsed recording time, the label
|
|
|
|
|
/// naming the current state, and the control buttons.
|
|
|
|
|
struct RecordingLiveActivityView: View {
|
2026-07-07 00:06:52 +02:00
|
|
|
|
2026-07-06 03:43:25 +02:00
|
|
|
// MARK: Properties
|
2026-07-07 00:06:52 +02:00
|
|
|
|
2026-07-06 03:43:25 +02:00
|
|
|
/// The dynamic content of the Live Activity to render.
|
|
|
|
|
let state: RecordingActivityAttributes.ContentState
|
2026-07-07 00:06:52 +02:00
|
|
|
|
2026-07-06 03:43:25 +02:00
|
|
|
// MARK: Body
|
2026-07-07 00:06:52 +02:00
|
|
|
|
2026-07-06 03:43:25 +02:00
|
|
|
var body: some View {
|
|
|
|
|
VStack(
|
|
|
|
|
alignment: .center,
|
|
|
|
|
spacing: Constant.Spacing.stack
|
|
|
|
|
) {
|
2026-07-06 04:07:14 +02:00
|
|
|
RecordingStateLabel(state: state)
|
2026-07-07 00:06:52 +02:00
|
|
|
|
2026-07-06 03:43:25 +02:00
|
|
|
RecordingTimerText(state: state)
|
|
|
|
|
.font(.largeTitle)
|
|
|
|
|
.fontWeight(.bold)
|
2026-07-06 04:07:14 +02:00
|
|
|
|
2026-07-06 03:43:25 +02:00
|
|
|
RecordingControls(state: state)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-07 00:06:52 +02:00
|
|
|
|
2026-07-06 03:43:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: - Constants
|
|
|
|
|
|
|
|
|
|
/// The constant values used across the recording Live Activity.
|
|
|
|
|
private enum Constant {
|
|
|
|
|
/// The spacing constants.
|
|
|
|
|
enum Spacing {
|
|
|
|
|
/// The spacing between the elements of a stack.
|
|
|
|
|
static let stack: CGFloat = 8
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: - Previews
|
|
|
|
|
|
|
|
|
|
#Preview(
|
|
|
|
|
"Recording Live Activity view",
|
|
|
|
|
as: .content,
|
|
|
|
|
using: RecordingActivityAttributes()
|
|
|
|
|
) {
|
|
|
|
|
RecordingLiveActivity()
|
|
|
|
|
} contentStates: {
|
|
|
|
|
RecordingActivityAttributes.ContentState(
|
|
|
|
|
state: .recording,
|
|
|
|
|
anchor: .now,
|
|
|
|
|
elapsed: 0
|
|
|
|
|
)
|
|
|
|
|
RecordingActivityAttributes.ContentState(
|
|
|
|
|
state: .paused,
|
|
|
|
|
anchor: nil,
|
|
|
|
|
elapsed: 42
|
|
|
|
|
)
|
|
|
|
|
RecordingActivityAttributes.ContentState(
|
|
|
|
|
state: .processing,
|
|
|
|
|
anchor: nil,
|
|
|
|
|
elapsed: 42
|
|
|
|
|
)
|
|
|
|
|
}
|