-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Swizzle shadow and disable animations
- Loading branch information
1 parent
c578372
commit 163762b
Showing
5 changed files
with
63 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// Copyright © 2023 Stream.io Inc. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import XCTest | ||
|
||
extension CALayer { | ||
static func swizzleShadow() { | ||
swizzle(original: #selector(getter: shadowOpacity), modified: #selector(_swizzled_shadowOpacity)) | ||
swizzle(original: #selector(getter: shadowRadius), modified: #selector(_swizzled_shadowRadius)) | ||
swizzle(original: #selector(getter: shadowColor), modified: #selector(_swizzled_shadowColor)) | ||
swizzle(original: #selector(getter: shadowOffset), modified: #selector(_swizzled_shadowOffset)) | ||
swizzle(original: #selector(getter: shadowPath), modified: #selector(_swizzled_shadowPath)) | ||
} | ||
|
||
static func reverSwizzleShadow() { | ||
swizzle(original: #selector(_swizzled_shadowOpacity), modified: #selector(getter: shadowOpacity)) | ||
swizzle(original: #selector(_swizzled_shadowRadius), modified: #selector(getter: shadowRadius)) | ||
swizzle(original: #selector(_swizzled_shadowColor), modified: #selector(getter: shadowColor)) | ||
swizzle(original: #selector(_swizzled_shadowOffset), modified: #selector(getter: shadowOffset)) | ||
swizzle(original: #selector(_swizzled_shadowPath), modified: #selector(getter: shadowPath)) | ||
} | ||
|
||
private static func swizzle(original: Selector, modified: Selector) { | ||
let originalMethod = class_getInstanceMethod(self, original)! | ||
let swizzledMethod = class_getInstanceMethod(self, modified)! | ||
method_exchangeImplementations(originalMethod, swizzledMethod) | ||
} | ||
|
||
@objc func _swizzled_shadowOpacity() -> Float { .zero } | ||
@objc func _swizzled_shadowRadius() -> CGFloat { .zero } | ||
@objc func _swizzled_shadowColor() -> CGColor? { nil } | ||
@objc func _swizzled_shadowOffset() -> CGSize { .zero } | ||
@objc func _swizzled_shadowPath() -> CGPath? { nil } | ||
} |