Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the interactive dismiss gesture of media previews on iOS 18.2 #3636

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Member Author

@pixlwave pixlwave Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timing of this being called changed from after the animation had completed (which presumably was to do with the preview controller as it doesn't make sense looking at the navigation stack code), to as soon as you lift your finger on the drag (which is too early to undo the flip).

Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ class MediaEventsTimelineFlowCoordinator: FlowCoordinatorProtocol {
}
.store(in: &cancellables)

navigationStackCoordinator.setFullScreenCoverCoordinator(coordinator) {
previewContext.completion?()
}
navigationStackCoordinator.setFullScreenCoverCoordinator(coordinator)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ final class TimelineMediaPreviewCoordinator: CoordinatorProtocol {
}

func toPresentable() -> AnyView {
AnyView(TimelineMediaPreviewScreen(context: viewModel.context))
// Calling the completion onDisappear isn't ideal, but we don't push away from the screen so it should be
// a good enough approximation of didDismiss, given that the only other option is our navigation callbacks
// which are essentially willDismiss callbacks and happen too early for this particular completion handler.
AnyView(TimelineMediaPreviewScreen(context: viewModel.context, onDisappear: parameters.context.completion))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import SwiftUI

struct TimelineMediaPreviewScreen: View {
@ObservedObject var context: TimelineMediaPreviewViewModel.Context
var onDisappear: (() -> Void)?

private var currentItem: TimelineMediaPreviewItem { context.viewState.currentItem }

var body: some View {
NavigationStack {
Color.clear
.overlay { QuickLookView(viewModelContext: context).ignoresSafeArea() } // Overlay to stop QL hijacking the toolbar.
Color.black
.opacity(0.01) // A completely clear view breaks any SwiftUI gestures (such as drag to dismiss).
.background { QuickLookView(viewModelContext: context).ignoresSafeArea() } // Not the root view to stop QL hijacking the toolbar.
.toolbar { toolbar }
.toolbarBackground(.visible, for: .navigationBar) // The toolbar's scrollEdgeAppearance isn't aware of the quicklook view 🤷‍♂️
.toolbarBackground(.visible, for: .bottomBar)
Expand All @@ -39,6 +41,9 @@ struct TimelineMediaPreviewScreen: View {
}
.alert(item: $context.alertInfo)
.preferredColorScheme(.dark)
.onDisappear {
onDisappear?()
}
.zoomTransition(sourceID: currentItem.id, in: context.viewState.transitionNamespace)
}

Expand Down Expand Up @@ -114,6 +119,8 @@ struct TimelineMediaPreviewScreen: View {
}
}

// MARK: - QuickLook

private struct QuickLookView: UIViewControllerRepresentable {
let viewModelContext: TimelineMediaPreviewViewModel.Context

Expand All @@ -128,6 +135,8 @@ private struct QuickLookView: UIViewControllerRepresentable {
Coordinator(viewModelContext: viewModelContext)
}

// MARK: Coordinator

class Coordinator: NSObject, QLPreviewControllerDataSource, QLPreviewControllerDelegate {
private let viewModelContext: TimelineMediaPreviewViewModel.Context

Expand All @@ -148,6 +157,8 @@ private struct QuickLookView: UIViewControllerRepresentable {
}
}

// MARK: UIKit

class PreviewController: QLPreviewController {
let coordinator: Coordinator

Expand Down
Loading