Files
letro-ios/ElementX/Sources/Other/VoiceMessage/WaveformInteractionModifier.swift
Florian 5f724941ee Voice message: variable play back speed (#5121)
* 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.
2026-02-19 22:40:31 +01:00

58 lines
2.4 KiB
Swift

//
// Copyright 2025 Element Creations Ltd.
// Copyright 2023-2025 New Vector 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
extension View {
func waveformInteraction(isDragging: GestureState<Bool>, progress: Double, showCursor: Bool, onSeek: @escaping (Double) -> Void) -> some View {
modifier(WaveformInteractionModifier(isDragging: isDragging, progress: progress, showCursor: showCursor, onSeek: onSeek))
}
}
private struct WaveformInteractionModifier: ViewModifier {
let isDragging: GestureState<Bool>
let progress: Double
let showCursor: Bool
let onSeek: (Double) -> Void
@ScaledMetric private var cursorVisibleWidth = 2.0
@ScaledMetric private var cursorVisibleHeight = 24.0
private let cursorInteractiveSize: CGFloat = 50
func body(content: Content) -> some View {
GeometryReader { geometry in
content
.progressCursor(progress: progress) {
WaveformCursorView(color: .compound.iconAccentTertiary)
.frame(width: cursorVisibleWidth, height: cursorVisibleHeight)
.opacity(showCursor ? 1 : 0)
.frame(width: cursorInteractiveSize)
.frame(maxHeight: cursorInteractiveSize)
.contentShape(Rectangle())
.gesture(DragGesture(coordinateSpace: .named(Self.namespaceName))
.updating(isDragging) { dragGesture, isDragging, _ in
isDragging = true
let progress = dragGesture.location.x / geometry.size.width
onSeek(max(0, min(progress, 1.0)))
})
.offset(x: -cursorInteractiveSize / 2, y: 0)
.allowsHitTesting(showCursor)
}
.gesture(SpatialTapGesture()
.onEnded { tapGesture in
let progress = tapGesture.location.x / geometry.size.width
onSeek(max(0, min(progress, 1.0)))
})
}
.coordinateSpace(name: Self.namespaceName)
.animation(nil, value: progress)
}
private static let namespaceName = "voice-message-waveform"
}