Implemented the (first version of the) Recording Live Activity in the Attendi widget target.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import Commanding
|
||||
import SwiftUI
|
||||
import WidgetKit
|
||||
|
||||
/// The timer of the elapsed recording time, formatted as `mm:ss`: counted up by the system from the content state's anchor when
|
||||
/// one is given, and frozen at the reported elapsed time otherwise.
|
||||
struct RecordingTimerText: View {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
/// The dynamic content of the Live Activity to render.
|
||||
let state: RecordingActivityAttributes.ContentState
|
||||
|
||||
// MARK: Body
|
||||
|
||||
var body: some View {
|
||||
if let anchor = state.anchor {
|
||||
Text(
|
||||
.durationOffset(to: anchor),
|
||||
format: timerFormat
|
||||
)
|
||||
.multilineTextAlignment(.center)
|
||||
}
|
||||
else {
|
||||
Text(
|
||||
Duration
|
||||
.seconds(state.elapsed)
|
||||
.formatted(timerFormat)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private extension RecordingTimerText {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
/// The format of the timer: minutes and seconds, as `mm:ss`.
|
||||
var timerFormat: Duration.TimeFormatStyle {
|
||||
.time(pattern: .minuteSecond(padMinuteToLength: 2))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
#Preview(
|
||||
"Recording Timer text",
|
||||
as: .dynamicIsland(.compact),
|
||||
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
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user