From 1992bfc73715e1ff5b13fe323f876efb4ef93432 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 19 Dec 2022 12:17:37 +0200 Subject: [PATCH] Fixes #329 - Simplify video player UI until we agree on final designs. (#375) --- .../FilePreview/View/FilePreviewScreen.swift | 3 ++- .../RoomScreen/RoomScreenCoordinator.swift | 23 +++++----------- .../VideoPlayer/VideoPlayerCoordinator.swift | 4 +-- .../VideoPlayer/VideoPlayerModels.swift | 1 - .../VideoPlayer/VideoPlayerViewModel.swift | 5 ++-- .../VideoPlayer/View/VideoPlayerScreen.swift | 27 ++----------------- 6 files changed, 13 insertions(+), 50 deletions(-) diff --git a/ElementX/Sources/Screens/FilePreview/View/FilePreviewScreen.swift b/ElementX/Sources/Screens/FilePreview/View/FilePreviewScreen.swift index b37310b5c..838b35044 100644 --- a/ElementX/Sources/Screens/FilePreview/View/FilePreviewScreen.swift +++ b/ElementX/Sources/Screens/FilePreview/View/FilePreviewScreen.swift @@ -23,7 +23,8 @@ struct FilePreviewScreen: View { var body: some View { PreviewController(fileURL: context.viewState.fileURL, title: context.viewState.title) - .ignoresSafeArea() + .ignoresSafeArea(.all, edges: [.horizontal, .bottom]) + .navigationTitle(ElementL10n.attachmentTypeFile) } } diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift index ec95a899b..13454dce0 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift @@ -81,25 +81,14 @@ final class RoomScreenCoordinator: CoordinatorProtocol { // MARK: - Private private func displayVideo(for videoURL: URL) { - let params = VideoPlayerCoordinatorParameters(videoURL: videoURL, isModallyPresented: false) + let params = VideoPlayerCoordinatorParameters(videoURL: videoURL) let coordinator = VideoPlayerCoordinator(parameters: params) - - if params.isModallyPresented { - coordinator.callback = { [weak self] _ in - self?.navigationStackCoordinator.setSheetCoordinator(nil) - } - - let controller = NavigationStackCoordinator() - controller.setRootCoordinator(coordinator) - - navigationStackCoordinator.setSheetCoordinator(controller) - } else { - coordinator.callback = { [weak self] _ in - self?.navigationStackCoordinator.pop() - } - - navigationStackCoordinator.push(coordinator) + + coordinator.callback = { [weak self] _ in + self?.navigationStackCoordinator.pop() } + + navigationStackCoordinator.push(coordinator) } private func displayFile(for fileURL: URL, with title: String?) { diff --git a/ElementX/Sources/Screens/VideoPlayer/VideoPlayerCoordinator.swift b/ElementX/Sources/Screens/VideoPlayer/VideoPlayerCoordinator.swift index 26b71f623..ae3f2ee29 100644 --- a/ElementX/Sources/Screens/VideoPlayer/VideoPlayerCoordinator.swift +++ b/ElementX/Sources/Screens/VideoPlayer/VideoPlayerCoordinator.swift @@ -19,7 +19,6 @@ import SwiftUI struct VideoPlayerCoordinatorParameters { let videoURL: URL - let isModallyPresented: Bool } enum VideoPlayerCoordinatorAction { @@ -36,8 +35,7 @@ final class VideoPlayerCoordinator: CoordinatorProtocol { self.parameters = parameters viewModel = VideoPlayerViewModel(videoURL: parameters.videoURL, - autoplay: UIApplication.shared.applicationState == .active, - isModallyPresented: parameters.isModallyPresented) + autoplay: UIApplication.shared.applicationState == .active) } // MARK: - Public diff --git a/ElementX/Sources/Screens/VideoPlayer/VideoPlayerModels.swift b/ElementX/Sources/Screens/VideoPlayer/VideoPlayerModels.swift index 8cf878d46..c2aaa51f6 100644 --- a/ElementX/Sources/Screens/VideoPlayer/VideoPlayerModels.swift +++ b/ElementX/Sources/Screens/VideoPlayer/VideoPlayerModels.swift @@ -23,7 +23,6 @@ enum VideoPlayerViewModelAction { struct VideoPlayerViewState: BindableState { let videoURL: URL let autoplay: Bool - let isModallyPresented: Bool } enum VideoPlayerViewAction { diff --git a/ElementX/Sources/Screens/VideoPlayer/VideoPlayerViewModel.swift b/ElementX/Sources/Screens/VideoPlayer/VideoPlayerViewModel.swift index aa9177eb9..abb18c176 100644 --- a/ElementX/Sources/Screens/VideoPlayer/VideoPlayerViewModel.swift +++ b/ElementX/Sources/Screens/VideoPlayer/VideoPlayerViewModel.swift @@ -21,10 +21,9 @@ typealias VideoPlayerViewModelType = StateStoreViewModel Void)? - init(videoURL: URL, autoplay: Bool = true, isModallyPresented: Bool = true) { + init(videoURL: URL, autoplay: Bool = true) { super.init(initialViewState: VideoPlayerViewState(videoURL: videoURL, - autoplay: autoplay, - isModallyPresented: isModallyPresented)) + autoplay: autoplay)) } override func process(viewAction: VideoPlayerViewAction) async { diff --git a/ElementX/Sources/Screens/VideoPlayer/View/VideoPlayerScreen.swift b/ElementX/Sources/Screens/VideoPlayer/View/VideoPlayerScreen.swift index f12f5eb4a..859c895bb 100644 --- a/ElementX/Sources/Screens/VideoPlayer/View/VideoPlayerScreen.swift +++ b/ElementX/Sources/Screens/VideoPlayer/View/VideoPlayerScreen.swift @@ -22,31 +22,8 @@ struct VideoPlayerScreen: View { var body: some View { VideoPlayer(player: player()) - .background(Color.black.ignoresSafeArea()) - .navigationBarTitleDisplayMode(.inline) - .navigationBarBackButtonHidden() - .toolbar { toolbar } - .onSwipeGesture(minimumDistance: 3.0, down: { - if context.viewState.isModallyPresented { - context.send(viewAction: .cancel) - } - }, right: { - if !context.viewState.isModallyPresented { - context.send(viewAction: .cancel) - } - }) - } - - @ToolbarContentBuilder - var toolbar: some ToolbarContent { - ToolbarItem(placement: .cancellationAction) { - Button { context.send(viewAction: .cancel) } label: { - Image(systemName: context.viewState.isModallyPresented ? "xmark" : "chevron.backward") - .foregroundColor(.white) - .fontWeight(.semibold) - } - .accessibilityIdentifier("dismissButton") - } + .ignoresSafeArea(.all, edges: [.horizontal, .bottom]) + .navigationTitle(ElementL10n.a11yVideo) } private func player() -> AVPlayer {