Update gradient

This commit is contained in:
Ali 2021-04-30 23:46:37 +04:00
parent 454bcc5ab0
commit b5039b573f
4 changed files with 52 additions and 6 deletions

View File

@ -2859,6 +2859,8 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
}
self.didScrollWithOffset?(-completeOffset, ContainedViewLayoutTransition.animated(duration: animationDuration, curve: animationCurve), nil)
}
} else {
self.didScrollWithOffset?(-completeOffset, .immediate, nil)
}
} else {
self.visibleSize = updateSizeAndInsets.size

View File

@ -23,7 +23,7 @@ private func generateGradientComponent(size: CGSize, color: UIColor) -> UIImage?
c?.setBlendMode(.normal)
var gradLocs: [CGFloat] = [0.0, 0.1, 1.0]
var gradLocs: [CGFloat] = [0.0, 0.05, 1.0]
let colorSpace = CGColorSpaceCreateDeviceRGB()
let radius = min(size.width / 2.0, size.height / 2.0)
@ -59,8 +59,10 @@ public final class GradientBackgroundNode: ASDisplayNode {
}
func updateFrame(frame: CGRect, transition: ContainedViewLayoutTransition) {
for imageView in stack {
transition.updateFrame(view: imageView, frame: frame)
let nextFrame = frame
for i in 0 ..< self.stack.count {
transition.updateFrame(view: self.stack[i], frame: nextFrame)
//nextFrame = nextFrame.insetBy(dx: nextFrame.width / 4.0, dy: nextFrame.height / 4.0)
}
}
}
@ -71,6 +73,8 @@ public final class GradientBackgroundNode: ASDisplayNode {
private var validLayout: CGSize?
private var testTimer: Timer?
override public init() {
self.dimView = UIView()
self.dimView.backgroundColor = UIColor(white: 1.0, alpha: 0.0)
@ -89,10 +93,10 @@ public final class GradientBackgroundNode: ASDisplayNode {
UIColor(rgb: 0xFBE37D)
]
let layerCount = 2
let layerCount = 1
for i in 0 ..< colors.count {
let image = generateGradientComponent(size: CGSize(width: 300.0, height: 300.0), color: colors[i].withMultiplied(hue: 1.0, saturation: 1.1, brightness: 1.0))!
let image = generateGradientComponent(size: CGSize(width: 300.0, height: 300.0), color: colors[i].withMultiplied(hue: 1.0, saturation: 1.0, brightness: 1.0))!
let pointImage = PointImage(image: image, count: layerCount)
@ -106,6 +110,36 @@ public final class GradientBackgroundNode: ASDisplayNode {
}
self.view.addSubview(self.dimView)
let defaultAlpha = self.pointImages[0].stack[0].alpha
var alphaPhase = 0
if #available(iOSApplicationExtension 10.0, iOS 10.0, *) {
let testTimer = Timer(timeInterval: 1.5, repeats: true, block: { [weak self] _ in
guard let strongSelf = self else {
return
}
return;
alphaPhase += 1
for image in strongSelf.pointImages {
for i in 0 ..< image.stack.count {
if alphaPhase % 2 == 0 {
//image.stack[i].alpha = defaultAlpha
image.stack[i].layer.compositingFilter = "screenBlendMode"
} else {
//image.stack[i].alpha = i == 0 ? 1.0 : 0.0
image.stack[i].layer.compositingFilter = nil
}
}
}
})
self.testTimer = testTimer
RunLoop.main.add(testTimer, forMode: .common)
}
}
deinit {
self.testTimer?.invalidate()
}
public func updateLayout(size: CGSize, transition: ContainedViewLayoutTransition) {
@ -147,7 +181,7 @@ public final class GradientBackgroundNode: ASDisplayNode {
}
let position = positions[i * 2]
let pointCenter = CGPoint(x: size.width * position.x, y: size.height * position.y)
let pointSize = CGSize(width: size.width * 1.8, height: size.height * 1.5)
let pointSize = CGSize(width: size.width * 1.9, height: size.height * 1.9)
self.pointImages[i].updateFrame(frame: CGRect(origin: CGPoint(x: pointCenter.x - pointSize.width / 2.0, y: pointCenter.y - pointSize.height / 2.0), size: pointSize), transition: transition)
}
}

View File

@ -319,6 +319,10 @@ public func customizeDefaultDayTheme(theme: PresentationTheme, editing: Bool, ti
public func makeDefaultDayPresentationTheme(extendingThemeReference: PresentationThemeReference? = nil, serviceBackgroundColor: UIColor?, day: Bool, preview: Bool) -> PresentationTheme {
var serviceBackgroundColor = serviceBackgroundColor ?? defaultServiceBackgroundColor
if !day {
serviceBackgroundColor = UIColor(white: 0.0, alpha: 0.2)
}
let intro = PresentationThemeIntro(
statusBarStyle: .black,

View File

@ -864,6 +864,9 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
containerNode.clipsToBounds = true
containerNode.cornerRadius = 15.0
containerNode.addSubnode(self.backgroundNode)
if let gradientBackgroundNode = self.gradientBackgroundNode {
containerNode.addSubnode(gradientBackgroundNode)
}
containerNode.addSubnode(self.historyNodeContainer)
if let restrictedNode = self.restrictedNode {
containerNode.addSubnode(restrictedNode)
@ -900,6 +903,9 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
self.containerNode = nil
containerNode.removeFromSupernode()
self.insertSubnode(self.backgroundNode, at: 0)
if let gradientBackgroundNode = self.gradientBackgroundNode {
self.insertSubnode(gradientBackgroundNode, at: 1)
}
self.insertSubnode(self.historyNodeContainer, aboveSubnode: self.backgroundNode)
if let restrictedNode = self.restrictedNode {
self.insertSubnode(restrictedNode, aboveSubnode: self.historyNodeContainer)