mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 20:09:04 +00:00
Refactor voice messages touch interaction (#1970)
* Remove enable/disable long press actions * Working poc * Refactor interaction in VoiceMessageRoomPlaybackView * Cleanup DateFormatter * Fix VoiceMessagePreviewComposer * Cleanup * Delete WaveformViewDragState * Refactor WaveformCursorView * Cleanup * Add WaveformInteractionModifier * Add selection hapitc feedback * Fix ComposerToolbar ZStack alignment * Refine cursor size * Remove haptic feedback * Fix preview test * Delete longPressDisabledItemID * Remove progress animation * Project file
This commit is contained in:
@@ -356,6 +356,7 @@
|
|||||||
62910B515BCB4B455E24D7C1 /* AdvancedSettingsScreenViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D086854995173E897F993C26 /* AdvancedSettingsScreenViewModelProtocol.swift */; };
|
62910B515BCB4B455E24D7C1 /* AdvancedSettingsScreenViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D086854995173E897F993C26 /* AdvancedSettingsScreenViewModelProtocol.swift */; };
|
||||||
6298AB0906DDD3525CD78C6B /* LRUCache in Frameworks */ = {isa = PBXBuildFile; productRef = 1081D3630AAD3ACEDDEC3A98 /* LRUCache */; };
|
6298AB0906DDD3525CD78C6B /* LRUCache in Frameworks */ = {isa = PBXBuildFile; productRef = 1081D3630AAD3ACEDDEC3A98 /* LRUCache */; };
|
||||||
62A7FC3A0191BC7181AA432B /* AudioRecorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 907FA4DE17DEA1A3738EFB83 /* AudioRecorder.swift */; };
|
62A7FC3A0191BC7181AA432B /* AudioRecorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 907FA4DE17DEA1A3738EFB83 /* AudioRecorder.swift */; };
|
||||||
|
63CDC201A5980F304F6D0A1C /* WaveformInteractionModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFEE91FB8ABB5F5884B6D940 /* WaveformInteractionModifier.swift */; };
|
||||||
63E46D18B91D08E15FC04125 /* ExpiringTaskRunner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B25F959A434BB9923A3223F /* ExpiringTaskRunner.swift */; };
|
63E46D18B91D08E15FC04125 /* ExpiringTaskRunner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B25F959A434BB9923A3223F /* ExpiringTaskRunner.swift */; };
|
||||||
642DF13C49ED4121C148230E /* TestablePreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1E227F34BE43B08E098796E /* TestablePreview.swift */; };
|
642DF13C49ED4121C148230E /* TestablePreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1E227F34BE43B08E098796E /* TestablePreview.swift */; };
|
||||||
6448F8D1D3CA4CD27BB4CADD /* RoomMemberProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F36C5D9B37E50915ECBD3EE /* RoomMemberProxy.swift */; };
|
6448F8D1D3CA4CD27BB4CADD /* RoomMemberProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F36C5D9B37E50915ECBD3EE /* RoomMemberProxy.swift */; };
|
||||||
@@ -587,7 +588,6 @@
|
|||||||
9D2E03DB175A6AB14589076D /* AnalyticsEvents in Frameworks */ = {isa = PBXBuildFile; productRef = 2A3F7BCCB18C15B30CCA39A9 /* AnalyticsEvents */; };
|
9D2E03DB175A6AB14589076D /* AnalyticsEvents in Frameworks */ = {isa = PBXBuildFile; productRef = 2A3F7BCCB18C15B30CCA39A9 /* AnalyticsEvents */; };
|
||||||
9D79B94493FB32249F7E472F /* PlaceholderAvatarImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C705E605EF57C19DBE86FFA1 /* PlaceholderAvatarImage.swift */; };
|
9D79B94493FB32249F7E472F /* PlaceholderAvatarImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C705E605EF57C19DBE86FFA1 /* PlaceholderAvatarImage.swift */; };
|
||||||
9D9690D2FD4CD26FF670620F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C75EF87651B00A176AB08E97 /* AppDelegate.swift */; };
|
9D9690D2FD4CD26FF670620F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C75EF87651B00A176AB08E97 /* AppDelegate.swift */; };
|
||||||
9D9EF9DD484E58A2E8877187 /* WaveformViewDragGestureModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03BA7958A4BB9C22CA8884EF /* WaveformViewDragGestureModifier.swift */; };
|
|
||||||
9DC5FB22B8F86C3B51E907C1 /* HomeScreenUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D6E4C37E9F0E53D3DF951AC /* HomeScreenUITests.swift */; };
|
9DC5FB22B8F86C3B51E907C1 /* HomeScreenUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D6E4C37E9F0E53D3DF951AC /* HomeScreenUITests.swift */; };
|
||||||
9DD5AA10E85137140FEA86A3 /* MediaProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = F17EFA1D3D09FC2F9C5E1CB2 /* MediaProvider.swift */; };
|
9DD5AA10E85137140FEA86A3 /* MediaProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = F17EFA1D3D09FC2F9C5E1CB2 /* MediaProvider.swift */; };
|
||||||
9DD84E014ADFB2DD813022D5 /* RoomDetailsEditScreenViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00E5B2CBEF8F96424F095508 /* RoomDetailsEditScreenViewModelTests.swift */; };
|
9DD84E014ADFB2DD813022D5 /* RoomDetailsEditScreenViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00E5B2CBEF8F96424F095508 /* RoomDetailsEditScreenViewModelTests.swift */; };
|
||||||
@@ -1033,7 +1033,6 @@
|
|||||||
035177BCD8E8308B098AC3C2 /* WindowManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowManager.swift; sourceTree = "<group>"; };
|
035177BCD8E8308B098AC3C2 /* WindowManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowManager.swift; sourceTree = "<group>"; };
|
||||||
0376C429FAB1687C3D905F3E /* MockCoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockCoder.swift; sourceTree = "<group>"; };
|
0376C429FAB1687C3D905F3E /* MockCoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockCoder.swift; sourceTree = "<group>"; };
|
||||||
0392E3FDE372C9B56FEEED8B /* test_voice_message.m4a */ = {isa = PBXFileReference; path = test_voice_message.m4a; sourceTree = "<group>"; };
|
0392E3FDE372C9B56FEEED8B /* test_voice_message.m4a */ = {isa = PBXFileReference; path = test_voice_message.m4a; sourceTree = "<group>"; };
|
||||||
03BA7958A4BB9C22CA8884EF /* WaveformViewDragGestureModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WaveformViewDragGestureModifier.swift; sourceTree = "<group>"; };
|
|
||||||
03DD998E523D4EC93C7ED703 /* RoomNotificationSettingsScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomNotificationSettingsScreenViewModelProtocol.swift; sourceTree = "<group>"; };
|
03DD998E523D4EC93C7ED703 /* RoomNotificationSettingsScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomNotificationSettingsScreenViewModelProtocol.swift; sourceTree = "<group>"; };
|
||||||
03FABD73FD8086EFAB699F42 /* MediaUploadPreviewScreenViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaUploadPreviewScreenViewModelTests.swift; sourceTree = "<group>"; };
|
03FABD73FD8086EFAB699F42 /* MediaUploadPreviewScreenViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaUploadPreviewScreenViewModelTests.swift; sourceTree = "<group>"; };
|
||||||
045253F9967A535EE5B16691 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = "<group>"; };
|
045253F9967A535EE5B16691 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = "<group>"; };
|
||||||
@@ -1681,6 +1680,7 @@
|
|||||||
BFC9F57320EC80C7CE34FE4A /* VoiceMessagePreviewComposer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VoiceMessagePreviewComposer.swift; sourceTree = "<group>"; };
|
BFC9F57320EC80C7CE34FE4A /* VoiceMessagePreviewComposer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VoiceMessagePreviewComposer.swift; sourceTree = "<group>"; };
|
||||||
BFDCAC6CAAD65A2C24EA9C4B /* Dictionary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dictionary.swift; sourceTree = "<group>"; };
|
BFDCAC6CAAD65A2C24EA9C4B /* Dictionary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dictionary.swift; sourceTree = "<group>"; };
|
||||||
BFEA446F8618DBA79A9239CC /* MessageForwardingScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageForwardingScreen.swift; sourceTree = "<group>"; };
|
BFEA446F8618DBA79A9239CC /* MessageForwardingScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageForwardingScreen.swift; sourceTree = "<group>"; };
|
||||||
|
BFEE91FB8ABB5F5884B6D940 /* WaveformInteractionModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WaveformInteractionModifier.swift; sourceTree = "<group>"; };
|
||||||
C024C151639C4E1B91FCC68B /* ElementXAttributeScope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ElementXAttributeScope.swift; sourceTree = "<group>"; };
|
C024C151639C4E1B91FCC68B /* ElementXAttributeScope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ElementXAttributeScope.swift; sourceTree = "<group>"; };
|
||||||
C070FD43DC6BF4E50217965A /* LocalizationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalizationTests.swift; sourceTree = "<group>"; };
|
C070FD43DC6BF4E50217965A /* LocalizationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalizationTests.swift; sourceTree = "<group>"; };
|
||||||
C08E9043618AE5B0BF7B07E1 /* TemplateScreenViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateScreenViewModelTests.swift; sourceTree = "<group>"; };
|
C08E9043618AE5B0BF7B07E1 /* TemplateScreenViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateScreenViewModelTests.swift; sourceTree = "<group>"; };
|
||||||
@@ -3861,8 +3861,8 @@
|
|||||||
AD0FF64B0E6470F66F42E182 /* EstimatedWaveformView.swift */,
|
AD0FF64B0E6470F66F42E182 /* EstimatedWaveformView.swift */,
|
||||||
B8516302ACCA94A0E680AB3B /* VoiceMessageButton.swift */,
|
B8516302ACCA94A0E680AB3B /* VoiceMessageButton.swift */,
|
||||||
FB9EABCA9348DFA27439A809 /* WaveformCursorView.swift */,
|
FB9EABCA9348DFA27439A809 /* WaveformCursorView.swift */,
|
||||||
|
BFEE91FB8ABB5F5884B6D940 /* WaveformInteractionModifier.swift */,
|
||||||
94028A227645FA880B966211 /* WaveformSource.swift */,
|
94028A227645FA880B966211 /* WaveformSource.swift */,
|
||||||
03BA7958A4BB9C22CA8884EF /* WaveformViewDragGestureModifier.swift */,
|
|
||||||
);
|
);
|
||||||
path = VoiceMessage;
|
path = VoiceMessage;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -5898,8 +5898,8 @@
|
|||||||
CF3827071B0BC9638BD44F5D /* WaitlistScreenViewModel.swift in Sources */,
|
CF3827071B0BC9638BD44F5D /* WaitlistScreenViewModel.swift in Sources */,
|
||||||
B717A820BE02C6FE2CB53F6E /* WaitlistScreenViewModelProtocol.swift in Sources */,
|
B717A820BE02C6FE2CB53F6E /* WaitlistScreenViewModelProtocol.swift in Sources */,
|
||||||
CA12AE0DCD57D49CD96C699A /* WaveformCursorView.swift in Sources */,
|
CA12AE0DCD57D49CD96C699A /* WaveformCursorView.swift in Sources */,
|
||||||
|
63CDC201A5980F304F6D0A1C /* WaveformInteractionModifier.swift in Sources */,
|
||||||
B773ACD8881DB18E876D950C /* WaveformSource.swift in Sources */,
|
B773ACD8881DB18E876D950C /* WaveformSource.swift in Sources */,
|
||||||
9D9EF9DD484E58A2E8877187 /* WaveformViewDragGestureModifier.swift in Sources */,
|
|
||||||
D871C8CF46950F959C9A62C3 /* WelcomeScreen.swift in Sources */,
|
D871C8CF46950F959C9A62C3 /* WelcomeScreen.swift in Sources */,
|
||||||
383055C6ABE5BE058CEE1DDB /* WelcomeScreenScreenCoordinator.swift in Sources */,
|
383055C6ABE5BE058CEE1DDB /* WelcomeScreenScreenCoordinator.swift in Sources */,
|
||||||
BD2BF1EC73FFB0C01552ECDA /* WelcomeScreenScreenModels.swift in Sources */,
|
BD2BF1EC73FFB0C01552ECDA /* WelcomeScreenScreenModels.swift in Sources */,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import SwiftUI
|
|||||||
|
|
||||||
extension View {
|
extension View {
|
||||||
func progressCursor<CursorView: View>(progress: CGFloat,
|
func progressCursor<CursorView: View>(progress: CGFloat,
|
||||||
cursorView: @escaping () -> CursorView) -> some View {
|
@ViewBuilder cursorView: @escaping () -> CursorView) -> some View {
|
||||||
modifier(ProgressCursorModifier(progress: progress,
|
modifier(ProgressCursorModifier(progress: progress,
|
||||||
cursorView: cursorView))
|
cursorView: cursorView))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2023 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
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
|
||||||
|
.gesture(SpatialTapGesture()
|
||||||
|
.onEnded { tapGesture in
|
||||||
|
let progress = tapGesture.location.x / geometry.size.width
|
||||||
|
onSeek(max(0, min(progress, 1.0)))
|
||||||
|
})
|
||||||
|
.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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.coordinateSpace(name: Self.namespaceName)
|
||||||
|
.animation(nil, value: progress)
|
||||||
|
}
|
||||||
|
|
||||||
|
private static let namespaceName = "voice-message-waveform"
|
||||||
|
}
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright 2023 New Vector Ltd
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
//
|
|
||||||
|
|
||||||
import DSWaveformImageViews
|
|
||||||
import Foundation
|
|
||||||
import SwiftUI
|
|
||||||
|
|
||||||
struct WaveformViewDragGestureModifier: ViewModifier {
|
|
||||||
@GestureState private var dragGestureState = WaveformViewDragState.inactive
|
|
||||||
@Binding var dragState: WaveformViewDragState
|
|
||||||
|
|
||||||
let minimumDragDistance: Double
|
|
||||||
|
|
||||||
func body(content: Content) -> some View {
|
|
||||||
GeometryReader { geometry in
|
|
||||||
content
|
|
||||||
.gesture(SpatialTapGesture()
|
|
||||||
.simultaneously(with: LongPressGesture())
|
|
||||||
.sequenced(before: DragGesture(minimumDistance: minimumDragDistance, coordinateSpace: .local))
|
|
||||||
.updating($dragGestureState) { value, state, _ in
|
|
||||||
switch value {
|
|
||||||
// (SpatialTap, LongPress) begins.
|
|
||||||
case .first(let spatialLongPress):
|
|
||||||
// Compute the progress with the spatialTap location
|
|
||||||
let progress = (spatialLongPress.first?.location ?? .zero).x / geometry.size.width
|
|
||||||
state = .pressing(progress: progress)
|
|
||||||
// Long press confirmed, dragging may begin.
|
|
||||||
case .second(let spatialLongPress, let drag) where spatialLongPress.second ?? false:
|
|
||||||
var progress: Double = dragState.progress
|
|
||||||
// Compute the progress with drag location
|
|
||||||
if let location = drag?.location {
|
|
||||||
progress = location.x / geometry.size.width
|
|
||||||
}
|
|
||||||
state = .dragging(progress: progress)
|
|
||||||
// Dragging ended or the long press cancelled.
|
|
||||||
default:
|
|
||||||
state = .inactive
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
.onChange(of: dragGestureState) { value in
|
|
||||||
dragState = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension View {
|
|
||||||
func waveformDragGesture(_ dragState: Binding<WaveformViewDragState>, minimumDragDistance: Double = 0) -> some View {
|
|
||||||
modifier(WaveformViewDragGestureModifier(dragState: dragState,
|
|
||||||
minimumDragDistance: minimumDragDistance))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum WaveformViewDragState: Equatable {
|
|
||||||
case inactive
|
|
||||||
case pressing(progress: Double)
|
|
||||||
case dragging(progress: Double)
|
|
||||||
|
|
||||||
var progress: Double {
|
|
||||||
switch self {
|
|
||||||
case .inactive:
|
|
||||||
return .zero
|
|
||||||
case .pressing(let progress), .dragging(let progress):
|
|
||||||
return progress
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var isActive: Bool {
|
|
||||||
switch self {
|
|
||||||
case .inactive:
|
|
||||||
return false
|
|
||||||
case .pressing, .dragging:
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var isDragging: Bool {
|
|
||||||
switch self {
|
|
||||||
case .inactive, .pressing:
|
|
||||||
return false
|
|
||||||
case .dragging:
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -116,7 +116,7 @@ struct ComposerToolbar: View {
|
|||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var mainTopBarContent: some View {
|
private var mainTopBarContent: some View {
|
||||||
ZStack {
|
ZStack(alignment: .bottom) {
|
||||||
topBarLayout {
|
topBarLayout {
|
||||||
if !context.composerActionsEnabled {
|
if !context.composerActionsEnabled {
|
||||||
RoomAttachmentPicker(context: context)
|
RoomAttachmentPicker(context: context)
|
||||||
|
|||||||
@@ -25,29 +25,22 @@ struct VoiceMessagePreviewComposer: View {
|
|||||||
@ScaledMetric private var waveformLineWidth = 2.0
|
@ScaledMetric private var waveformLineWidth = 2.0
|
||||||
@ScaledMetric private var waveformLinePadding = 2.0
|
@ScaledMetric private var waveformLinePadding = 2.0
|
||||||
@State private var resumePlaybackAfterScrubbing = false
|
@State private var resumePlaybackAfterScrubbing = false
|
||||||
|
@GestureState var isDragging = false
|
||||||
|
|
||||||
let onPlay: () -> Void
|
let onPlay: () -> Void
|
||||||
let onPause: () -> Void
|
let onPause: () -> Void
|
||||||
let onSeek: (Double) -> Void
|
let onSeek: (Double) -> Void
|
||||||
|
|
||||||
@State var dragState: WaveformViewDragState = .inactive
|
|
||||||
|
|
||||||
private static let elapsedTimeFormatter: DateFormatter = {
|
|
||||||
let dateFormatter = DateFormatter()
|
|
||||||
dateFormatter.dateFormat = "mm:ss"
|
|
||||||
return dateFormatter
|
|
||||||
}()
|
|
||||||
|
|
||||||
var timeLabelContent: String {
|
var timeLabelContent: String {
|
||||||
// Display the duration if progress is 0.0
|
// Display the duration if progress is 0.0
|
||||||
let percent = playerState.progress > 0.0 ? playerState.progress : 1.0
|
let percent = playerState.progress > 0.0 ? playerState.progress : 1.0
|
||||||
// If the duration is greater or equal 10 minutes, use the long format
|
// If the duration is greater or equal 10 minutes, use the long format
|
||||||
let elapsed = Date(timeIntervalSinceReferenceDate: playerState.duration * percent)
|
let elapsed = Date(timeIntervalSinceReferenceDate: playerState.duration * percent)
|
||||||
return Self.elapsedTimeFormatter.string(from: elapsed)
|
return DateFormatter.elapsedTimeFormatter.string(from: elapsed)
|
||||||
}
|
}
|
||||||
|
|
||||||
var showWaveformCursor: Bool {
|
var showWaveformCursor: Bool {
|
||||||
playerState.playbackState == .playing || dragState.isActive
|
playerState.playbackState == .playing || isDragging
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -63,25 +56,12 @@ struct VoiceMessagePreviewComposer: View {
|
|||||||
.monospacedDigit()
|
.monospacedDigit()
|
||||||
.fixedSize(horizontal: true, vertical: true)
|
.fixedSize(horizontal: true, vertical: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
waveformView
|
waveformView
|
||||||
.waveformDragGesture($dragState)
|
.waveformInteraction(isDragging: $isDragging,
|
||||||
.progressCursor(progress: playerState.progress) {
|
progress: playerState.progress,
|
||||||
WaveformCursorView(color: .compound.iconAccentTertiary)
|
showCursor: showWaveformCursor,
|
||||||
.opacity(showWaveformCursor ? 1 : 0)
|
onSeek: onSeek)
|
||||||
.frame(width: waveformLineWidth)
|
|
||||||
}
|
|
||||||
.onChange(of: dragState) { dragState in
|
|
||||||
switch dragState {
|
|
||||||
case .inactive:
|
|
||||||
onScrubbing(false)
|
|
||||||
case .pressing(let progress):
|
|
||||||
onScrubbing(true)
|
|
||||||
onSeek(max(0, min(progress, 1.0)))
|
|
||||||
case .dragging(let progress):
|
|
||||||
onSeek(max(0, min(progress, 1.0)))
|
|
||||||
}
|
|
||||||
self.dragState = dragState
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.padding(.vertical, 4.0)
|
.padding(.vertical, 4.0)
|
||||||
.padding(.horizontal, 6.0)
|
.padding(.horizontal, 6.0)
|
||||||
@@ -135,6 +115,14 @@ struct VoiceMessagePreviewComposer: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private extension DateFormatter {
|
||||||
|
static let elapsedTimeFormatter: DateFormatter = {
|
||||||
|
let dateFormatter = DateFormatter()
|
||||||
|
dateFormatter.dateFormat = "mm:ss"
|
||||||
|
return dateFormatter
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
struct VoiceMessagePreviewComposer_Previews: PreviewProvider, TestablePreview {
|
struct VoiceMessagePreviewComposer_Previews: PreviewProvider, TestablePreview {
|
||||||
static let playerState = AudioPlayerState(id: .recorderPreview,
|
static let playerState = AudioPlayerState(id: .recorderPreview,
|
||||||
duration: 10.0,
|
duration: 10.0,
|
||||||
|
|||||||
@@ -80,9 +80,6 @@ enum RoomScreenViewAction {
|
|||||||
|
|
||||||
case scrolledToBottom
|
case scrolledToBottom
|
||||||
|
|
||||||
case enableLongPress(itemID: TimelineItemIdentifier)
|
|
||||||
case disableLongPress(itemID: TimelineItemIdentifier)
|
|
||||||
|
|
||||||
case playPauseAudio(itemID: TimelineItemIdentifier)
|
case playPauseAudio(itemID: TimelineItemIdentifier)
|
||||||
case seekAudio(itemID: TimelineItemIdentifier, progress: Double)
|
case seekAudio(itemID: TimelineItemIdentifier, progress: Double)
|
||||||
|
|
||||||
@@ -107,8 +104,7 @@ struct RoomScreenViewState: BindableState {
|
|||||||
var isEncryptedOneToOneRoom = false
|
var isEncryptedOneToOneRoom = false
|
||||||
var timelineViewState = TimelineViewState() // check the doc before changing this
|
var timelineViewState = TimelineViewState() // check the doc before changing this
|
||||||
var swiftUITimelineEnabled = false
|
var swiftUITimelineEnabled = false
|
||||||
|
|
||||||
var longPressDisabledItemID: TimelineItemIdentifier?
|
|
||||||
var ownUserID: String
|
var ownUserID: String
|
||||||
|
|
||||||
var showCallButton = false
|
var showCallButton = false
|
||||||
|
|||||||
@@ -158,11 +158,6 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
Task { await timelineController.playPauseAudio(for: itemID) }
|
Task { await timelineController.playPauseAudio(for: itemID) }
|
||||||
case .seekAudio(let itemID, let progress):
|
case .seekAudio(let itemID, let progress):
|
||||||
Task { await timelineController.seekAudio(for: itemID, progress: progress) }
|
Task { await timelineController.seekAudio(for: itemID, progress: progress) }
|
||||||
case .enableLongPress(let itemID):
|
|
||||||
guard state.longPressDisabledItemID == itemID else { return }
|
|
||||||
state.longPressDisabledItemID = nil
|
|
||||||
case .disableLongPress(let itemID):
|
|
||||||
state.longPressDisabledItemID = itemID
|
|
||||||
case let .endPoll(pollStartID):
|
case let .endPoll(pollStartID):
|
||||||
state.bindings.confirmationAlertInfo = .init(id: .init(),
|
state.bindings.confirmationAlertInfo = .init(id: .init(),
|
||||||
title: L10n.actionEndPoll,
|
title: L10n.actionEndPoll,
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import SwiftUI
|
|||||||
|
|
||||||
struct LongPressWithFeedback: ViewModifier {
|
struct LongPressWithFeedback: ViewModifier {
|
||||||
let action: () -> Void
|
let action: () -> Void
|
||||||
let disabled: () -> Bool
|
|
||||||
|
|
||||||
@State private var triggerTask: Task<Void, Never>?
|
@State private var triggerTask: Task<Void, Never>?
|
||||||
@State private var isLongPressing = false
|
@State private var isLongPressing = false
|
||||||
@@ -50,8 +49,6 @@ struct LongPressWithFeedback: ViewModifier {
|
|||||||
|
|
||||||
if Task.isCancelled { return }
|
if Task.isCancelled { return }
|
||||||
|
|
||||||
guard !disabled() else { return }
|
|
||||||
|
|
||||||
action()
|
action()
|
||||||
feedbackGenerator.impactOccurred()
|
feedbackGenerator.impactOccurred()
|
||||||
}
|
}
|
||||||
@@ -60,8 +57,8 @@ struct LongPressWithFeedback: ViewModifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension View {
|
extension View {
|
||||||
func longPressWithFeedback(disabled: @escaping @autoclosure () -> Bool = false, action: @escaping () -> Void) -> some View {
|
func longPressWithFeedback(action: @escaping () -> Void) -> some View {
|
||||||
modifier(LongPressWithFeedback(action: action, disabled: disabled))
|
modifier(LongPressWithFeedback(action: action))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
|
|||||||
}
|
}
|
||||||
// We need a tap gesture before this long one so that it doesn't
|
// We need a tap gesture before this long one so that it doesn't
|
||||||
// steal away the gestures from the scroll view
|
// steal away the gestures from the scroll view
|
||||||
.longPressWithFeedback(disabled: context.viewState.longPressDisabledItemID == timelineItem.id) {
|
.longPressWithFeedback {
|
||||||
context.send(viewAction: .timelineItemMenu(itemID: timelineItem.id))
|
context.send(viewAction: .timelineItemMenu(itemID: timelineItem.id))
|
||||||
}
|
}
|
||||||
.swipeRightAction {
|
.swipeRightAction {
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ struct TimelineItemPlainStylerView<Content: View>: View {
|
|||||||
}
|
}
|
||||||
// We need a tap gesture before this long one so that it doesn't
|
// We need a tap gesture before this long one so that it doesn't
|
||||||
// steal away the gestures from the scroll view
|
// steal away the gestures from the scroll view
|
||||||
.longPressWithFeedback(disabled: context.viewState.longPressDisabledItemID == timelineItem.id) {
|
.longPressWithFeedback {
|
||||||
context.send(viewAction: .timelineItemMenu(itemID: timelineItem.id))
|
context.send(viewAction: .timelineItemMenu(itemID: timelineItem.id))
|
||||||
}
|
}
|
||||||
.swipeRightAction {
|
.swipeRightAction {
|
||||||
|
|||||||
+24
-73
@@ -22,42 +22,26 @@ struct VoiceMessageRoomPlaybackView: View {
|
|||||||
@ObservedObject var playerState: AudioPlayerState
|
@ObservedObject var playerState: AudioPlayerState
|
||||||
@ScaledMetric private var waveformLineWidth = 2.0
|
@ScaledMetric private var waveformLineWidth = 2.0
|
||||||
@ScaledMetric private var waveformLinePadding = 2.0
|
@ScaledMetric private var waveformLinePadding = 2.0
|
||||||
|
@GestureState var isDragging = false
|
||||||
|
|
||||||
let onPlayPause: () -> Void
|
let onPlayPause: () -> Void
|
||||||
let onSeek: (Double) -> Void
|
let onSeek: (Double) -> Void
|
||||||
let onScrubbing: (Bool) -> Void
|
let onScrubbing: (Bool) -> Void
|
||||||
|
|
||||||
private let feedbackGenerator = UIImpactFeedbackGenerator(style: .heavy)
|
|
||||||
@State private var sendFeedback = false
|
|
||||||
|
|
||||||
private static let elapsedTimeFormatter: DateFormatter = {
|
|
||||||
let dateFormatter = DateFormatter()
|
|
||||||
dateFormatter.dateFormat = "m:ss"
|
|
||||||
return dateFormatter
|
|
||||||
}()
|
|
||||||
|
|
||||||
private static let longElapsedTimeFormatter: DateFormatter = {
|
|
||||||
let dateFormatter = DateFormatter()
|
|
||||||
dateFormatter.dateFormat = "mm:ss"
|
|
||||||
return dateFormatter
|
|
||||||
}()
|
|
||||||
|
|
||||||
@State var dragState: WaveformViewDragState = .inactive
|
|
||||||
|
|
||||||
var timeLabelContent: String {
|
var timeLabelContent: String {
|
||||||
// Display the duration if progress is 0.0
|
// Display the duration if progress is 0.0
|
||||||
let percent = playerState.progress > 0.0 ? playerState.progress : 1.0
|
let percent = playerState.progress > 0.0 ? playerState.progress : 1.0
|
||||||
// If the duration is greater or equal 10 minutes, use the long format
|
// If the duration is greater or equal 10 minutes, use the long format
|
||||||
let elapsed = Date(timeIntervalSinceReferenceDate: playerState.duration * percent)
|
let elapsed = Date(timeIntervalSinceReferenceDate: playerState.duration * percent)
|
||||||
if playerState.duration >= 600 {
|
if playerState.duration >= 600 {
|
||||||
return Self.longElapsedTimeFormatter.string(from: elapsed)
|
return DateFormatter.longElapsedTimeFormatter.string(from: elapsed)
|
||||||
} else {
|
} else {
|
||||||
return Self.elapsedTimeFormatter.string(from: elapsed)
|
return DateFormatter.elapsedTimeFormatter.string(from: elapsed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var showWaveformCursor: Bool {
|
var showWaveformCursor: Bool {
|
||||||
playerState.playbackState == .playing || dragState.isDragging
|
playerState.playbackState == .playing || isDragging
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -73,32 +57,18 @@ struct VoiceMessageRoomPlaybackView: View {
|
|||||||
.monospacedDigit()
|
.monospacedDigit()
|
||||||
.fixedSize(horizontal: true, vertical: true)
|
.fixedSize(horizontal: true, vertical: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
waveformView
|
waveformView
|
||||||
.waveformDragGesture($dragState)
|
.waveformInteraction(isDragging: $isDragging,
|
||||||
.progressCursor(progress: playerState.progress) {
|
progress: playerState.progress,
|
||||||
WaveformCursorView(color: .compound.iconAccentTertiary)
|
showCursor: showWaveformCursor,
|
||||||
.opacity(showWaveformCursor ? 1 : 0)
|
onSeek: onSeek)
|
||||||
.frame(width: waveformLineWidth)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.onChange(of: dragState) { newDragState in
|
|
||||||
switch newDragState {
|
|
||||||
case .inactive:
|
|
||||||
onScrubbing(false)
|
|
||||||
case .pressing:
|
|
||||||
onScrubbing(true)
|
|
||||||
feedbackGenerator.prepare()
|
|
||||||
sendFeedback = true
|
|
||||||
case .dragging(let progress):
|
|
||||||
if sendFeedback {
|
|
||||||
feedbackGenerator.impactOccurred()
|
|
||||||
sendFeedback = false
|
|
||||||
}
|
|
||||||
onSeek(max(0, min(progress, 1.0)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.padding(.leading, 2)
|
.padding(.leading, 2)
|
||||||
.padding(.trailing, 8)
|
.padding(.trailing, 8)
|
||||||
|
.onChange(of: isDragging) { isDragging in
|
||||||
|
onScrubbing(isDragging)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
@@ -122,37 +92,18 @@ struct VoiceMessageRoomPlaybackView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum DragState: Equatable {
|
private extension DateFormatter {
|
||||||
case inactive
|
static let elapsedTimeFormatter: DateFormatter = {
|
||||||
case pressing(progress: Double)
|
let dateFormatter = DateFormatter()
|
||||||
case dragging(progress: Double)
|
dateFormatter.dateFormat = "m:ss"
|
||||||
|
return dateFormatter
|
||||||
var progress: Double {
|
}()
|
||||||
switch self {
|
|
||||||
case .inactive, .pressing:
|
static let longElapsedTimeFormatter: DateFormatter = {
|
||||||
return .zero
|
let dateFormatter = DateFormatter()
|
||||||
case .dragging(let progress):
|
dateFormatter.dateFormat = "mm:ss"
|
||||||
return progress
|
return dateFormatter
|
||||||
}
|
}()
|
||||||
}
|
|
||||||
|
|
||||||
var isActive: Bool {
|
|
||||||
switch self {
|
|
||||||
case .inactive:
|
|
||||||
return false
|
|
||||||
case .pressing, .dragging:
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var isDragging: Bool {
|
|
||||||
switch self {
|
|
||||||
case .inactive, .pressing:
|
|
||||||
return false
|
|
||||||
case .dragging:
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VoiceMessageRoomPlaybackView_Previews: PreviewProvider, TestablePreview {
|
struct VoiceMessageRoomPlaybackView_Previews: PreviewProvider, TestablePreview {
|
||||||
|
|||||||
-2
@@ -52,9 +52,7 @@ struct VoiceMessageRoomTimelineView: View {
|
|||||||
resumePlaybackAfterScrubbing = true
|
resumePlaybackAfterScrubbing = true
|
||||||
context.send(viewAction: .playPauseAudio(itemID: timelineItem.id))
|
context.send(viewAction: .playPauseAudio(itemID: timelineItem.id))
|
||||||
}
|
}
|
||||||
context.send(viewAction: .disableLongPress(itemID: timelineItem.id))
|
|
||||||
} else {
|
} else {
|
||||||
context.send(viewAction: .enableLongPress(itemID: timelineItem.id))
|
|
||||||
if resumePlaybackAfterScrubbing {
|
if resumePlaybackAfterScrubbing {
|
||||||
context.send(viewAction: .playPauseAudio(itemID: timelineItem.id))
|
context.send(viewAction: .playPauseAudio(itemID: timelineItem.id))
|
||||||
resumePlaybackAfterScrubbing = false
|
resumePlaybackAfterScrubbing = false
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:09e3015e6bc13ff47decd46943fdee10c9c4b79d1361143f6d35e48c0822e5f8
|
oid sha256:6387ef1c9d6ba711f20718a3bf9c3f32d5af688dbdb078481301d4a5ccc88a69
|
||||||
size 93714
|
size 93719
|
||||||
|
|||||||
@@ -120,6 +120,3 @@ packages:
|
|||||||
DSWaveformImage:
|
DSWaveformImage:
|
||||||
url: https://github.com/dmrschmidt/DSWaveformImage
|
url: https://github.com/dmrschmidt/DSWaveformImage
|
||||||
exactVersion: 14.1.1
|
exactVersion: 14.1.1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user