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) { public func setIsEnabled(_ enabled: Bool, animated: Bool = false) {
if !enabled { let transition: ContainedViewLayoutTransition = animated ? .animated(duration: 0.25, curve: .easeInOut) : .immediate
if self.disabledOverlay == nil { transition.updateAlpha(node: self.placeholderNode, alpha: enabled ? 1.0 : 0.6)
let disabledOverlay = ASDisplayNode() self.placeholderNode.isUserInteractionEnabled = enabled
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()
}
}
} }
private func updatePlaceholder(_ progress: CGFloat, size: CGSize, leftInset: CGFloat, rightInset: CGFloat, transition: ContainedViewLayoutTransition) { 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) let fileReference = FileMediaReference.standalone(media: file.file)
if wallpaper.isPattern { if wallpaper.isPattern {
signal = patternWallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, representations: convertedRepresentations, mode: .screen, autoFetchFullSize: false) signal = patternWallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, representations: convertedRepresentations, mode: .screen, autoFetchFullSize: false)
}/* else if strongSelf.instantChatBackgroundNode.image == nil { } else {
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 {
signal = .complete() signal = .complete()
} }
strongSelf.remoteChatBackgroundNode.setSignal(signal) strongSelf.remoteChatBackgroundNode.setSignal(signal)

View File

@@ -257,6 +257,23 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
|> afterNext { image in |> afterNext { image in
cacheWallpaper(image?.0) 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,10 +32,13 @@ func titlePanelForChatPresentationInterfaceState(_ chatPresentationInterfaceStat
loop: for context in chatPresentationInterfaceState.titlePanelContexts.reversed() { loop: for context in chatPresentationInterfaceState.titlePanelContexts.reversed() {
switch context { switch context {
case .pinnedMessage: case .pinnedMessage:
if case .pinnedMessages = chatPresentationInterfaceState.subject {
} else {
if let pinnedMessage = chatPresentationInterfaceState.pinnedMessage, pinnedMessage.topMessageId != chatPresentationInterfaceState.interfaceState.messageActionsState.closedPinnedMessageId, !chatPresentationInterfaceState.pendingUnpinnedAllMessages { if let pinnedMessage = chatPresentationInterfaceState.pinnedMessage, pinnedMessage.topMessageId != chatPresentationInterfaceState.interfaceState.messageActionsState.closedPinnedMessageId, !chatPresentationInterfaceState.pendingUnpinnedAllMessages {
selectedContext = context selectedContext = context
break loop break loop
} }
}
case .chatInfo, .requestInProgress, .toastAlert: case .chatInfo, .requestInProgress, .toastAlert:
selectedContext = context selectedContext = context
break loop break loop

View File

@@ -202,6 +202,8 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
private var bubbleCorners: PresentationChatBubbleCorners? private var bubbleCorners: PresentationChatBubbleCorners?
private var bubbleBackgroundNodeReferences = SparseBag<BubbleBackgroundNodeReference>() private var bubbleBackgroundNodeReferences = SparseBag<BubbleBackgroundNodeReference>()
private let wallpaperDisposable = MetaDisposable()
private var motionEnabled: Bool = false { private var motionEnabled: Bool = false {
didSet { didSet {
if oldValue != self.motionEnabled { if oldValue != self.motionEnabled {
@@ -275,6 +277,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
deinit { deinit {
self.patternImageDisposable.dispose() self.patternImageDisposable.dispose()
self.wallpaperDisposable.dispose()
} }
public func update(wallpaper: TelegramWallpaper) { public func update(wallpaper: TelegramWallpaper) {
@@ -311,6 +314,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
self.contentNode.backgroundColor = nil self.contentNode.backgroundColor = nil
self.contentNode.contents = nil self.contentNode.contents = nil
self.motionEnabled = false self.motionEnabled = false
self.wallpaperDisposable.set(nil)
} else { } else {
if let gradientBackgroundNode = self.gradientBackgroundNode { if let gradientBackgroundNode = self.gradientBackgroundNode {
self.gradientBackgroundNode = nil 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]) context.drawLinearGradient(gradient, start: CGPoint(x: 0.0, y: 0.0), end: CGPoint(x: 0.0, y: size.height), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation])
})?.cgImage })?.cgImage
self.wallpaperDisposable.set(nil)
} else if gradientColors.count >= 1 { } else if gradientColors.count >= 1 {
self.contentNode.backgroundColor = UIColor(rgb: gradientColors[0]) self.contentNode.backgroundColor = UIColor(rgb: gradientColors[0])
self.contentNode.contents = nil self.contentNode.contents = nil
self.wallpaperDisposable.set(nil)
} else { } else {
self.contentNode.backgroundColor = .white 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 self.contentNode.isHidden = false
} }
} }