From 269d0535bd454e665b8c25d342a3d07f582dea06 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 10 Oct 2023 20:28:26 -0500 Subject: [PATCH] Fix for scroll indicators on iOS when using Dark Mode --- iOS/Article/WebViewController.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index 52cf28037..df4b46549 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -82,6 +82,28 @@ class WebViewController: UIViewController { } + override func viewWillAppear(_ animated: Bool) { + updateScrollIndicatorStyle() + } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + updateScrollIndicatorStyle() + } + + + // See https://shadowfacts.net/2022/wkwebview-scroll-indicators-again/ for why this is necessary. + private func updateScrollIndicatorStyle() { + guard #available(iOS 15.4, *) else { + return + } + + if traitCollection.userInterfaceStyle == .dark { + webView?.scrollView.indicatorStyle = .white + } else { + webView?.scrollView.indicatorStyle = .black + } + } + // MARK: Notifications @objc func webFeedIconDidBecomeAvailable(_ note: Notification) {