Swizzle WKWebView to fix scroll indicator in dark mode
This commit is contained in:
parent
c3d0174f23
commit
949f2bca01
|
@ -6,15 +6,15 @@
|
|||
//
|
||||
|
||||
import UIKit
|
||||
import CoreData
|
||||
import WebKit
|
||||
import OSLog
|
||||
|
||||
@main
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
swizzleWKWebView()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
|
||||
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
|
||||
}
|
||||
|
||||
private func swizzleWKWebView() {
|
||||
let selector = Selector(("_updateScrollViewBackground"))
|
||||
var originalIMP: IMP?
|
||||
let imp = imp_implementationWithBlock({ (self: WKWebView) in
|
||||
if let originalIMP = originalIMP {
|
||||
let original = unsafeBitCast(originalIMP, to: (@convention(c) (WKWebView, Selector) -> Void).self)
|
||||
original(self, selector)
|
||||
} else {
|
||||
os_log(.error, "Missing originalIMP for -[WKWebView _updateScrollViewBackground], did WebKit change?")
|
||||
}
|
||||
|
||||
self.scrollView.indicatorStyle = .default
|
||||
|
||||
} as (@convention(block) (WKWebView) -> Void))
|
||||
originalIMP = class_replaceMethod(WKWebView.self, selector, imp, "v@:")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue