Skip to content

Instantly share code, notes, and snippets.

@JunyuKuang
Created November 18, 2022 14:42
Show Gist options
  • Save JunyuKuang/a0ed4f324ea2b439b2127bac214578d2 to your computer and use it in GitHub Desktop.
Save JunyuKuang/a0ed4f324ea2b439b2127bac214578d2 to your computer and use it in GitHub Desktop.
Remove the unexpected HDR effect on iOS Share Sheet when Dark Mode is off.
//
// ShareSheetHDREffectRemover.swift
// MIT license
//
// Copyright © 2022 Jonny Kuang (theSpringApp@gmail.com)
//
#if !targetEnvironment(macCatalyst)
/// Remove the unexpected HDR effect on iOS Share Sheet when Dark Mode is off.
enum ShareSheetHDREffectRemover {
static let setup: Void = {
swizzleInstanceMethod(
class: UIVisualEffectView.self,
originalSelector: #selector(UIVisualEffectView.didMoveToWindow),
swizzledSelector: #selector(UIVisualEffectView.kjy_swizzle_removeShareSheetHDREffect_didMoveToWindow)
)
}()
}
private extension UIVisualEffectView {
static let groupCellClass = NSClassFromString("UIActivityActionGroupCell") as? UIView.Type
@objc func kjy_swizzle_removeShareSheetHDREffect_didMoveToWindow() {
kjy_swizzle_removeShareSheetHDREffect_didMoveToWindow()
guard let aClass = Self.groupCellClass,
window != nil,
kjy_findSuperview({ $0.isKind(of: aClass) }) != nil
else {
return
}
contentView.backgroundColor = UIColor {
$0.userInterfaceStyle == .light ? .clear : .black
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment