From bec5eb74ece44dcae5dfc72b92db96f8760b56af Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Tue, 18 Apr 2023 11:06:37 +0200 Subject: [PATCH] feat: Selectable text view --- Mail/Views/Thread/MessageBodyView.swift | 4 +-- Mail/Views/Thread/SelectableTextView.swift | 40 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 Mail/Views/Thread/SelectableTextView.swift diff --git a/Mail/Views/Thread/MessageBodyView.swift b/Mail/Views/Thread/MessageBodyView.swift index 6b8bb3a77..9099fa36b 100644 --- a/Mail/Views/Thread/MessageBodyView.swift +++ b/Mail/Views/Thread/MessageBodyView.swift @@ -34,9 +34,7 @@ struct MessageBodyView: View { VStack { if let body = presentableBody.body { if body.type == "text/plain" { - Text(body.value ?? "") - .textStyle(.body) - .frame(maxWidth: .infinity, alignment: .leading) + SelectableTextView(text: body.value) .padding(.horizontal, 16) } else { GeometryReader { proxy in diff --git a/Mail/Views/Thread/SelectableTextView.swift b/Mail/Views/Thread/SelectableTextView.swift new file mode 100644 index 000000000..196962baa --- /dev/null +++ b/Mail/Views/Thread/SelectableTextView.swift @@ -0,0 +1,40 @@ +/* + Infomaniak Mail - iOS App + Copyright (C) 2022 Infomaniak Network SA + + 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 MailCore +import SwiftUI + +struct SelectableTextView: UIViewRepresentable { + let text: String? + func makeUIView(context: Context) -> UITextView { + let textView = UITextView() + textView.isScrollEnabled = false + textView.isEditable = false + textView.textContainer.lineFragmentPadding = 0 + textView.font = .systemFont(ofSize: 16) + textView.textColor = UIColor(MailTextStyle.body.color) + + textView.text = text + return textView + } + + func updateUIView(_ uiView: UITextView, context: Context) { + uiView.text = text + } +}