mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix bubble backgrounds
This commit is contained in:
parent
83feaa6cf5
commit
4b5bde5a24
@ -653,10 +653,21 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
|
||||
private let contentNode: ASDisplayNode
|
||||
|
||||
private var blurredBackgroundContents: UIImage?
|
||||
private var blurredBackgroundPortalSourceView: PortalSourceView?
|
||||
private var blurredBackgroundDimmedNode: GradientBackgroundNode.CloneNode?
|
||||
private var blurredBackgroundDimmedOverlayView: UIView?
|
||||
private var blurredBackgroundContentView: UIImageView?
|
||||
|
||||
private var freeBackgroundPortalSourceView: PortalSourceView?
|
||||
private var freeBackgroundNode: WallpaperBackgroundNodeImpl.BubbleBackgroundNodeImpl? {
|
||||
didSet {
|
||||
if self.freeBackgroundNode !== oldValue {
|
||||
if let oldValue {
|
||||
oldValue.view.removeFromSuperview()
|
||||
}
|
||||
if let freeBackgroundNode = self.freeBackgroundNode, let freeBackgroundPortalSourceView = self.freeBackgroundPortalSourceView {
|
||||
freeBackgroundPortalSourceView.addSubview(freeBackgroundNode.view)
|
||||
freeBackgroundNode.frame = CGRect(origin: CGPoint(), size: freeBackgroundPortalSourceView.bounds.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var incomingBackgroundPortalSourceView: PortalSourceView?
|
||||
private var incomingBackgroundNode: WallpaperBackgroundNodeImpl.BubbleBackgroundNodeImpl? {
|
||||
@ -817,14 +828,10 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
|
||||
super.init()
|
||||
|
||||
if #available(iOS 12.0, *) {
|
||||
let blurredBackgroundPortalSourceView = PortalSourceView()
|
||||
self.blurredBackgroundPortalSourceView = blurredBackgroundPortalSourceView
|
||||
blurredBackgroundPortalSourceView.alpha = 0.0
|
||||
self.view.addSubview(blurredBackgroundPortalSourceView)
|
||||
|
||||
let blurredBackgroundContentView = UIImageView()
|
||||
self.blurredBackgroundContentView = blurredBackgroundContentView
|
||||
blurredBackgroundPortalSourceView.addSubview(blurredBackgroundContentView)
|
||||
let freeBackgroundPortalSourceView = PortalSourceView()
|
||||
self.freeBackgroundPortalSourceView = freeBackgroundPortalSourceView
|
||||
freeBackgroundPortalSourceView.alpha = 0.0
|
||||
self.view.addSubview(freeBackgroundPortalSourceView)
|
||||
|
||||
let incomingBackgroundPortalSourceView = PortalSourceView()
|
||||
self.incomingBackgroundPortalSourceView = incomingBackgroundPortalSourceView
|
||||
@ -885,28 +892,11 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
|
||||
scheduleLoopingEvent = true
|
||||
}
|
||||
}
|
||||
if let gradientBackgroundNode = self.gradientBackgroundNode {
|
||||
if self.blurredBackgroundDimmedNode == nil {
|
||||
let blurredBackgroundDimmedNode = GradientBackgroundNode.CloneNode(parentNode: gradientBackgroundNode)
|
||||
self.blurredBackgroundDimmedNode = blurredBackgroundDimmedNode
|
||||
self.blurredBackgroundPortalSourceView?.addSubnode(blurredBackgroundDimmedNode)
|
||||
}
|
||||
if self.blurredBackgroundDimmedOverlayView == nil {
|
||||
let blurredBackgroundDimmedOverlayView = UIView()
|
||||
self.blurredBackgroundDimmedOverlayView = blurredBackgroundDimmedOverlayView
|
||||
self.blurredBackgroundPortalSourceView?.addSubview(blurredBackgroundDimmedOverlayView)
|
||||
}
|
||||
}
|
||||
self.gradientBackgroundNode?.updateColors(colors: mappedColors)
|
||||
|
||||
if let bubbleTheme = self.bubbleTheme {
|
||||
self.blurredBackgroundDimmedOverlayView?.backgroundColor = selectDateFillStaticColor(theme: bubbleTheme, wallpaper: wallpaper)
|
||||
}
|
||||
|
||||
self.contentNode.backgroundColor = nil
|
||||
self.contentNode.contents = nil
|
||||
self.blurredBackgroundContents = nil
|
||||
self.blurredBackgroundContentView?.image = self.blurredBackgroundContents
|
||||
self.motionEnabled = false
|
||||
self.wallpaperDisposable.set(nil)
|
||||
} else {
|
||||
@ -916,14 +906,6 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
|
||||
gradientBackgroundNode.setPatternOverlay(layer: nil)
|
||||
self.layer.insertSublayer(self.patternImageLayer, above: self.contentNode.layer)
|
||||
}
|
||||
if let blurredBackgroundDimmedNode = self.blurredBackgroundDimmedNode {
|
||||
self.blurredBackgroundDimmedNode = nil
|
||||
blurredBackgroundDimmedNode.removeFromSupernode()
|
||||
}
|
||||
if let blurredBackgroundDimmedOverlayView = self.blurredBackgroundDimmedOverlayView {
|
||||
self.blurredBackgroundDimmedOverlayView = nil
|
||||
blurredBackgroundDimmedOverlayView.removeFromSuperview()
|
||||
}
|
||||
|
||||
self.motionEnabled = wallpaper.settings?.motion ?? false
|
||||
|
||||
@ -944,20 +926,17 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
|
||||
})
|
||||
self.contentNode.contents = image?.cgImage
|
||||
self.blurredBackgroundContents = image
|
||||
self.blurredBackgroundContentView?.image = self.blurredBackgroundContents
|
||||
self.wallpaperDisposable.set(nil)
|
||||
} else if gradientColors.count >= 1 {
|
||||
self.contentNode.backgroundColor = UIColor(rgb: gradientColors[0])
|
||||
self.contentNode.contents = nil
|
||||
self.blurredBackgroundContents = nil
|
||||
self.blurredBackgroundContentView?.image = self.blurredBackgroundContents
|
||||
self.wallpaperDisposable.set(nil)
|
||||
} else {
|
||||
self.contentNode.backgroundColor = .white
|
||||
if let image = chatControllerBackgroundImage(theme: nil, wallpaper: wallpaper, mediaBox: self.context.sharedContext.accountManager.mediaBox, knockoutMode: false) {
|
||||
self.contentNode.contents = image.cgImage
|
||||
self.blurredBackgroundContents = generateBlurredContents(image: image)
|
||||
self.blurredBackgroundContentView?.image = self.blurredBackgroundContents
|
||||
self.wallpaperDisposable.set(nil)
|
||||
Queue.mainQueue().justDispatch {
|
||||
self._isReady.set(true)
|
||||
@ -965,7 +944,6 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
|
||||
} else if let image = chatControllerBackgroundImage(theme: nil, wallpaper: wallpaper, mediaBox: self.context.account.postbox.mediaBox, knockoutMode: false) {
|
||||
self.contentNode.contents = image.cgImage
|
||||
self.blurredBackgroundContents = generateBlurredContents(image: image)
|
||||
self.blurredBackgroundContentView?.image = self.blurredBackgroundContents
|
||||
self.wallpaperDisposable.set(nil)
|
||||
Queue.mainQueue().justDispatch {
|
||||
self._isReady.set(true)
|
||||
@ -982,7 +960,6 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
|
||||
} else {
|
||||
strongSelf.blurredBackgroundContents = nil
|
||||
}
|
||||
strongSelf.blurredBackgroundContentView?.image = strongSelf.blurredBackgroundContents
|
||||
strongSelf._isReady.set(true)
|
||||
}))
|
||||
}
|
||||
@ -990,6 +967,12 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
|
||||
}
|
||||
}
|
||||
|
||||
if self.hasBubbleBackground(for: .free) {
|
||||
self.freeBackgroundNode = WallpaperBackgroundNodeImpl.BubbleBackgroundNodeImpl(backgroundNode: self, bubbleType: .free)
|
||||
} else {
|
||||
self.freeBackgroundNode = nil
|
||||
}
|
||||
|
||||
if self.hasBubbleBackground(for: .incoming) {
|
||||
self.incomingBackgroundNode = WallpaperBackgroundNodeImpl.BubbleBackgroundNodeImpl(backgroundNode: self, bubbleType: .incoming)
|
||||
} else {
|
||||
@ -1243,17 +1226,8 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
|
||||
let isFirstLayout = self.validLayout == nil
|
||||
self.validLayout = (size, displayMode)
|
||||
|
||||
if let blurredBackgroundPortalSourceView = self.blurredBackgroundPortalSourceView {
|
||||
transition.updateFrame(view: blurredBackgroundPortalSourceView, frame: CGRect(origin: CGPoint(), size: size))
|
||||
}
|
||||
if let blurredBackgroundContentView = self.blurredBackgroundContentView {
|
||||
transition.updateFrame(view: blurredBackgroundContentView, frame: CGRect(origin: CGPoint(), size: size))
|
||||
}
|
||||
if let blurredBackgroundDimmedNode = self.blurredBackgroundDimmedNode {
|
||||
transition.updateFrame(view: blurredBackgroundDimmedNode.view, frame: CGRect(origin: CGPoint(), size: size))
|
||||
}
|
||||
if let blurredBackgroundDimmedOverlayView = self.blurredBackgroundDimmedOverlayView {
|
||||
transition.updateFrame(view: blurredBackgroundDimmedOverlayView, frame: CGRect(origin: CGPoint(), size: size))
|
||||
if let freeBackgroundPortalSourceView = self.freeBackgroundPortalSourceView {
|
||||
transition.updateFrame(view: freeBackgroundPortalSourceView, frame: CGRect(origin: CGPoint(), size: size))
|
||||
}
|
||||
|
||||
if let incomingBackgroundPortalSourceView = self.incomingBackgroundPortalSourceView {
|
||||
@ -1277,6 +1251,11 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
|
||||
outgoingBubbleGradientBackgroundNode.updateLayout(size: size, transition: transition, extendAnimation: false, backwards: false, completion: {})
|
||||
}
|
||||
|
||||
if let freeBackgroundNode = self.freeBackgroundNode {
|
||||
transition.updateFrame(node: freeBackgroundNode, frame: CGRect(origin: CGPoint(), size: size))
|
||||
freeBackgroundNode.update(rect: CGRect(origin: CGPoint(), size: size), within: size, transition: transition)
|
||||
}
|
||||
|
||||
if let incomingBackgroundNode = self.incomingBackgroundNode {
|
||||
transition.updateFrame(node: incomingBackgroundNode, frame: CGRect(origin: CGPoint(), size: size))
|
||||
incomingBackgroundNode.update(rect: CGRect(origin: CGPoint(), size: size), within: size, transition: transition)
|
||||
@ -1348,8 +1327,10 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
|
||||
self.outgoingBubbleGradientBackgroundNode = nil
|
||||
}
|
||||
|
||||
if let wallpaper = self.wallpaper {
|
||||
self.blurredBackgroundDimmedOverlayView?.backgroundColor = selectDateFillStaticColor(theme: bubbleTheme, wallpaper: wallpaper)
|
||||
if self.hasBubbleBackground(for: .free) {
|
||||
self.freeBackgroundNode = WallpaperBackgroundNodeImpl.BubbleBackgroundNodeImpl(backgroundNode: self, bubbleType: .free)
|
||||
} else {
|
||||
self.freeBackgroundNode = nil
|
||||
}
|
||||
|
||||
if self.hasBubbleBackground(for: .incoming) {
|
||||
@ -1428,7 +1409,7 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
|
||||
var sourceView: PortalSourceView?
|
||||
switch type {
|
||||
case .free:
|
||||
sourceView = self.blurredBackgroundPortalSourceView
|
||||
sourceView = self.freeBackgroundPortalSourceView
|
||||
case .incoming:
|
||||
sourceView = self.incomingBackgroundPortalSourceView
|
||||
case .outgoing:
|
||||
@ -1451,14 +1432,12 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
|
||||
}
|
||||
|
||||
func makeFreeBackground() -> PortalView? {
|
||||
guard let blurredBackgroundPortalSourceView = self.blurredBackgroundPortalSourceView else {
|
||||
if let sourceView = self.freeBackgroundPortalSourceView, let portalView = PortalView(matchPosition: true) {
|
||||
sourceView.addPortal(view: portalView)
|
||||
return portalView
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
guard let portalView = PortalView(matchPosition: true) else {
|
||||
return nil
|
||||
}
|
||||
blurredBackgroundPortalSourceView.addPortal(view: portalView)
|
||||
return portalView
|
||||
}
|
||||
|
||||
func hasExtraBubbleBackground() -> Bool {
|
||||
|
Loading…
x
Reference in New Issue
Block a user