NCAcknowledgementsView.swift 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // NCAcknowledgementsView.swift
  3. // Nextcloud
  4. //
  5. // Created by Aditya Tyagi on 04/03/24.
  6. // Copyright © 2024 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Aditya Tyagi <adityagi02@yahoo.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import SwiftUI
  24. /// Returns a WebView preferably for Sheets in SwiftUI, using a UIViewRepresentable struct with WebKit library
  25. ///
  26. /// - Parameters:
  27. /// - showText: A Bool value which initiates the RTF file view in the sheet
  28. /// - text: A String value which contains the text of RTF file
  29. /// - browserTitle: A String value to show as the title of the webView
  30. struct NCAcknowledgementsView: View {
  31. @State private var text = ""
  32. @State var showText: Bool = false
  33. var browserTitle: String
  34. @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
  35. var body: some View {
  36. VStack(spacing: 0) {
  37. HStack {
  38. HStack(alignment: .center) {
  39. Text(browserTitle)
  40. .font(.title3)
  41. .foregroundColor(Color(NCBrandColor.shared.textColor))
  42. .padding(.leading, 8)
  43. }
  44. .padding()
  45. Spacer()
  46. Button(action: {
  47. presentationMode.wrappedValue.dismiss()
  48. }) {
  49. ZStack {
  50. Image(systemName: "xmark")
  51. .renderingMode(.template)
  52. .resizable()
  53. .scaledToFit()
  54. .font(Font.system(.body).weight(.light))
  55. .frame(width: 14, height: 14)
  56. .foregroundColor(Color(NCBrandColor.shared.iconImageColor))
  57. }
  58. }
  59. .padding()
  60. }
  61. Divider()
  62. if showText {
  63. ScrollView {
  64. Text(text)
  65. .padding()
  66. }
  67. }
  68. }
  69. .navigationBarTitle(Text(NSLocalizedString("_autoupload_description_", comment: "")), displayMode: .inline)
  70. .onAppear {
  71. loadRTF()
  72. DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
  73. self.showText = true
  74. }
  75. }
  76. }
  77. func loadRTF() {
  78. if let rtfPath = Bundle.main.url(forResource: "Acknowledgements", withExtension: "rtf"),
  79. let attributedStringWithRtf = try? NSAttributedString(url: rtfPath, options: [.documentType: NSAttributedString.DocumentType.rtf], documentAttributes: nil) {
  80. self.text = attributedStringWithRtf.string
  81. }
  82. }
  83. }