[WIP] Reactions

This commit is contained in:
Ali
2022-08-16 22:19:22 +03:00
parent fb0824ed8b
commit f1e4e2dc7b
35 changed files with 1713 additions and 489 deletions

View File

@@ -39,7 +39,8 @@ final class ReactionContextBackgroundNode: ASDisplayNode {
private let largeCircleSize: CGFloat
private let smallCircleSize: CGFloat
private let backgroundNode: NavigationBackgroundNode
private let backgroundView: BlurredBackgroundView
private(set) var vibrancyEffectView: UIVisualEffectView?
private let maskLayer: SimpleLayer
private let backgroundClippingLayer: SimpleLayer
@@ -56,11 +57,11 @@ final class ReactionContextBackgroundNode: ASDisplayNode {
self.largeCircleSize = largeCircleSize
self.smallCircleSize = smallCircleSize
self.backgroundNode = NavigationBackgroundNode(color: .clear, enableBlur: true)
self.backgroundView = BlurredBackgroundView(color: .clear, enableBlur: true)
self.maskLayer = SimpleLayer()
self.backgroundClippingLayer = SimpleLayer()
self.backgroundClippingLayer.cornerRadius = 52.0
self.backgroundClippingLayer.cornerRadius = 47.0
self.backgroundClippingLayer.masksToBounds = true
self.backgroundMaskNode = maskNode
@@ -79,7 +80,6 @@ final class ReactionContextBackgroundNode: ASDisplayNode {
self.smallCircleLayer.cornerRadius = smallCircleSize / 2.0
if #available(iOS 13.0, *) {
// self.backgroundLayer.cornerCurve = .circular
self.largeCircleLayer.cornerCurve = .circular
self.smallCircleLayer.cornerCurve = .circular
}
@@ -94,7 +94,7 @@ final class ReactionContextBackgroundNode: ASDisplayNode {
self.largeCircleShadowLayer.opacity = 0.0
self.smallCircleShadowLayer.opacity = 0.0
self.addSubnode(self.backgroundNode)
self.view.addSubview(self.backgroundView)
self.maskLayer.addSublayer(self.smallCircleLayer)
self.maskLayer.addSublayer(self.largeCircleLayer)
@@ -102,7 +102,7 @@ final class ReactionContextBackgroundNode: ASDisplayNode {
self.backgroundClippingLayer.addSublayer(self.backgroundMaskNode.layer)
self.backgroundNode.layer.mask = self.maskLayer
self.backgroundView.layer.mask = self.maskLayer
}
func updateIsIntersectingContent(isIntersectingContent: Bool, transition: ContainedViewLayoutTransition) {
@@ -125,11 +125,28 @@ final class ReactionContextBackgroundNode: ASDisplayNode {
if self.theme !== theme {
self.theme = theme
self.backgroundNode.updateColor(color: theme.contextMenu.backgroundColor, transition: .immediate)
if theme.overallDarkAppearance {
if let vibrancyEffectView = self.vibrancyEffectView {
self.vibrancyEffectView = nil
vibrancyEffectView.removeFromSuperview()
}
} else {
if self.vibrancyEffectView == nil {
let style: UIBlurEffect.Style
style = .extraLight
let blurEffect = UIBlurEffect(style: style)
let vibrancyEffect = UIVibrancyEffect(blurEffect: blurEffect)
let vibrancyEffectView = UIVisualEffectView(effect: vibrancyEffect)
self.vibrancyEffectView = vibrancyEffectView
self.backgroundView.addSubview(vibrancyEffectView)
}
}
self.backgroundView.updateColor(color: theme.contextMenu.backgroundColor, transition: .immediate)
let shadowColor = UIColor(white: 0.0, alpha: 0.4)
if let image = generateBubbleShadowImage(shadow: shadowColor, diameter: 52.0, shadowBlur: shadowInset) {
if let image = generateBubbleShadowImage(shadow: shadowColor, diameter: 46.0, shadowBlur: shadowInset) {
ASDisplayNodeSetResizableContents(self.backgroundShadowLayer, image)
}
if let image = generateBubbleShadowImage(shadow: shadowColor, diameter: self.largeCircleSize, shadowBlur: shadowInset) {
@@ -148,7 +165,7 @@ final class ReactionContextBackgroundNode: ASDisplayNode {
backgroundMaskNodeFrame = backgroundMaskNodeFrame.offsetBy(dx: 0.0, dy: (updatedHeight - backgroundMaskNodeFrame.height) * 0.5)
}
transition.updateCornerRadius(layer: self.backgroundClippingLayer, cornerRadius: 52.0 / 2.0)
transition.updateCornerRadius(layer: self.backgroundClippingLayer, cornerRadius: 46.0 / 2.0)
let largeCircleFrame: CGRect
let smallCircleFrame: CGRect
@@ -171,8 +188,12 @@ final class ReactionContextBackgroundNode: ASDisplayNode {
transition.updateFrame(layer: self.largeCircleShadowLayer, frame: largeCircleFrame.insetBy(dx: -shadowInset, dy: -shadowInset), beginWithCurrentState: true)
transition.updateFrame(layer: self.smallCircleShadowLayer, frame: smallCircleFrame.insetBy(dx: -shadowInset, dy: -shadowInset), beginWithCurrentState: true)
transition.updateFrame(node: self.backgroundNode, frame: contentBounds, beginWithCurrentState: true)
self.backgroundNode.update(size: contentBounds.size, transition: transition)
transition.updateFrame(view: self.backgroundView, frame: contentBounds, beginWithCurrentState: true)
self.backgroundView.update(size: contentBounds.size, transition: transition)
if let vibrancyEffectView = self.vibrancyEffectView {
transition.updateFrame(view: vibrancyEffectView, frame: CGRect(origin: CGPoint(x: 10.0, y: 10.0), size: contentBounds.size))
}
}
func animateIn() {
@@ -199,7 +220,7 @@ final class ReactionContextBackgroundNode: ASDisplayNode {
let springDelay: Double = 0.05
let shadowInset: CGFloat = 15.0
let contentBounds = self.backgroundNode.frame
let contentBounds = self.backgroundView.frame
let visualSourceBackgroundFrame = sourceBackgroundFrame.offsetBy(dx: -contentBounds.minX, dy: -contentBounds.minY)
let sourceShadowFrame = visualSourceBackgroundFrame.insetBy(dx: -shadowInset, dy: -shadowInset)