Add light context menu theme

This commit is contained in:
Ali
2023-10-24 18:39:41 +04:00
parent d7546f6751
commit 5452f275b4
15 changed files with 124 additions and 91 deletions

View File

@@ -17,22 +17,32 @@ private final class ContextMenuContainerMaskView: UIView {
public final class ContextMenuContainerNode: ASDisplayNode {
private var cachedMaskParams: CachedMaskParams?
private let maskView = ContextMenuContainerMaskView()
public let containerNode: ASDisplayNode
public var relativeArrowPosition: (CGFloat, Bool)?
private var effectView: UIVisualEffectView?
public init(blurred: Bool) {
public init(isBlurred: Bool, isDark: Bool) {
self.containerNode = ASDisplayNode()
super.init()
if blurred {
let effectView = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
self.view.addSubview(effectView)
if isBlurred {
let effectView = UIVisualEffectView(effect: UIBlurEffect(style: isDark ? .dark : .light))
self.containerNode.view.addSubview(effectView)
self.effectView = effectView
} else {
self.backgroundColor = UIColor(rgb: 0x8c8e8e)
self.containerNode.backgroundColor = isDark ? UIColor(rgb: 0x8c8e8e) : UIColor(rgb: 0xF8F8F6)
}
self.view.mask = self.maskView
self.layer.shadowColor = UIColor.black.cgColor
self.layer.shadowRadius = 10.0
self.layer.shadowOpacity = 0.2
self.layer.shadowOffset = CGSize(width: 0.0, height: 5.0)
self.containerNode.view.mask = self.maskView
self.addSubnode(self.containerNode)
}
override public func didLoad() {
@@ -48,6 +58,8 @@ public final class ContextMenuContainerNode: ASDisplayNode {
}
public func updateLayout(transition: ContainedViewLayoutTransition) {
transition.updateFrame(node: self.containerNode, frame: self.bounds)
self.effectView?.frame = self.bounds
let maskParams = CachedMaskParams(size: self.bounds.size, relativeArrowPosition: self.relativeArrowPosition?.0 ?? self.bounds.size.width / 2.0, arrowOnBottom: self.relativeArrowPosition?.1 ?? true)
@@ -87,6 +99,13 @@ public final class ContextMenuContainerNode: ASDisplayNode {
}
layer.path = path.cgPath
}
if case let .animated(duration, curve) = transition, let previousPath = self.layer.shadowPath {
self.layer.shadowPath = path.cgPath
self.layer.animate(from: previousPath, to: path.cgPath, keyPath: "shadowPath", timingFunction: curve.timingFunction, duration: duration)
} else {
self.layer.shadowPath = path.cgPath
}
}
}
}