From a1e077035cab635df61908c3acef7d9e906197d9 Mon Sep 17 00:00:00 2001 From: hilmyveradin Date: Thu, 28 Mar 2024 18:59:27 +0700 Subject: [PATCH] Fix dark mode flashing button and modify content body code --- .../TransitAlertDetailViewController.swift | 2 ++ OBAKit/Settings/CreditsViewController.swift | 2 ++ OBAKit/WebView/DocumentWebView.swift | 29 ++++++++++--------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/OBAKit/Alerts/TransitAlertDetailViewController.swift b/OBAKit/Alerts/TransitAlertDetailViewController.swift index d4d0ad389..75839c02b 100644 --- a/OBAKit/Alerts/TransitAlertDetailViewController.swift +++ b/OBAKit/Alerts/TransitAlertDetailViewController.swift @@ -67,6 +67,8 @@ class TransitAlertDetailViewController: UIViewController, WKScriptMessageHandler let view = DocumentWebView(frame: view.bounds, configuration: configuration) view.autoresizingMask = [.flexibleWidth, .flexibleHeight] + view.isOpaque = false + view.backgroundColor = ThemeColors.shared.systemBackground if #available(iOS 16.4, *) { view.isInspectable = true diff --git a/OBAKit/Settings/CreditsViewController.swift b/OBAKit/Settings/CreditsViewController.swift index 8aa615df0..adb93033a 100644 --- a/OBAKit/Settings/CreditsViewController.swift +++ b/OBAKit/Settings/CreditsViewController.swift @@ -84,6 +84,8 @@ class CreditViewerController: UIViewController { override func viewDidLoad() { webView.frame = view.bounds webView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + webView.isOpaque = false + webView.backgroundColor = ThemeColors.shared.systemBackground view.addSubview(webView) let mungedCredits = "\(licenseText.replacingOccurrences(of: "\n", with: "
"))
" diff --git a/OBAKit/WebView/DocumentWebView.swift b/OBAKit/WebView/DocumentWebView.swift index 438bd0a83..c255874c8 100644 --- a/OBAKit/WebView/DocumentWebView.swift +++ b/OBAKit/WebView/DocumentWebView.swift @@ -25,20 +25,23 @@ class DocumentWebView: WKWebView { /// - Parameter htmlFragment: The content to render in the web view. /// - Parameter actionButtonTitle: The title of the optional button shown at the bottom of the web view. func setPageContent(_ htmlFragment: String, actionButtonTitle: String? = nil) { - var content = pageBody.replacingOccurrences(of: "{{{oba_page_content}}}", with: htmlFragment) - content = content.replacingOccurrences(of: "{{{accent_color}}}", with: accentHexColor) - content = content.replacingOccurrences(of: "{{{accent_foreground_color}}}", with: accentForegroundColor) - - if let actionButtonTitle { - let buttonText = """ -
- -
- """ - content = content.replacingOccurrences(of: "{{{oba_page_actions}}}", with: buttonText) + var content = pageBody + .replacingOccurrences(of: "{{{oba_page_content}}}", with: htmlFragment) + .replacingOccurrences(of: "{{{accent_color}}}", with: accentHexColor) + .replacingOccurrences(of: "{{{accent_foreground_color}}}", with: accentForegroundColor) + + // Construct button HTML if actionButtonTitle is present and not empty + let buttonText: String? = actionButtonTitle.flatMap { title in + title.isEmpty ? nil : """ +
+ +
+ """ } + // Use coalescing operator to remove action button placeholder if buttonText is nil + content = content.replacingOccurrences(of: "{{{oba_page_actions}}}", with: buttonText ?? "") loadHTMLString(content, baseURL: nil) }