From 63ffcbc4e78f9cee5c9532e5396509744e9a3405 Mon Sep 17 00:00:00 2001 From: Levitating Pineapple Date: Fri, 27 Sep 2024 15:33:21 +0300 Subject: [PATCH] instantanious longPress; tweak animations --- .../Shared/Views/ChatList/UserPicker.swift | 20 +++++++++++++------ .../Views/Helpers/SheetRepresentable.swift | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/ios/Shared/Views/ChatList/UserPicker.swift b/apps/ios/Shared/Views/ChatList/UserPicker.swift index f835e4c303..1effb109ab 100644 --- a/apps/ios/Shared/Views/ChatList/UserPicker.swift +++ b/apps/ios/Shared/Views/ChatList/UserPicker.swift @@ -22,7 +22,7 @@ struct UserPicker: View { // Inset grouped list dimensions private let imageSize: CGFloat = 44 private let rowPadding: CGFloat = 16 - private let rowVerticalPadding: CGFloat = 10 + private let rowVerticalPadding: CGFloat = 11 private let sectionSpacing: CGFloat = 35 private var sectionHorizontalPadding: CGFloat { frameWidth > 375 ? 20 : 16 } private let sectionShape = RoundedRectangle(cornerRadius: 10, style: .continuous) @@ -208,7 +208,7 @@ struct ListRow: ViewModifier { action: #selector(touchView.longPress(gesture:)) ) gesture.delegate = touchView - gesture.minimumPressDuration = 0.05 + gesture.minimumPressDuration = 0 touchView.addGestureRecognizer(gesture) return touchView } @@ -219,17 +219,25 @@ struct ListRow: ViewModifier { class TouchView: UIView, UIGestureRecognizerDelegate { var representer: TouchOverlay? - var startLocation: CGPoint? + private var startLocation: CGPoint? + private var task: Task? @objc func longPress(gesture: UILongPressGestureRecognizer) { switch gesture.state { case .began: startLocation = gesture.location(in: nil) - representer?.touchDown = true + task = Task { + do { + try await Task.sleep(nanoseconds: 100_000000) + await MainActor.run { representer?.touchDown = true } + } catch { } + } case .ended: + task?.cancel() if hitTest(gesture.location(in: self), with: nil) == self { - withAnimation(.easeOut(duration: 0.2)) { representer?.touchDown = false } + representer?.touchDown = true + withAnimation(.easeIn(duration: 0.05)) { representer?.touchDown = false } representer?.action() } else { representer?.touchDown = false @@ -241,8 +249,8 @@ struct ListRow: ViewModifier { let dy = location.y - startLocation.y if sqrt(pow(dx, 2) + pow(dy, 2)) > 10 { gesture.state = .failed } } - case .cancelled, .failed: + task?.cancel() representer?.touchDown = false default: break } diff --git a/apps/ios/Shared/Views/Helpers/SheetRepresentable.swift b/apps/ios/Shared/Views/Helpers/SheetRepresentable.swift index 45639090ec..526edd4781 100644 --- a/apps/ios/Shared/Views/Helpers/SheetRepresentable.swift +++ b/apps/ios/Shared/Views/Helpers/SheetRepresentable.swift @@ -8,7 +8,7 @@ import SwiftUI -private let sheetAnimationDuration: Double = 0.3 +private let sheetAnimationDuration: Double = 0.25 struct Sheet: ViewModifier { @Binding var isPresented: Bool