diff --git a/Core/Core/Configuration/CSSInjector.swift b/Core/Core/Configuration/CSSInjector.swift index efd18643c..7161965c5 100644 --- a/Core/Core/Configuration/CSSInjector.swift +++ b/Core/Core/Configuration/CSSInjector.swift @@ -95,9 +95,17 @@ public class CSSInjector { var maxWidth: String switch type { case .discovery: - maxWidth = "max-width: \(screenWidth)px;" + if screenWidth == .infinity { + maxWidth = "max-width: 100%;" + } else { + maxWidth = "max-width: \(screenWidth)px;" + } case .comment: - maxWidth = "width: \(screenWidth / 1.3)px;" + if screenWidth == .infinity { + maxWidth = "width: 100%;" + } else { + maxWidth = "width: \(screenWidth / 1.3)px;" + } } func currentColor() -> String { diff --git a/Course/Course/Presentation/Handouts/HandoutsUpdatesDetailView.swift b/Course/Course/Presentation/Handouts/HandoutsUpdatesDetailView.swift index ac4fbeddd..80b8ce43f 100644 --- a/Course/Course/Presentation/Handouts/HandoutsUpdatesDetailView.swift +++ b/Course/Course/Presentation/Handouts/HandoutsUpdatesDetailView.swift @@ -17,8 +17,8 @@ public struct HandoutsUpdatesDetailView: View { private var router: CourseRouter private let cssInjector: CSSInjector - public var handouts: String? - public var announcements: [CourseUpdate]? + private var handouts: String? + private var announcements: [CourseUpdate]? private let title: String public init( @@ -77,12 +77,9 @@ public struct HandoutsUpdatesDetailView: View { public var body: some View { ZStack(alignment: .top) { Theme.Colors.background - .ignoresSafeArea() - GeometryReader { reader in - + .ignoresSafeArea() // MARK: - Page Body VStack(alignment: .leading) { - // MARK: - Handouts if let handouts { let formattedHandouts = cssInjector.injectCSS( @@ -94,52 +91,114 @@ public struct HandoutsUpdatesDetailView: View { ) WebViewHtml(fixBrokenLinks(in: formattedHandouts)) - } else if let announcements { - + } else if let html = announcemetsHtml() { // MARK: - Announcements - ScrollView { - ForEach(Array(announcements.enumerated()), id: \.offset) { index, ann in - - Text(ann.date) - .font(Theme.Fonts.labelSmall) - let formattedAnnouncements = cssInjector.injectCSS( - colorScheme: colorScheme, - html: ann.content, - type: .discovery, - screenWidth: reader.size.width - ) - HStack { - HTMLFormattedText(formattedAnnouncements) - Spacer() - } - - .id(UUID()) - - if index != announcements.count - 1 { - Divider() - } - } - }.frame(height: reader.size.height - 60) - } - }.padding(.top, 8) - .padding(.horizontal, 32) - .frame( - maxHeight: .infinity, - alignment: .topLeading) - .onRightSwipeGesture { - router.back() + WebViewHtml(fixBrokenLinks(in: html)) } + } + .padding(.top, 8) + .padding(.horizontal, 32) + .frame( + maxHeight: .infinity, + alignment: .topLeading) + .onRightSwipeGesture { + router.back() + } Spacer(minLength: 84) - } } .navigationBarHidden(false) .navigationBarBackButtonHidden(false) .navigationTitle(title) - .onChange(of: colorSchemeNative) { newValue in + .onChange(of: colorSchemeNative) { _ in guard UIApplication.shared.applicationState == .active else { return } updateColorScheme() } } + + func fontsCSS(for fontFamily: String) -> String? { + if let path = Bundle(for: ThemeBundle.self).path(forResource: "fonts_file", ofType: "ttf"), + let data = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe) { + let fontCSS = """ + @font-face { + font-family: \(fontFamily); + src: url(data:font/truetype;charset=utf-8;base64,\(data.base64EncodedString())) format('truetype'); + font-weight: normal; + font-style: normal; + } + """ + return "" + } + return nil + } + + func titleHTML(fontFamily: String, fontSize: CGFloat, title: String) -> String { + """ +
+ \(title) +
+