Smooth player details panel drag on iOS

This commit is contained in:
Arkadiusz Fal
2026-04-20 01:18:06 +02:00
parent ad075319ee
commit 1ae73789a4
3 changed files with 23 additions and 7 deletions

View File

@@ -13,6 +13,8 @@ import UIKit
/// A transparent view that finds its parent UIScrollView and attaches an overscroll gesture handler.
/// Use as a `.background` on a SwiftUI `ScrollView` to intercept pull-down gestures at scroll top.
struct OverscrollGestureView: UIViewRepresentable {
/// Whether the handler should currently be attached.
var isEnabled: Bool = true
/// Called during the drag with the vertical translation (positive = pulling down)
var onDragChanged: ((CGFloat) -> Void)?
/// Called when the drag ends with translation and predicted end translation
@@ -30,6 +32,10 @@ struct OverscrollGestureView: UIViewRepresentable {
context.coordinator.onDragChanged = onDragChanged
context.coordinator.onDragEnded = onDragEnded
guard isEnabled else {
return view
}
// Schedule scroll view discovery after view is in hierarchy
DispatchQueue.main.async {
if let scrollView = Self.findScrollView(from: view) {
@@ -45,6 +51,11 @@ struct OverscrollGestureView: UIViewRepresentable {
context.coordinator.onDragChanged = onDragChanged
context.coordinator.onDragEnded = onDragEnded
guard isEnabled else {
context.coordinator.gestureHandler.detach()
return
}
// If not attached yet, try again
if context.coordinator.gestureHandler.scrollView == nil {
DispatchQueue.main.async {