From 50d8bfaf1507b7333956cf635a8dfe6e9b6f9d8b Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Fri, 15 Nov 2024 16:13:42 +0100 Subject: [PATCH] Fix QuickLookPreview --- Linphone.xcodeproj/project.pbxproj | 8 -- .../Fragments/ChatBubbleView.swift | 35 +++---- Linphone/Utils/QuickLookPreview.swift | 83 ----------------- Linphone/Utils/ShareSheetController.swift | 91 ------------------- 4 files changed, 18 insertions(+), 199 deletions(-) delete mode 100644 Linphone/Utils/QuickLookPreview.swift delete mode 100644 Linphone/Utils/ShareSheetController.swift diff --git a/Linphone.xcodeproj/project.pbxproj b/Linphone.xcodeproj/project.pbxproj index b7b73212a..604966c47 100644 --- a/Linphone.xcodeproj/project.pbxproj +++ b/Linphone.xcodeproj/project.pbxproj @@ -94,7 +94,6 @@ D726E43F2B19E56F0083C415 /* StartCallViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D726E43E2B19E56F0083C415 /* StartCallViewModel.swift */; }; D72992392ADD7F68003AF125 /* HistoryContactFragment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D72992382ADD7F68003AF125 /* HistoryContactFragment.swift */; }; D72A9A052B9750A1000DC093 /* UIList.swift in Sources */ = {isa = PBXBuildFile; fileRef = D72A9A042B9750A1000DC093 /* UIList.swift */; }; - D732A9092AFD235500DB42BA /* ShareSheetController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D732A9082AFD235500DB42BA /* ShareSheetController.swift */; }; D732A90C2B0376F500DB42BA /* linphonerc-default in Resources */ = {isa = PBXBuildFile; fileRef = D732A90A2B0376F500DB42BA /* linphonerc-default */; }; D732A90D2B0376F500DB42BA /* linphonerc-factory in Resources */ = {isa = PBXBuildFile; fileRef = D732A90B2B0376F500DB42BA /* linphonerc-factory */; }; D732A90F2B04C3B400DB42BA /* HistoryFragment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D732A90E2B04C3B400DB42BA /* HistoryFragment.swift */; }; @@ -163,7 +162,6 @@ D7DA67622ACCB2FA00E95002 /* LoginFragment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7DA67612ACCB2FA00E95002 /* LoginFragment.swift */; }; D7DA67642ACCB31700E95002 /* ProfileModeFragment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7DA67632ACCB31700E95002 /* ProfileModeFragment.swift */; }; D7E2E69F2CE356C90080DA0D /* PopupViewWithTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7E2E69E2CE356C90080DA0D /* PopupViewWithTextField.swift */; }; - D7E2E6A12CE5F8850080DA0D /* QuickLookPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7E2E6A02CE5F87D0080DA0D /* QuickLookPreview.swift */; }; D7E6ADF32B9875C20009A2BC /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7E6ADF22B9875C20009A2BC /* Message.swift */; }; D7E6ADF52B9876ED0009A2BC /* Attachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7E6ADF42B9876ED0009A2BC /* Attachment.swift */; }; D7E6D0492AE933AD00A57AAF /* FavoriteContactsListFragment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7E6D0482AE933AD00A57AAF /* FavoriteContactsListFragment.swift */; }; @@ -286,7 +284,6 @@ D726E43E2B19E56F0083C415 /* StartCallViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartCallViewModel.swift; sourceTree = ""; }; D72992382ADD7F68003AF125 /* HistoryContactFragment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryContactFragment.swift; sourceTree = ""; }; D72A9A042B9750A1000DC093 /* UIList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIList.swift; sourceTree = ""; }; - D732A9082AFD235500DB42BA /* ShareSheetController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareSheetController.swift; sourceTree = ""; }; D732A90A2B0376F500DB42BA /* linphonerc-default */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "linphonerc-default"; sourceTree = ""; }; D732A90B2B0376F500DB42BA /* linphonerc-factory */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "linphonerc-factory"; sourceTree = ""; }; D732A90E2B04C3B400DB42BA /* HistoryFragment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryFragment.swift; sourceTree = ""; }; @@ -356,7 +353,6 @@ D7DA67612ACCB2FA00E95002 /* LoginFragment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginFragment.swift; sourceTree = ""; }; D7DA67632ACCB31700E95002 /* ProfileModeFragment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileModeFragment.swift; sourceTree = ""; }; D7E2E69E2CE356C90080DA0D /* PopupViewWithTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopupViewWithTextField.swift; sourceTree = ""; }; - D7E2E6A02CE5F87D0080DA0D /* QuickLookPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickLookPreview.swift; sourceTree = ""; }; D7E6ADF22B9875C20009A2BC /* Message.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = ""; }; D7E6ADF42B9876ED0009A2BC /* Attachment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Attachment.swift; sourceTree = ""; }; D7E6D0482AE933AD00A57AAF /* FavoriteContactsListFragment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteContactsListFragment.swift; sourceTree = ""; }; @@ -513,13 +509,11 @@ D7D1698B2AE66FA500109A5C /* MagicSearchSingleton.swift */, D74C9D002ACB098C0021626A /* PermissionManager.swift */, D7C3650D2AF15BF200FE6142 /* PhotoPicker.swift */, - D732A9082AFD235500DB42BA /* ShareSheetController.swift */, D7B99E9A2B29F7C200BE7BF2 /* ActivityIndicator.swift */, D7173EBD2B7A5C0A00BCC481 /* LinphoneUtils.swift */, C67586AF2C09F247002E77BF /* URIHandler.swift */, C6A5A9462C10B64A0070FEA4 /* SingleSignOn */, D79F2D092C47F4BF0038FA07 /* TouchFeedback.swift */, - D7E2E6A02CE5F87D0080DA0D /* QuickLookPreview.swift */, ); path = Utils; sourceTree = ""; @@ -1199,7 +1193,6 @@ D74C9CF82ACACECE0021626A /* WelcomePage1Fragment.swift in Sources */, 66E56BCE2BA9A1F8006CE56F /* MeetingModel.swift in Sources */, D7E6D0552AEBFCCE00A57AAF /* ContactsInnerFragment.swift in Sources */, - D732A9092AFD235500DB42BA /* ShareSheetController.swift in Sources */, D72343362AD037AF009AA24E /* ToastView.swift in Sources */, D7FB55112AD447FD00A5AB15 /* RegisterFragment.swift in Sources */, D7E6ADF32B9875C20009A2BC /* Message.swift in Sources */, @@ -1219,7 +1212,6 @@ 66F08C892C2AFEF700D9AE2F /* MeetingsListBottomSheet.swift in Sources */, D726E43F2B19E56F0083C415 /* StartCallViewModel.swift in Sources */, D70A26EE2B7CF60B006CC8FC /* ConversationsListBottomSheet.swift in Sources */, - D7E2E6A12CE5F8850080DA0D /* QuickLookPreview.swift in Sources */, D7D1698C2AE66FA500109A5C /* MagicSearchSingleton.swift in Sources */, D714DE602C1B3B34006C1F1D /* RegisterViewModel.swift in Sources */, D70C82A72C85F5910087F43F /* ConversationForwardMessageViewModel.swift in Sources */, diff --git a/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift b/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift index 920f71124..e4ccc2acf 100644 --- a/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift +++ b/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift @@ -19,11 +19,14 @@ import SwiftUI import WebKit +import QuickLook // swiftlint:disable type_body_length // swiftlint:disable cyclomatic_complexity struct ChatBubbleView: View { + private var idiom: UIUserInterfaceIdiom { UIDevice.current.userInterfaceIdiom } + @ObservedObject private var sharedMainViewModel = SharedMainViewModel.shared @ObservedObject var conversationViewModel: ConversationViewModel @@ -42,6 +45,10 @@ struct ChatBubbleView: View { @State private var selectedAttachment: Bool = false @State private var selectedAttachmentIndex: Int = 0 + @State private var selectedURLAttachment: URL? + + @State private var showShareSheet = false + var body: some View { HStack { if eventLogMessage.eventModel.eventLogType == .ConferenceChatMessage { @@ -491,9 +498,7 @@ struct ChatBubbleView: View { } UIApplication.shared.endEditing() } - .fullScreenCover(isPresented: $selectedAttachment) { - QuickLookFullScreenView(conversationViewModel: conversationViewModel, currentIndex: $selectedAttachmentIndex) - } + .quickLookPreview($selectedURLAttachment, in: conversationViewModel.attachments.map { $0.full }) } func containsDuplicates(strings: [String]) -> Bool { @@ -561,8 +566,7 @@ struct ChatBubbleView: View { .layoutPriority(-1) .clipShape(RoundedRectangle(cornerRadius: 4)) .onTapGesture { - selectedAttachmentIndex = conversationViewModel.getAttachmentIndex(attachment: eventLogMessage.message.attachments.first!) - selectedAttachment.toggle() + selectedURLAttachment = eventLogMessage.message.attachments.first!.full } } else { AsyncImage(url: eventLogMessage.message.attachments.first!.thumbnail) { phase in @@ -594,8 +598,7 @@ struct ChatBubbleView: View { .clipShape(RoundedRectangle(cornerRadius: 4)) .id(UUID()) .onTapGesture { - selectedAttachmentIndex = conversationViewModel.getAttachmentIndex(attachment: eventLogMessage.message.attachments.first!) - selectedAttachment.toggle() + selectedURLAttachment = eventLogMessage.message.attachments.first!.full } } } else if eventLogMessage.message.attachments.first!.type == .gif { @@ -603,18 +606,18 @@ struct ChatBubbleView: View { GifImageView(eventLogMessage.message.attachments.first!.thumbnail) .layoutPriority(-1) .clipShape(RoundedRectangle(cornerRadius: 4)) + .contentShape(Rectangle()) .onTapGesture { - selectedAttachmentIndex = conversationViewModel.getAttachmentIndex(attachment: eventLogMessage.message.attachments.first!) - selectedAttachment.toggle() + selectedURLAttachment = eventLogMessage.message.attachments.first!.full } } else { GifImageView(eventLogMessage.message.attachments.first!.thumbnail) .id(UUID()) .layoutPriority(-1) .clipShape(RoundedRectangle(cornerRadius: 4)) + .contentShape(Rectangle()) .onTapGesture { - selectedAttachmentIndex = conversationViewModel.getAttachmentIndex(attachment: eventLogMessage.message.attachments.first!) - selectedAttachment.toggle() + selectedURLAttachment = eventLogMessage.message.attachments.first!.full } } } @@ -659,8 +662,7 @@ struct ChatBubbleView: View { .background(.white) .clipShape(RoundedRectangle(cornerRadius: 10)) .onTapGesture { - selectedAttachmentIndex = conversationViewModel.getAttachmentIndex(attachment: eventLogMessage.message.attachments.first!) - selectedAttachment.toggle() + selectedURLAttachment = eventLogMessage.message.attachments.first!.full } } } else if eventLogMessage.message.attachments.count > 1 { @@ -695,8 +697,7 @@ struct ChatBubbleView: View { } .layoutPriority(-1) .onTapGesture { - selectedAttachmentIndex = conversationViewModel.getAttachmentIndex(attachment: attachment) - selectedAttachment.toggle() + selectedURLAttachment = attachment.full } } else { AsyncImage(url: attachment.thumbnail) { image in @@ -720,8 +721,7 @@ struct ChatBubbleView: View { .id(UUID()) .layoutPriority(-1) .onTapGesture { - selectedAttachmentIndex = conversationViewModel.getAttachmentIndex(attachment: attachment) - selectedAttachment.toggle() + selectedURLAttachment = attachment.full } } } @@ -853,6 +853,7 @@ struct GifImageView: UIViewRepresentable { if data != nil { webview.load(data!, mimeType: "image/gif", characterEncodingName: "UTF-8", baseURL: url.deletingLastPathComponent()) webview.scrollView.isScrollEnabled = false + webview.isUserInteractionEnabled = false } return webview } diff --git a/Linphone/Utils/QuickLookPreview.swift b/Linphone/Utils/QuickLookPreview.swift deleted file mode 100644 index d0c081b46..000000000 --- a/Linphone/Utils/QuickLookPreview.swift +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2010-2023 Belledonne Communications SARL. - * - * This file is part of linphone-iphone - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -import SwiftUI -import QuickLook - -struct QuickLookFullScreenView: View { - @Environment(\.presentationMode) var presentationMode - - @ObservedObject var conversationViewModel: ConversationViewModel - - @Binding var currentIndex: Int - - var body: some View { - NavigationView { - QuickLookPreview(fileURLs: conversationViewModel.attachments.map { $0.full }, startIndex: currentIndex) - .navigationBarTitleDisplayMode(.inline) - .toolbar { - ToolbarItem(placement: .principal) { - Text(conversationViewModel.attachments.first?.name ?? "File error") - .lineLimit(1) - .truncationMode(.middle) - .font(.headline) - } - } - .navigationBarItems(trailing: Button("Close") { - presentationMode.wrappedValue.dismiss() - }) - } - } -} - -struct QuickLookPreview: UIViewControllerRepresentable { - let fileURLs: [URL] - let startIndex: Int - - func makeUIViewController(context: Context) -> QLPreviewController { - let previewController = QLPreviewController() - previewController.dataSource = context.coordinator - previewController.currentPreviewItemIndex = startIndex // Définir l’index de départ - return previewController - } - - func updateUIViewController(_ uiViewController: QLPreviewController, context: Context) { - // No update needed - } - - func makeCoordinator() -> Coordinator { - Coordinator(self) - } - - class Coordinator: NSObject, QLPreviewControllerDataSource { - var parent: QuickLookPreview - - init(_ parent: QuickLookPreview) { - self.parent = parent - } - - func numberOfPreviewItems(in controller: QLPreviewController) -> Int { - return parent.fileURLs.count - } - - func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem { - return parent.fileURLs[index] as QLPreviewItem - } - } -} diff --git a/Linphone/Utils/ShareSheetController.swift b/Linphone/Utils/ShareSheetController.swift deleted file mode 100644 index 8a512713c..000000000 --- a/Linphone/Utils/ShareSheetController.swift +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2010-2023 Belledonne Communications SARL. - * - * This file is part of linphone-iphone - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -import Foundation -import SwiftUI -import linphonesw - -struct ShareSheet: UIViewControllerRepresentable { - typealias Callback = (_ activityType: UIActivity.ActivityType?, _ completed: Bool, _ returnedItems: [Any]?, _ error: Error?) -> Void - - let friendToShare: Friend - var activityItems: [Any] = [] - let applicationActivities: [UIActivity]? = nil - let excludedActivityTypes: [UIActivity.ActivityType]? = nil - let callback: Callback? = nil - - func makeUIViewController(context: Context) -> UIActivityViewController { - let directoryURL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first - - if directoryURL != nil { - if friendToShare.name != nil { - let filename = friendToShare.name!.replacingOccurrences(of: " ", with: "") - - let fileURL = directoryURL! - .appendingPathComponent(filename) - .appendingPathExtension("vcf") - - if friendToShare.vcard != nil { - try? friendToShare.vcard!.asVcard4String().write(to: fileURL, atomically: false, encoding: String.Encoding.utf8) - - let controller = UIActivityViewController( - activityItems: [fileURL], - applicationActivities: applicationActivities - ) - controller.excludedActivityTypes = excludedActivityTypes - controller.completionWithItemsHandler = callback - return controller - } - } - } - - let controller = UIActivityViewController( - activityItems: activityItems, - applicationActivities: applicationActivities) - controller.excludedActivityTypes = excludedActivityTypes - controller.completionWithItemsHandler = callback - return controller - } - - func updateUIViewController(_ uiViewController: UIActivityViewController, context: Context) { - // nothing to do here - } - - func shareContacts(friend: String) { - - let directoryURL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first - - if directoryURL != nil { - let filename = NSUUID().uuidString - - let fileURL = directoryURL! - .appendingPathComponent(filename) - .appendingPathExtension("vcf") - - try? friend.write(to: fileURL, atomically: false, encoding: String.Encoding.utf8) - } - - /* - let activityViewController = UIActivityViewController( - activityItems: [fileURL], - applicationActivities: nil - ) - */ - } -}