mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Fixes #1140 - Dismiss all modals when presenting a room
This commit is contained in:
committed by
Stefan Ceriu
parent
8a69ca1ce0
commit
a73502a146
@@ -259,6 +259,10 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func asyncPresentRoom(_ roomID: String, animated: Bool, destinationRoomProxy: RoomProxyProtocol? = nil) async {
|
private func asyncPresentRoom(_ roomID: String, animated: Bool, destinationRoomProxy: RoomProxyProtocol? = nil) async {
|
||||||
|
// If any sheets are presented dismiss them, rely on their dismissal callbacks to transition the state machine
|
||||||
|
// through the correct states before presenting the room
|
||||||
|
navigationStackCoordinator.setSheetCoordinator(nil)
|
||||||
|
|
||||||
if let roomProxy, roomProxy.id == roomID {
|
if let roomProxy, roomProxy.id == roomID {
|
||||||
navigationStackCoordinator.popToRoot()
|
navigationStackCoordinator.popToRoot()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import Combine
|
||||||
import QuickLook
|
import QuickLook
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
@@ -28,10 +29,15 @@ extension View {
|
|||||||
private struct InteractiveQuickLookModifier: ViewModifier {
|
private struct InteractiveQuickLookModifier: ViewModifier {
|
||||||
@Binding var item: MediaPreviewItem?
|
@Binding var item: MediaPreviewItem?
|
||||||
|
|
||||||
|
@State private var dismissalPublisher = PassthroughSubject<Void, Never>()
|
||||||
|
|
||||||
func body(content: Content) -> some View {
|
func body(content: Content) -> some View {
|
||||||
content.background {
|
content.background {
|
||||||
if let item {
|
if let item {
|
||||||
MediaPreviewViewController(previewItem: item) { self.item = nil }
|
MediaPreviewViewController(previewItem: item, dismissalPublisher: dismissalPublisher) { self.item = nil }
|
||||||
|
} else {
|
||||||
|
// Work around QLPreviewController dismissal issues, see below.
|
||||||
|
let _ = dismissalPublisher.send(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,10 +45,11 @@ private struct InteractiveQuickLookModifier: ViewModifier {
|
|||||||
|
|
||||||
private struct MediaPreviewViewController: UIViewControllerRepresentable {
|
private struct MediaPreviewViewController: UIViewControllerRepresentable {
|
||||||
let previewItem: MediaPreviewItem
|
let previewItem: MediaPreviewItem
|
||||||
|
let dismissalPublisher: PassthroughSubject<Void, Never>
|
||||||
let onDismiss: () -> Void
|
let onDismiss: () -> Void
|
||||||
|
|
||||||
func makeUIViewController(context: Context) -> PreviewHostingController {
|
func makeUIViewController(context: Context) -> PreviewHostingController {
|
||||||
PreviewHostingController(previewItem: previewItem, onDismiss: onDismiss)
|
PreviewHostingController(previewItem: previewItem, dismissalPublisher: dismissalPublisher, onDismiss: onDismiss)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateUIViewController(_ uiViewController: PreviewHostingController, context: Context) { }
|
func updateUIViewController(_ uiViewController: PreviewHostingController, context: Context) { }
|
||||||
@@ -53,15 +60,26 @@ private struct MediaPreviewViewController: UIViewControllerRepresentable {
|
|||||||
/// animations and interactions which don't work if you represent it directly to SwiftUI 🤷♂️
|
/// animations and interactions which don't work if you represent it directly to SwiftUI 🤷♂️
|
||||||
class PreviewHostingController: UIViewController, QLPreviewControllerDataSource, QLPreviewControllerDelegate {
|
class PreviewHostingController: UIViewController, QLPreviewControllerDataSource, QLPreviewControllerDelegate {
|
||||||
let previewItem: MediaPreviewItem
|
let previewItem: MediaPreviewItem
|
||||||
|
let dismissalPublisher: PassthroughSubject<Void, Never>
|
||||||
let onDismiss: () -> Void
|
let onDismiss: () -> Void
|
||||||
|
|
||||||
|
private var dismissalObserver: AnyCancellable?
|
||||||
|
|
||||||
var previewController: QLPreviewController?
|
var previewController: QLPreviewController?
|
||||||
|
|
||||||
init(previewItem: MediaPreviewItem, onDismiss: @escaping () -> Void) {
|
init(previewItem: MediaPreviewItem, dismissalPublisher: PassthroughSubject<Void, Never>, onDismiss: @escaping () -> Void) {
|
||||||
self.previewItem = previewItem
|
self.previewItem = previewItem
|
||||||
|
self.dismissalPublisher = dismissalPublisher
|
||||||
self.onDismiss = onDismiss
|
self.onDismiss = onDismiss
|
||||||
|
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
|
|
||||||
|
// The QLPreviewController will not automatically dismiss itself when the underlying view is removed
|
||||||
|
// (e.g. switching rooms from a notification) and it continues to hold on to the whole hierarcy.
|
||||||
|
// Manually tell it to dismiss itself here.
|
||||||
|
dismissalObserver = dismissalPublisher.sink { _ in
|
||||||
|
self.dismiss(animated: true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, unavailable)
|
@available(*, unavailable)
|
||||||
@@ -125,6 +143,6 @@ struct PreviewView_Previews: PreviewProvider {
|
|||||||
title: "Important Document")
|
title: "Important Document")
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
MediaPreviewViewController(previewItem: previewItem) { }
|
MediaPreviewViewController(previewItem: previewItem, dismissalPublisher: .init()) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,10 @@ final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stop() {
|
||||||
|
viewModel.stop()
|
||||||
|
}
|
||||||
|
|
||||||
func toPresentable() -> AnyView {
|
func toPresentable() -> AnyView {
|
||||||
AnyView(RoomDetailsScreen(context: viewModel.context))
|
AnyView(RoomDetailsScreen(context: viewModel.context))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
|||||||
|
|
||||||
// MARK: - Public
|
// MARK: - Public
|
||||||
|
|
||||||
|
func stop() {
|
||||||
|
// Work around QLPreviewController dismissal issues, see the InteractiveQuickLookModifier.
|
||||||
|
state.bindings.mediaPreviewItem = nil
|
||||||
|
}
|
||||||
|
|
||||||
override func process(viewAction: RoomDetailsScreenViewAction) {
|
override func process(viewAction: RoomDetailsScreenViewAction) {
|
||||||
switch viewAction {
|
switch viewAction {
|
||||||
case .processTapPeople:
|
case .processTapPeople:
|
||||||
|
|||||||
@@ -20,4 +20,5 @@ import Foundation
|
|||||||
protocol RoomDetailsScreenViewModelProtocol {
|
protocol RoomDetailsScreenViewModelProtocol {
|
||||||
var callback: ((RoomDetailsScreenViewModelAction) -> Void)? { get set }
|
var callback: ((RoomDetailsScreenViewModelAction) -> Void)? { get set }
|
||||||
var context: RoomDetailsScreenViewModelType.Context { get }
|
var context: RoomDetailsScreenViewModelType.Context { get }
|
||||||
|
func stop()
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -41,6 +41,8 @@ final class RoomMemberDetailsScreenCoordinator: CoordinatorProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func start() { }
|
func start() { }
|
||||||
|
|
||||||
|
func stop() { viewModel.stop() }
|
||||||
|
|
||||||
func toPresentable() -> AnyView {
|
func toPresentable() -> AnyView {
|
||||||
AnyView(RoomMemberDetailsScreen(context: viewModel.context))
|
AnyView(RoomMemberDetailsScreen(context: viewModel.context))
|
||||||
|
|||||||
+5
@@ -43,6 +43,11 @@ class RoomMemberDetailsScreenViewModel: RoomMemberDetailsScreenViewModelType, Ro
|
|||||||
|
|
||||||
// MARK: - Public
|
// MARK: - Public
|
||||||
|
|
||||||
|
func stop() {
|
||||||
|
// Work around QLPreviewController dismissal issues, see the InteractiveQuickLookModifier.
|
||||||
|
state.bindings.mediaPreviewItem = nil
|
||||||
|
}
|
||||||
|
|
||||||
override func process(viewAction: RoomMemberDetailsScreenViewAction) {
|
override func process(viewAction: RoomMemberDetailsScreenViewAction) {
|
||||||
switch viewAction {
|
switch viewAction {
|
||||||
case .showUnignoreAlert:
|
case .showUnignoreAlert:
|
||||||
|
|||||||
+1
@@ -20,4 +20,5 @@ import Foundation
|
|||||||
protocol RoomMemberDetailsScreenViewModelProtocol {
|
protocol RoomMemberDetailsScreenViewModelProtocol {
|
||||||
var callback: ((RoomMemberDetailsScreenViewModelAction) -> Void)? { get set }
|
var callback: ((RoomMemberDetailsScreenViewModelAction) -> Void)? { get set }
|
||||||
var context: RoomMemberDetailsScreenViewModelType.Context { get }
|
var context: RoomMemberDetailsScreenViewModelType.Context { get }
|
||||||
|
func stop()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,6 +106,10 @@ final class RoomScreenCoordinator: CoordinatorProtocol {
|
|||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stop() {
|
||||||
|
viewModel.stop()
|
||||||
|
}
|
||||||
|
|
||||||
func toPresentable() -> AnyView {
|
func toPresentable() -> AnyView {
|
||||||
AnyView(RoomScreen(context: viewModel.context, composerToolbar: ComposerToolbar(context: composerViewModel.context)))
|
AnyView(RoomScreen(context: viewModel.context, composerToolbar: ComposerToolbar(context: composerViewModel.context)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,6 +89,11 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
actionsSubject.eraseToAnyPublisher()
|
actionsSubject.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stop() {
|
||||||
|
// Work around QLPreviewController dismissal issues, see the InteractiveQuickLookModifier.
|
||||||
|
state.bindings.mediaPreviewItem = nil
|
||||||
|
}
|
||||||
|
|
||||||
override func process(viewAction: RoomScreenViewAction) {
|
override func process(viewAction: RoomScreenViewAction) {
|
||||||
switch viewAction {
|
switch viewAction {
|
||||||
case .displayRoomDetails:
|
case .displayRoomDetails:
|
||||||
|
|||||||
@@ -23,4 +23,5 @@ protocol RoomScreenViewModelProtocol {
|
|||||||
var actions: AnyPublisher<RoomScreenViewModelAction, Never> { get }
|
var actions: AnyPublisher<RoomScreenViewModelAction, Never> { get }
|
||||||
var context: RoomScreenViewModelType.Context { get }
|
var context: RoomScreenViewModelType.Context { get }
|
||||||
func process(composerAction: ComposerToolbarViewModelAction)
|
func process(composerAction: ComposerToolbarViewModelAction)
|
||||||
|
func stop()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Prevent inconsistent view hierarchies when opening rooms from push notifications
|
||||||
Reference in New Issue
Block a user