diff --git a/submodules/ShimmerEffect/Sources/ShimmerEffect.swift b/submodules/ShimmerEffect/Sources/ShimmerEffect.swift index 37163a13ff..5b37a045b5 100644 --- a/submodules/ShimmerEffect/Sources/ShimmerEffect.swift +++ b/submodules/ShimmerEffect/Sources/ShimmerEffect.swift @@ -376,7 +376,7 @@ public final class ShimmerEffectNode: ASDisplayNode { self.effectNode.updateAbsoluteRect(rect, within: containerSize) } - public func update(backgroundColor: UIColor, foregroundColor: UIColor, shimmeringColor: UIColor, shapes: [Shape], horizontal: Bool = false, effectSize: CGFloat? = nil, globalTimeOffset: Bool = true, duration: Double? = nil, size: CGSize) { + public func update(backgroundColor: UIColor, foregroundColor: UIColor, shimmeringColor: UIColor, shapes: [Shape], horizontal: Bool = false, effectSize: CGFloat? = nil, globalTimeOffset: Bool = true, duration: Double? = nil, size: CGSize, mask: Bool = false) { if self.currentShapes == shapes, let currentBackgroundColor = self.currentBackgroundColor, currentBackgroundColor.isEqual(backgroundColor), let currentForegroundColor = self.currentForegroundColor, currentForegroundColor.isEqual(foregroundColor), let currentShimmeringColor = self.currentShimmeringColor, currentShimmeringColor.isEqual(shimmeringColor), horizontal == self.currentHorizontal, effectSize == self.currentEffectSize, self.currentSize == size { return } @@ -393,11 +393,17 @@ public final class ShimmerEffectNode: ASDisplayNode { self.effectNode.update(backgroundColor: foregroundColor, foregroundColor: shimmeringColor, horizontal: horizontal, effectSize: effectSize, globalTimeOffset: globalTimeOffset, duration: duration) self.foregroundNode.image = generateImage(size, rotatedContext: { size, context in - context.setFillColor(backgroundColor.cgColor) - context.setBlendMode(.copy) - context.fill(CGRect(origin: CGPoint(), size: size)) - - context.setFillColor(UIColor.clear.cgColor) + if !mask { + context.setFillColor(backgroundColor.cgColor) + context.setBlendMode(.copy) + context.fill(CGRect(origin: .zero, size: size)) + + context.setFillColor(UIColor.clear.cgColor) + } else { + context.clear(CGRect(origin: .zero, size: size)) + + context.setFillColor(UIColor.white.cgColor) + } for shape in shapes { switch shape { case let .circle(frame): @@ -425,6 +431,20 @@ public final class ShimmerEffectNode: ASDisplayNode { } }) + if mask { + if self.view.mask == nil { + self.foregroundNode.removeFromSupernode() + self.view.mask = self.foregroundNode.view + } + } else { + if self.view.mask != nil { + self.view.mask = nil + if self.foregroundNode.supernode == nil { + self.addSubnode(self.foregroundNode) + } + } + } + self.backgroundNode.frame = CGRect(origin: CGPoint(), size: size) self.foregroundNode.frame = CGRect(origin: CGPoint(), size: size) self.effectNode.frame = CGRect(origin: CGPoint(), size: size) diff --git a/submodules/WebUI/Sources/WebAppController.swift b/submodules/WebUI/Sources/WebAppController.swift index 3869af4f37..7c78ea5b63 100644 --- a/submodules/WebUI/Sources/WebAppController.swift +++ b/submodules/WebUI/Sources/WebAppController.swift @@ -260,9 +260,7 @@ public final class WebAppController: ViewController, AttachmentContainable { fileprivate var webView: WebAppWebView? private var placeholderIcon: (UIImage, Bool)? private var placeholderNode: ShimmerEffectNode? - - private var scheduledBackgroundColor: UIColor? - + fileprivate let loadingProgressPromise = Promise(nil) fileprivate var mainButtonState: AttachmentMainButtonState? { @@ -497,7 +495,7 @@ public final class WebAppController: ViewController, AttachmentContainable { } let theme = self.presentationData.theme - self.placeholderNode?.update(backgroundColor: self.backgroundColor ?? .clear, foregroundColor: theme.list.mediaPlaceholderColor, shimmeringColor: theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.4), shapes: shapes, horizontal: true, size: placeholderSize) + self.placeholderNode?.update(backgroundColor: .clear, foregroundColor: theme.list.mediaPlaceholderColor, shimmeringColor: theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.4), shapes: shapes, horizontal: true, size: placeholderSize, mask: true) return placeholderSize } @@ -531,10 +529,6 @@ public final class WebAppController: ViewController, AttachmentContainable { let transition = ContainedViewLayoutTransition.animated(duration: 0.2, curve: .linear) transition.updateAlpha(layer: webView.layer, alpha: 1.0) - if let color = self.scheduledBackgroundColor { - self.scheduledBackgroundColor = nil - transition.updateBackgroundColor(node: self.backgroundNode, color: color) - } self.updateHeaderBackgroundColor(transition: transition) if let placeholderNode = self.placeholderNode { @@ -876,12 +870,8 @@ public final class WebAppController: ViewController, AttachmentContainable { } case "web_app_set_background_color": if let json = json, let colorValue = json["color"] as? String, let color = UIColor(hexString: colorValue) { - if self.placeholderNode != nil { - self.scheduledBackgroundColor = color - } else { - let transition = ContainedViewLayoutTransition.animated(duration: 0.2, curve: .linear) - transition.updateBackgroundColor(node: self.backgroundNode, color: color) - } + let transition = ContainedViewLayoutTransition.animated(duration: 0.2, curve: .linear) + transition.updateBackgroundColor(node: self.backgroundNode, color: color) } case "web_app_set_header_color": if let json = json { @@ -892,9 +882,7 @@ public final class WebAppController: ViewController, AttachmentContainable { self.headerColor = color self.headerColorKey = nil } - if self.placeholderNode == nil { - self.updateHeaderBackgroundColor(transition: .animated(duration: 0.2, curve: .linear)) - } + self.updateHeaderBackgroundColor(transition: .animated(duration: 0.2, curve: .linear)) } case "web_app_open_popup": if let json = json, let message = json["message"] as? String, let buttons = json["buttons"] as? [Any] {