* Implement voice message variable playback speed * Move playback speed string to Untranslated https://github.com/element-hq/element-x-ios/pull/5121#discussion_r2822631371 * Address review feedback for voice message playback speed - Persist voice message playback speed as an enum in AppSettings instead of storing an index. - Update playback speed cycling to derive from enum allCases and safely fall back to `.default` if the stored value cannot be resolved. - Apply runtime speed updates in AudioPlayer only when the player is in the `.playing` state. - Keep MediaPlayerProviderTests formatting/indentation style intact while retaining mock playback speed setup. - Regenerate preview snapshots for: - PlaybackSpeedButton - VoiceMessageRoomPlaybackView - VoiceMessageRoomTimelineView * Move VoiceMessagePlaybackSpeed outside AppSettings, remove speedRatio * Stabilize PlaybackSpeedButton width * Sync voice-message speed label - Add voiceMessagePlaybackSpeed to TimelineViewState and bind it from appSettings.$voiceMessagePlaybackSpeed. - Pass that timeline-level speed into VoiceMessageRoomPlaybackView and use it for PlaybackSpeedButton, so labels update consistently across items. - Use @EnvironmentObject in VoiceMessageRoomTimelineContent so the view re-renders when timeline context state changes. - In WaveformInteractionModifier, add .allowsHitTesting(showCursor) to the cursor interaction view so hidden pre-playback cursor hit area does not steal taps from the speed button.
54 lines
1.5 KiB
Swift
54 lines
1.5 KiB
Swift
//
|
|
// Copyright 2025 Element Creations Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
// Please see LICENSE files in the repository root for full details.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct PlaybackSpeedButton: View {
|
|
let speed: Float
|
|
let onTap: () -> Void
|
|
|
|
var body: some View {
|
|
Button(action: onTap) {
|
|
ZStack {
|
|
Text("0.0x")
|
|
.font(.compound.bodyXSSemibold)
|
|
.hidden()
|
|
|
|
Text(speedLabel)
|
|
.font(.compound.bodyXSSemibold)
|
|
.foregroundColor(.compound.iconSecondary)
|
|
}
|
|
.padding(.horizontal, 8)
|
|
.padding(.vertical, 2)
|
|
.background(.compound.bgCanvasDefault, in: RoundedRectangle(cornerRadius: 12))
|
|
}
|
|
.buttonStyle(.plain)
|
|
.accessibilityLabel(UntranslatedL10n.a11yPlaybackSpeed(speedLabel))
|
|
}
|
|
|
|
private var speedLabel: String {
|
|
if speed == Float(Int(speed)) {
|
|
"\(Int(speed))x"
|
|
} else {
|
|
String(format: "%gx", speed)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct PlaybackSpeedButton_Previews: PreviewProvider, TestablePreview {
|
|
static var previews: some View {
|
|
HStack(spacing: 8) {
|
|
PlaybackSpeedButton(speed: 0.5) { }
|
|
PlaybackSpeedButton(speed: 1.0) { }
|
|
PlaybackSpeedButton(speed: 1.5) { }
|
|
PlaybackSpeedButton(speed: 2.0) { }
|
|
}
|
|
.padding()
|
|
.background(Color.gray)
|
|
}
|
|
}
|