Wallpaper fixes

This commit is contained in:
Ali 2021-05-31 17:15:56 +04:00
parent 7e52c6c345
commit 9a364604c1
5 changed files with 48 additions and 41 deletions

View File

@ -88,34 +88,9 @@ public class NavigationBarSearchContentNode: NavigationBarContentNode {
}
public func setIsEnabled(_ enabled: Bool, animated: Bool = false) {
if !enabled {
if self.disabledOverlay == nil {
let disabledOverlay = ASDisplayNode()
self.addSubnode(disabledOverlay)
self.disabledOverlay = disabledOverlay
if animated {
disabledOverlay.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.25)
}
}
if let disabledOverlay = self.disabledOverlay {
disabledOverlay.backgroundColor = self.theme?.rootController.navigationBar.opaqueBackgroundColor.withAlphaComponent(0.4)
var disabledOverlayFrame = self.placeholderNode.frame
if let searchBarHeight = self.placeholderHeight {
disabledOverlayFrame.size.height = searchBarHeight
}
disabledOverlay.frame = disabledOverlayFrame
}
} else if let disabledOverlay = self.disabledOverlay {
self.disabledOverlay = nil
if animated {
disabledOverlay.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false, completion: { [weak disabledOverlay] _ in
disabledOverlay?.removeFromSupernode()
})
} else {
disabledOverlay.removeFromSupernode()
}
}
let transition: ContainedViewLayoutTransition = animated ? .animated(duration: 0.25, curve: .easeInOut) : .immediate
transition.updateAlpha(node: self.placeholderNode, alpha: enabled ? 1.0 : 0.6)
self.placeholderNode.isUserInteractionEnabled = enabled
}
private func updatePlaceholder(_ progress: CGFloat, size: CGSize, leftInset: CGFloat, rightInset: CGFloat, transition: ContainedViewLayoutTransition) {

View File

@ -251,15 +251,7 @@ final class ThemePreviewControllerNode: ASDisplayNode, UIScrollViewDelegate {
let fileReference = FileMediaReference.standalone(media: file.file)
if wallpaper.isPattern {
signal = patternWallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, representations: convertedRepresentations, mode: .screen, autoFetchFullSize: false)
}/* else if strongSelf.instantChatBackgroundNode.image == nil {
signal = wallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, fileReference: fileReference, representations: convertedRepresentations, alwaysShowThumbnailFirst: false, autoFetchFullSize: false)
|> afterNext { next in
if let _ = context.sharedContext.accountManager.mediaBox.completedResourcePath(file.file.resource) {
} else if let path = context.account.postbox.mediaBox.completedResourcePath(file.file.resource), let data = try? Data(contentsOf: URL(fileURLWithPath: path)) {
context.sharedContext.accountManager.mediaBox.storeResourceData(file.file.resource.id, data: data)
}
}
}*/ else {
} else {
signal = .complete()
}
strongSelf.remoteChatBackgroundNode.setSignal(signal)

View File

@ -257,6 +257,23 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
|> afterNext { image in
cacheWallpaper(image?.0)
}
} else {
return Signal { subscriber in
let fetch = fetchedMediaResource(mediaBox: accountMediaBox, reference: MediaResourceReference.standalone(resource: file.file.resource)).start()
let data = accountMediaBox.resourceData(file.file.resource).start(next: { data in
if data.complete {
if let image = UIImage(contentsOfFile: data.path)?.precomposed() {
mediaBox.copyResourceData(file.file.resource.id, fromTempPath: data.path)
subscriber.putNext((image, true))
}
}
})
return ActionDisposable {
fetch.dispose()
data.dispose()
}
}
}
}
}

View File

@ -32,9 +32,12 @@ func titlePanelForChatPresentationInterfaceState(_ chatPresentationInterfaceStat
loop: for context in chatPresentationInterfaceState.titlePanelContexts.reversed() {
switch context {
case .pinnedMessage:
if let pinnedMessage = chatPresentationInterfaceState.pinnedMessage, pinnedMessage.topMessageId != chatPresentationInterfaceState.interfaceState.messageActionsState.closedPinnedMessageId, !chatPresentationInterfaceState.pendingUnpinnedAllMessages {
selectedContext = context
break loop
if case .pinnedMessages = chatPresentationInterfaceState.subject {
} else {
if let pinnedMessage = chatPresentationInterfaceState.pinnedMessage, pinnedMessage.topMessageId != chatPresentationInterfaceState.interfaceState.messageActionsState.closedPinnedMessageId, !chatPresentationInterfaceState.pendingUnpinnedAllMessages {
selectedContext = context
break loop
}
}
case .chatInfo, .requestInProgress, .toastAlert:
selectedContext = context

View File

@ -201,6 +201,8 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
private var bubbleTheme: PresentationTheme?
private var bubbleCorners: PresentationChatBubbleCorners?
private var bubbleBackgroundNodeReferences = SparseBag<BubbleBackgroundNodeReference>()
private let wallpaperDisposable = MetaDisposable()
private var motionEnabled: Bool = false {
didSet {
@ -275,6 +277,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
deinit {
self.patternImageDisposable.dispose()
self.wallpaperDisposable.dispose()
}
public func update(wallpaper: TelegramWallpaper) {
@ -311,6 +314,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
self.contentNode.backgroundColor = nil
self.contentNode.contents = nil
self.motionEnabled = false
self.wallpaperDisposable.set(nil)
} else {
if let gradientBackgroundNode = self.gradientBackgroundNode {
self.gradientBackgroundNode = nil
@ -335,12 +339,28 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
context.drawLinearGradient(gradient, start: CGPoint(x: 0.0, y: 0.0), end: CGPoint(x: 0.0, y: size.height), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation])
})?.cgImage
self.wallpaperDisposable.set(nil)
} else if gradientColors.count >= 1 {
self.contentNode.backgroundColor = UIColor(rgb: gradientColors[0])
self.contentNode.contents = nil
self.wallpaperDisposable.set(nil)
} else {
self.contentNode.backgroundColor = .white
self.contentNode.contents = chatControllerBackgroundImage(theme: nil, wallpaper: wallpaper, mediaBox: self.context.sharedContext.accountManager.mediaBox, knockoutMode: false)?.cgImage
if let image = chatControllerBackgroundImage(theme: nil, wallpaper: wallpaper, mediaBox: self.context.sharedContext.accountManager.mediaBox, knockoutMode: false) {
self.contentNode.contents = image.cgImage
self.wallpaperDisposable.set(nil)
} else if let image = chatControllerBackgroundImage(theme: nil, wallpaper: wallpaper, mediaBox: self.context.account.postbox.mediaBox, knockoutMode: false) {
self.contentNode.contents = image.cgImage
self.wallpaperDisposable.set(nil)
} else {
self.wallpaperDisposable.set((chatControllerBackgroundImageSignal(wallpaper: wallpaper, mediaBox: self.context.sharedContext.accountManager.mediaBox, accountMediaBox: self.context.account.postbox.mediaBox)
|> deliverOnMainQueue).start(next: { [weak self] image in
guard let strongSelf = self else {
return
}
strongSelf.contentNode.contents = image?.0?.cgImage
}))
}
self.contentNode.isHidden = false
}
}