Theme updates

This commit is contained in:
Ali 2021-05-29 01:10:45 +04:00
parent b11b306c30
commit 154c74a607
20 changed files with 115 additions and 61 deletions

View File

@ -38,7 +38,7 @@ open class GalleryControllerNode: ASDisplayNode, UIScrollViewDelegate, UIGesture
}
}
public init(controllerInteraction: GalleryControllerInteraction, pageGap: CGFloat = 20.0) {
public init(controllerInteraction: GalleryControllerInteraction, pageGap: CGFloat = 20.0, disableTapNavigation: Bool = false) {
self.backgroundNode = ASDisplayNode()
self.backgroundNode.backgroundColor = UIColor.black
self.scrollView = UIScrollView()
@ -48,7 +48,7 @@ open class GalleryControllerNode: ASDisplayNode, UIScrollViewDelegate, UIGesture
self.scrollView.contentInsetAdjustmentBehavior = .never
}
self.pager = GalleryPagerNode(pageGap: pageGap)
self.pager = GalleryPagerNode(pageGap: pageGap, disableTapNavigation: disableTapNavigation)
self.footerNode = GalleryFooterNode(controllerInteraction: controllerInteraction)
super.init()

View File

@ -78,6 +78,7 @@ public struct GalleryPagerTransaction {
public final class GalleryPagerNode: ASDisplayNode, UIScrollViewDelegate, UIGestureRecognizerDelegate {
private let pageGap: CGFloat
private let disableTapNavigation: Bool
private let scrollView: UIScrollView
@ -111,8 +112,10 @@ public final class GalleryPagerNode: ASDisplayNode, UIScrollViewDelegate, UIGest
public var completeCustomDismiss: () -> Void = { }
public var baseNavigationController: () -> NavigationController? = { return nil }
public init(pageGap: CGFloat) {
public init(pageGap: CGFloat, disableTapNavigation: Bool) {
self.pageGap = pageGap
self.disableTapNavigation = disableTapNavigation
self.scrollView = UIScrollView()
if #available(iOSApplicationExtension 11.0, iOS 11.0, *) {
self.scrollView.contentInsetAdjustmentBehavior = .never
@ -434,6 +437,9 @@ public final class GalleryPagerNode: ASDisplayNode, UIScrollViewDelegate, UIGest
}
private func canGoToPreviousItem() -> Bool {
if self.disableTapNavigation {
return false
}
if let index = self.centralItemIndex, index > 0 {
return true
} else {
@ -442,6 +448,9 @@ public final class GalleryPagerNode: ASDisplayNode, UIScrollViewDelegate, UIGest
}
private func canGoToNextItem() -> Bool {
if self.disableTapNavigation {
return false
}
if let index = self.centralItemIndex, index < self.items.count - 1 {
return true
} else {

View File

@ -3,6 +3,6 @@ import UIKit
import Display
import AsyncDisplayKit
public func createGradientBackgroundNode() -> GradientBackgroundNode {
return GradientBackgroundNode()
public func createGradientBackgroundNode(useSharedAnimationPhase: Bool = false) -> GradientBackgroundNode {
return GradientBackgroundNode(useSharedAnimationPhase: useSharedAnimationPhase)
}

View File

@ -180,14 +180,22 @@ public final class GradientBackgroundNode: ASDisplayNode {
private let cloneNodes = SparseBag<Weak<CloneNode>>()
override public init() {
private let useSharedAnimationPhase: Bool
static var sharedPhase: Int = 0
public init(useSharedAnimationPhase: Bool = false) {
self.useSharedAnimationPhase = useSharedAnimationPhase
self.contentView = UIImageView()
super.init()
self.view.addSubview(self.contentView)
self.phase = 0
if useSharedAnimationPhase {
self.phase = GradientBackgroundNode.sharedPhase
} else {
self.phase = 0
}
}
deinit {
@ -280,6 +288,9 @@ public final class GradientBackgroundNode: ASDisplayNode {
} else {
self.phase = self.phase - 1
}
if self.useSharedAnimationPhase {
GradientBackgroundNode.sharedPhase = self.phase
}
if let size = self.validLayout {
self.updateLayout(size: size, transition: transition)
}

View File

@ -147,34 +147,31 @@ public final class CachedPatternWallpaperMaskRepresentation: CachedMediaResource
public final class CachedPatternWallpaperRepresentation: CachedMediaResourceRepresentation {
public let keepDuration: CachedMediaRepresentationKeepDuration = .general
public let color: UInt32
public let bottomColor: UInt32?
public let colors: [UInt32]
public let intensity: Int32
public let rotation: Int32?
public var uniqueId: String {
var id: String
if let bottomColor = self.bottomColor {
id = "pattern-wallpaper-\(self.color)-\(bottomColor)-\(self.intensity)"
} else {
id = "pattern-wallpaper-\(self.color)-\(self.intensity)"
var id: String = "pattern-wallpaper"
for color in self.colors {
id.append("-\(color)")
}
id.append("-\(self.intensity)")
if let rotation = self.rotation, rotation != 0 {
id += "-\(rotation)deg"
}
return id
}
public init(color: UInt32, bottomColor: UInt32?, intensity: Int32, rotation: Int32?) {
self.color = color
self.bottomColor = bottomColor
public init(colors: [UInt32], intensity: Int32, rotation: Int32?) {
self.colors = colors
self.intensity = intensity
self.rotation = rotation
}
public func isEqual(to: CachedMediaResourceRepresentation) -> Bool {
if let to = to as? CachedPatternWallpaperRepresentation {
return self.color == to.color && self.bottomColor == to.bottomColor && self.intensity == intensity && self.rotation == to.rotation
return self.colors == to.colors && self.intensity == intensity && self.rotation == to.rotation
} else {
return false
}

View File

@ -514,7 +514,7 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
let prepare: Signal<CreateThemeResult, CreateThemeError>
if let resolvedWallpaper = resolvedWallpaper, case let .file(file) = resolvedWallpaper, resolvedWallpaper.isPattern {
let resource = file.file.resource
let representation = CachedPatternWallpaperRepresentation(color: file.settings.colors.count >= 1 ? file.settings.colors[0] : 0xd6e2ee, bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: file.settings.intensity ?? 50, rotation: file.settings.rotation)
let representation = CachedPatternWallpaperRepresentation(colors: file.settings.colors.count >= 1 ? file.settings.colors : [0xd6e2ee], intensity: file.settings.intensity ?? 50, rotation: file.settings.rotation)
var data: Data?
if let path = context.account.postbox.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {

View File

@ -173,7 +173,7 @@ final class ThemeAccentColorController: ViewController {
let prepareWallpaper: Signal<CreateThemeResult, CreateThemeError>
if let patternWallpaper = state.patternWallpaper, case let .file(file) = patternWallpaper, !state.backgroundColors.isEmpty {
let resource = file.file.resource
let representation = CachedPatternWallpaperRepresentation(color: state.backgroundColors.count >= 1 ? state.backgroundColors[0] : 0, bottomColor: state.backgroundColors.count >= 2 ? state.backgroundColors[1] : 0, intensity: state.patternIntensity, rotation: state.rotation)
let representation = CachedPatternWallpaperRepresentation(colors: state.backgroundColors.count >= 1 ? state.backgroundColors : [0], intensity: state.patternIntensity, rotation: state.rotation)
var data: Data?
if let path = strongSelf.context.account.postbox.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {
@ -455,12 +455,14 @@ final class ThemeAccentColorController: ViewController {
let themeSpecificAccentColor = settings.themeSpecificAccentColors[themeReference.index]
accentColor = themeSpecificAccentColor?.color ?? defaultDayAccentColor
var referenceTheme: PresentationTheme?
if let accentColor = themeSpecificAccentColor, let customWallpaper = settings.themeSpecificChatWallpapers[coloredThemeIndex(reference: themeReference, accentColor: accentColor)] {
wallpaper = customWallpaper
} else if let customWallpaper = settings.themeSpecificChatWallpapers[themeReference.index] {
wallpaper = customWallpaper
} else {
let theme = makePresentationTheme(mediaBox: strongSelf.context.sharedContext.accountManager.mediaBox, themeReference: themeReference, accentColor: themeSpecificAccentColor?.color, wallpaper: themeSpecificAccentColor?.wallpaper) ?? defaultPresentationTheme
referenceTheme = theme
wallpaper = theme.chat.defaultWallpaper
}
@ -485,6 +487,8 @@ final class ThemeAccentColorController: ViewController {
} else {
if let themeReference = strongSelf.mode.themeReference, themeReference == .builtin(.dayClassic), settings.themeSpecificAccentColors[themeReference.index] == nil {
messageColors = (UIColor(rgb: 0xe1ffc7), nil)
} else if let referenceTheme = referenceTheme {
messageColors = (referenceTheme.chat.message.outgoing.bubble.withoutWallpaper.fill, referenceTheme.chat.message.outgoing.bubble.withoutWallpaper.gradientFill)
} else {
messageColors = nil
}

View File

@ -1240,7 +1240,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
|> mapToSignal { cachedWallpaper in
if let wallpaper = cachedWallpaper?.wallpaper, case let .file(file) = wallpaper {
let resource = file.file.resource
let representation = CachedPatternWallpaperRepresentation(color: file.settings.colors.count >= 1 ? file.settings.colors[0] : 0xd6e2ee, bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : 0xd6e2ee, intensity: file.settings.intensity ?? 50, rotation: file.settings.rotation)
let representation = CachedPatternWallpaperRepresentation(colors: file.settings.colors.count >= 1 ? file.settings.colors : [0xd6e2ee], intensity: file.settings.intensity ?? 50, rotation: file.settings.rotation)
let _ = fetchedMediaResource(mediaBox: context.account.postbox.mediaBox, reference: .wallpaper(wallpaper: .slug(file.slug), resource: file.file.resource)).start()

View File

@ -360,7 +360,7 @@ public class WallpaperGalleryController: ViewController {
}, replaceRootController: { controller, ready in
}, editMedia: { _ in
})
self.displayNode = WallpaperGalleryControllerNode(controllerInteraction: controllerInteraction, pageGap: 0.0)
self.displayNode = WallpaperGalleryControllerNode(controllerInteraction: controllerInteraction, pageGap: 0.0, disableTapNavigation: true)
self.displayNodeDidLoad()
(self.displayNode as? WallpaperGalleryControllerNode)?.nativeStatusBar = self.statusBar
@ -498,7 +498,7 @@ public class WallpaperGalleryController: ViewController {
}
} else if case let .file(file) = wallpaper, let resource = resource {
if wallpaper.isPattern, !file.settings.colors.isEmpty, let intensity = file.settings.intensity {
let representation = CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation)
let representation = CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation)
var data: Data?
if let path = strongSelf.context.account.postbox.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {
@ -671,14 +671,23 @@ public class WallpaperGalleryController: ViewController {
}
if let entry = self.currentEntry(), case let .wallpaper(wallpaper, _) = entry, case let .file(_, _, _, _, true, _, _, _ , settings) = wallpaper, !settings.colors.isEmpty {
if self.patternPanelNode?.backgroundColors != nil, let snapshotView = self.patternPanelNode?.scrollNode.view.snapshotContentTree() {
/*if self.patternPanelNode?.backgroundColors != nil, let snapshotView = self.patternPanelNode?.scrollNode.view.snapshotContentTree() {
self.patternPanelNode?.view.addSubview(snapshotView)
snapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false) { [weak snapshotView] _ in
snapshotView?.removeFromSuperview()
}
}
}*/
//self.patternPanelNode?.backgroundColors = ([settings.colors[0]], nil)
}
if self.colorsPanelEnabled || self.patternPanelEnabled {
self.colorsPanelEnabled = false
self.patternPanelEnabled = false
if let (layout, _) = self.validLayout {
self.containerLayoutUpdated(layout, transition: .animated(duration: 0.3, curve: .spring))
}
}
}
}

View File

@ -284,9 +284,10 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
switch entry {
case let .wallpaper(wallpaper, _):
self.nativeNode.update(wallpaper: wallpaper)
if case let .file(_, _, _, _, isPattern, _, _, _, settings) = wallpaper, isPattern {
self.nativeNode.isHidden = false
self.nativeNode.update(wallpaper: wallpaper)
self.patternButtonNode.isSelected = isPattern
if isPattern && settings.colors.count >= 3 {
@ -629,11 +630,11 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
}))
} else if self.arguments.patternEnabled != previousArguments.patternEnabled {
self.patternButtonNode.isSelected = self.arguments.patternEnabled
}
if let (layout, _) = self.validLayout {
self.updateButtonsLayout(layout: layout, offset: CGPoint(), transition: .immediate)
self.updateMessagesLayout(layout: layout, offset: CGPoint(), transition: .immediate)
}
if let (layout, _) = self.validLayout {
self.updateButtonsLayout(layout: layout, offset: CGPoint(), transition: .immediate)
self.updateMessagesLayout(layout: layout, offset: CGPoint(), transition: .immediate)
}
}
@ -949,9 +950,8 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
motionAlpha = 0.0
patternAlpha = 1.0
patternFrame = leftButtonFrame.offsetBy(dx: -centerOffset, dy: 0.0)
colorsFrame = colorsFrame.offsetBy(dx: centerOffset, dy: 0.0)
playAlpha = 1.0
patternFrame = leftButtonFrame
playAlpha = 0.0
colorsAlpha = 1.0
case .image:
@ -959,13 +959,18 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
blurFrame = leftButtonFrame
motionAlpha = 1.0
motionFrame = rightButtonFrame
case .gradient:
case let .gradient(colors, _):
motionAlpha = 0.0
patternAlpha = 1.0
patternFrame = leftButtonFrame.offsetBy(dx: -centerOffset, dy: 0.0)
colorsFrame = colorsFrame.offsetBy(dx: centerOffset, dy: 0.0)
playAlpha = 1.0
if colors.count >= 2 {
playAlpha = 1.0
patternFrame = leftButtonFrame.offsetBy(dx: -centerOffset, dy: 0.0)
colorsFrame = colorsFrame.offsetBy(dx: centerOffset, dy: 0.0)
} else {
playAlpha = 0.0
patternFrame = leftButtonFrame
}
colorsAlpha = 1.0
case let .file(file):
@ -973,9 +978,14 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
motionAlpha = 0.0
patternAlpha = 1.0
patternFrame = leftButtonFrame.offsetBy(dx: -centerOffset, dy: 0.0)
colorsFrame = colorsFrame.offsetBy(dx: centerOffset, dy: 0.0)
playAlpha = 1.0
if file.settings.colors.count >= 2 {
playAlpha = 1.0
patternFrame = leftButtonFrame.offsetBy(dx: -centerOffset, dy: 0.0)
colorsFrame = colorsFrame.offsetBy(dx: centerOffset, dy: 0.0)
} else {
playAlpha = 0.0
patternFrame = leftButtonFrame
}
colorsAlpha = 1.0
} else {

View File

@ -75,7 +75,7 @@ public func chatControllerBackgroundImage(theme: PresentationTheme?, wallpaper i
case let .file(file):
if wallpaper.isPattern, !file.settings.colors.isEmpty, let intensity = file.settings.intensity {
var image: UIImage?
let _ = mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: true).start(next: { data in
let _ = mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: true).start(next: { data in
if data.complete {
image = UIImage(contentsOfFile: data.path)?.precomposed()
}
@ -175,7 +175,7 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
}
case let .file(file):
if wallpaper.isPattern, !file.settings.colors.isEmpty, let intensity = file.settings.intensity {
let representation = CachedPatternWallpaperRepresentation(color: file.settings.colors.count >= 1 ? file.settings.colors[0] : 0, bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : 0, intensity: intensity, rotation: file.settings.rotation)
let representation = CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation)
let effectiveMediaBox: MediaBox
if FileManager.default.fileExists(atPath: mediaBox.cachedRepresentationCompletePath(file.file.resource.id, representation: representation)) {
@ -214,7 +214,7 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
}
})
return .single((interrimImage, false)) |> then(effectiveMediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 1 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: false)
return .single((interrimImage, false)) |> then(effectiveMediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: false)
|> map { data -> (UIImage?, Bool)? in
return (UIImage(contentsOfFile: data.path)?.precomposed(), true)
})

View File

@ -432,7 +432,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
self.botStart = botStart
self.peekData = peekData
self.chatBackgroundNode = WallpaperBackgroundNode(context: context)
self.chatBackgroundNode = WallpaperBackgroundNode(context: context, useSharedAnimationPhase: true)
var locationBroadcastPanelSource: LocationBroadcastPanelSource
var groupCallPanelSource: GroupCallPanelSource

View File

@ -1610,6 +1610,8 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
}
self.updatePlainInputSeparator(transition: .immediate)
self.inputPanelBackgroundSeparatorNode.backgroundColor = self.chatPresentationInterfaceState.theme.chat.inputPanel.panelSeparatorColor
self.backgroundNode.updateBubbleTheme(bubbleTheme: chatPresentationInterfaceState.theme, bubbleCorners: chatPresentationInterfaceState.bubbleCorners)
}
let keepSendButtonEnabled = chatPresentationInterfaceState.interfaceState.forwardMessageIds != nil || chatPresentationInterfaceState.interfaceState.editMessage != nil

View File

@ -101,7 +101,7 @@ final class ChatMessageBubbleBackdrop: ASDisplayNode {
let maskMode = self.fixedMaskMode ?? inputMaskMode
if self.currentType != type || self.theme != theme || self.currentMaskMode != maskMode || self.essentialGraphics !== essentialGraphics || self.backgroundNode !== backgroundNode {
let typeUpdated = self.currentType != type
let typeUpdated = self.currentType != type || self.theme != theme || self.currentMaskMode != maskMode || self.backgroundNode !== backgroundNode
self.currentType = type
self.theme = theme

View File

@ -2211,6 +2211,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
backgroundView.frame = self.textInputBackgroundNode.frame
func updateIsCaretHidden(view: UIView, isHidden: Bool) {
return;
if String(describing: type(of: view)).contains("TextSelectionView") {
view.isHidden = isHidden
} else {

View File

@ -19,6 +19,7 @@ import WallpaperResources
import Svg
import GZip
import TelegramUniversalVideoContent
import GradientBackground
public func fetchCachedResourceRepresentation(account: Account, resource: MediaResource, representation: CachedMediaResourceRepresentation) -> Signal<CachedMediaResourceRepresentationResult, NoError> {
if let representation = representation as? CachedStickerAJpegRepresentation {
@ -480,11 +481,7 @@ private func fetchCachedPatternWallpaperRepresentation(resource: MediaResource,
let path = NSTemporaryDirectory() + "\(Int64.random(in: Int64.min ... Int64.max))"
let url = URL(fileURLWithPath: path)
var colors: [UIColor] = []
if let bottomColor = representation.bottomColor {
colors.append(UIColor(rgb: bottomColor))
}
colors.append(UIColor(rgb: representation.color))
let colors: [UIColor] = representation.colors.map(UIColor.init(rgb:))
let intensity = CGFloat(representation.intensity) / 100.0
@ -510,6 +507,16 @@ private func fetchCachedPatternWallpaperRepresentation(resource: MediaResource,
if colors.count == 1, let color = colors.first {
c.setFillColor(color.cgColor)
c.fill(rect)
} else if colors.count >= 3 {
let drawingRect = rect
let image = GradientBackgroundNode.generatePreview(size: CGSize(width: 60.0, height: 60.0), colors: colors)
c.translateBy(x: drawingRect.midX, y: drawingRect.midY)
c.scaleBy(x: 1.0, y: -1.0)
c.translateBy(x: -drawingRect.midX, y: -drawingRect.midY)
c.draw(image.cgImage!, in: drawingRect)
c.translateBy(x: drawingRect.midX, y: drawingRect.midY)
c.scaleBy(x: 1.0, y: -1.0)
c.translateBy(x: -drawingRect.midX, y: -drawingRect.midY)
} else {
let gradientColors = colors.map { $0.cgColor } as CFArray
let delta: CGFloat = 1.0 / (CGFloat(colors.count) - 1.0)
@ -535,6 +542,10 @@ private func fetchCachedPatternWallpaperRepresentation(resource: MediaResource,
c.clip(to: rect, mask: cgImage)
}
if colors.count >= 3 {
c.setBlendMode(.softLight)
}
if colors.count == 1, let color = colors.first {
c.setFillColor(patternColor(for: color, intensity: intensity).cgColor)
c.fill(rect)

View File

@ -167,7 +167,7 @@ public func upgradedAccounts(accountManager: AccountManager, rootPath: String, e
let _ = accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: true, fetch: true).start()
if wallpaper.isPattern {
if !file.settings.colors.isEmpty, let intensity = file.settings.intensity {
let _ = accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true).start()
let _ = accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true).start()
}
} else {
if file.settings.blur {

@ -1 +1 @@
Subproject commit f89519e4fbfe7c0abceefcc60acd22d3b763598e
Subproject commit c918c50087466adf5fdca47f2f62de58eccf514b

View File

@ -178,6 +178,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
}
private let context: AccountContext
private let useSharedAnimationPhase: Bool
private let contentNode: ASDisplayNode
private var gradientBackgroundNode: GradientBackgroundNode?
@ -245,8 +246,9 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
}
}
public init(context: AccountContext) {
public init(context: AccountContext, useSharedAnimationPhase: Bool = false) {
self.context = context
self.useSharedAnimationPhase = useSharedAnimationPhase
self.imageContentMode = .scaleAspectFill
self.contentNode = ASDisplayNode()
@ -289,7 +291,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
if gradientColors.count >= 3 {
if self.gradientBackgroundNode == nil {
let gradientBackgroundNode = createGradientBackgroundNode()
let gradientBackgroundNode = createGradientBackgroundNode(useSharedAnimationPhase: self.useSharedAnimationPhase)
self.gradientBackgroundNode = gradientBackgroundNode
self.insertSubnode(gradientBackgroundNode, aboveSubnode: self.contentNode)
gradientBackgroundNode.addSubnode(self.patternImageNode)

View File

@ -810,10 +810,8 @@ public func drawThemeImage(context c: CGContext, theme: PresentationTheme, wallp
let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)!
c.drawLinearGradient(gradient, start: CGPoint(x: 0.0, y: drawingRect.height), end: CGPoint(x: 0.0, y: 0.0), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation])
}
case .file:
case let .file(file):
c.setFillColor(theme.chatList.backgroundColor.cgColor)
c.fill(drawingRect)
if let image = wallpaperImage, let cgImage = image.cgImage {
let size = image.size.aspectFilled(drawingRect.size)
c.draw(cgImage, in: CGRect(origin: CGPoint(x: (drawingRect.size.width - size.width) / 2.0, y: (drawingRect.size.height - size.height) / 2.0), size: size))
@ -1026,7 +1024,7 @@ public func themeImage(account: Account, accountManager: AccountManager, source:
let _ = accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: true, fetch: true).start()
if wallpaper.wallpaper.isPattern, !file.settings.colors.isEmpty, let intensity = file.settings.intensity {
return accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true)
return accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true)
|> mapToSignal { data in
if data.complete, let data = try? Data(contentsOf: URL(fileURLWithPath: data.path)), let image = UIImage(data: data) {
return .single((theme, image, thumbnailData))
@ -1325,7 +1323,7 @@ public func themeIconImage(account: Account, accountManager: AccountManager, the
if wallpaper.wallpaper.isPattern {
if !file.settings.colors.isEmpty, let intensity = file.settings.intensity {
return accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true)
return accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true)
|> mapToSignal { _ in
return .single((effectiveBackgroundColor, incomingColor, outgoingColor, nil, rotation))
}