Skip to content

Commit

Permalink
Make sure to clean-up any previews when the coordinator is done.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Feb 5, 2025
1 parent 5098b42 commit 4fe21b6
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ final class MediaEventsTimelineScreenCoordinator: CoordinatorProtocol {
.store(in: &cancellables)
}

func stop() {
viewModel.stop()
}

func toPresentable() -> AnyView {
AnyView(MediaEventsTimelineScreen(context: viewModel.context))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ class MediaEventsTimelineScreenViewModel: MediaEventsTimelineScreenViewModelType
}
}

func stop() {
// Work around QLPreviewController dismissal issues, see the InteractiveQuickLookModifier.
state.bindings.mediaPreviewViewModel = nil
}

// MARK: - Private

private func updateWithTimelineViewState(_ timelineViewState: TimelineViewState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ import Combine
protocol MediaEventsTimelineScreenViewModelProtocol {
var actionsPublisher: AnyPublisher<MediaEventsTimelineScreenViewModelAction, Never> { get }
var context: MediaEventsTimelineScreenViewModelType.Context { get }

func stop()
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ final class PinnedEventsTimelineScreenCoordinator: CoordinatorProtocol {
}
.store(in: &cancellables)
}

func stop() {
viewModel.stop()
}

func toPresentable() -> AnyView {
AnyView(PinnedEventsTimelineScreen(context: viewModel.context, timelineContext: timelineViewModel.context))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class PinnedEventsTimelineScreenViewModel: PinnedEventsTimelineScreenViewModelTy
}
}

func stop() {
// Work around QLPreviewController dismissal issues, see the InteractiveQuickLookModifier.
state.bindings.mediaPreviewViewModel = nil
}

func displayMediaPreview(_ mediaPreviewViewModel: TimelineMediaPreviewViewModel) {
mediaPreviewViewModel.actions.sink { [weak self] action in
switch action {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ protocol PinnedEventsTimelineScreenViewModelProtocol {
var actionsPublisher: AnyPublisher<PinnedEventsTimelineScreenViewModelAction, Never> { get }
var context: PinnedEventsTimelineScreenViewModelType.Context { get }

func stop()

func displayMediaPreview(_ mediaPreviewViewModel: TimelineMediaPreviewViewModel)
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ final class RoomScreenCoordinator: CoordinatorProtocol {

func stop() {
composerViewModel.saveDraft()
timelineViewModel.stop()
roomViewModel.stop()
}

func toPresentable() -> AnyView {
Expand Down
5 changes: 5 additions & 0 deletions ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
}
}

func stop() {
// Work around QLPreviewController dismissal issues, see the InteractiveQuickLookModifier.
state.bindings.mediaPreviewViewModel = nil
}

func timelineHasScrolled(direction: ScrollDirection) {
state.lastScrollDirection = direction
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ protocol RoomScreenViewModelProtocol {
var actions: AnyPublisher<RoomScreenViewModelAction, Never> { get }
var context: RoomScreenViewModel.Context { get }

func stop()

func timelineHasScrolled(direction: ScrollDirection)
func setSelectedPinnedEventID(_ eventID: String)
func displayMediaPreview(_ mediaPreviewViewModel: TimelineMediaPreviewViewModel)
Expand Down
5 changes: 0 additions & 5 deletions ElementX/Sources/Screens/Timeline/TimelineViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {

// MARK: - Public

func stop() {
// Work around QLPreviewController dismissal issues, see the InteractiveQuickLookModifier.
// state.bindings.mediaPreviewViewModel = nil
}

override func process(viewAction: TimelineViewAction) {
switch viewAction {
case .itemAppeared(let id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import SwiftUI
protocol TimelineViewModelProtocol {
var actions: AnyPublisher<TimelineViewModelAction, Never> { get }
var context: TimelineViewModel.Context { get }

func process(composerAction: ComposerToolbarViewModelAction)
/// Updates the timeline to show and highlight the item with the corresponding event ID.
func focusOnEvent(eventID: String) async
func stop()
}

0 comments on commit 4fe21b6

Please sign in to comment.