Chat wallpaper fixes

This commit is contained in:
Ilya Laktyushin
2023-04-12 12:41:07 +04:00
parent 62470a424f
commit 256439b138
6 changed files with 57 additions and 25 deletions

View File

@@ -303,7 +303,7 @@ public func uploadCustomPeerWallpaper(context: AccountContext, wallpaper: Wallpa
var intensity: Int32?
if let brightness {
intensity = max(1, Int32(brightness * 100.0))
intensity = max(0, min(100, Int32(brightness * 100.0)))
}
let settings = WallpaperSettings(blur: mode.contains(.blur), motion: mode.contains(.motion), colors: [], intensity: intensity)

View File

@@ -313,7 +313,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
}
switch entry {
case .asset, .contextResult:
return self.sliderNode.value
return 1.0 - self.sliderNode.value
default:
return nil
}

View File

@@ -125,6 +125,14 @@ func _internal_setChatWallpaper(postbox: Postbox, network: Network, stateManager
return .complete()
}
return postbox.transaction { transaction -> Signal<Api.Updates, NoError> in
transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in
if let current = current as? CachedUserData {
return current.withUpdatedWallpaper(wallpaper)
} else {
return current
}
})
var flags: Int32 = 0
var inputWallpaper: Api.InputWallPaper?
var inputSettings: Api.WallPaperSettings?
@@ -139,19 +147,10 @@ func _internal_setChatWallpaper(postbox: Postbox, network: Network, stateManager
return .complete()
}
|> mapToSignal { updates -> Signal<Api.Updates, NoError> in
return postbox.transaction { transaction -> Api.Updates in
transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in
if let current = current as? CachedUserData {
return current.withUpdatedWallpaper(wallpaper)
} else {
return current
}
})
if applyUpdates {
stateManager.addUpdates(updates)
}
return updates
}
return .single(updates)
}
} |> switchToLatest
}

View File

@@ -1071,7 +1071,13 @@ private class ChatThemeScreenNode: ViewControllerTracingNode, UIScrollViewDelega
self.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: .immediate)
}
self.cancelButtonNode.theme = presentationData.theme
if let animatingCrossFade = self.animatingCrossFade {
Queue.mainQueue().after(!animatingCrossFade ? ChatThemeScreen.themeCrossfadeDelay * UIView.animationDurationFactor() : 0.0, {
self.cancelButtonNode.setTheme(presentationData.theme, animated: true)
})
} else {
self.cancelButtonNode.setTheme(presentationData.theme, animated: false)
}
let previousIconColors = iconColors(theme: previousTheme)
let newIconColors = iconColors(theme: self.presentationData.theme)
@@ -1164,6 +1170,7 @@ private class ChatThemeScreenNode: ViewControllerTracingNode, UIScrollViewDelega
}
}
private var animatingCrossFade: Bool?
private func animateCrossfade(animateIcon: Bool) {
if animateIcon, let snapshotView = self.animationNode.view.snapshotView(afterScreenUpdates: false) {
snapshotView.frame = self.animationNode.frame
@@ -1174,6 +1181,7 @@ private class ChatThemeScreenNode: ViewControllerTracingNode, UIScrollViewDelega
})
}
self.animatingCrossFade = animateIcon
Queue.mainQueue().after(ChatThemeScreen.themeCrossfadeDelay * UIView.animationDurationFactor()) {
if let effectView = self.effectNode.view as? UIVisualEffectView {
UIView.animate(withDuration: ChatThemeScreen.themeCrossfadeDuration, delay: 0.0, options: .curveLinear) {
@@ -1185,6 +1193,8 @@ private class ChatThemeScreenNode: ViewControllerTracingNode, UIScrollViewDelega
let previousColor = self.contentBackgroundNode.backgroundColor ?? .clear
self.contentBackgroundNode.backgroundColor = self.presentationData.theme.actionSheet.itemBackgroundColor
self.contentBackgroundNode.layer.animate(from: previousColor.cgColor, to: (self.contentBackgroundNode.backgroundColor ?? .clear).cgColor, keyPath: "backgroundColor", timingFunction: CAMediaTimingFunctionName.linear.rawValue, duration: ChatThemeScreen.themeCrossfadeDuration)
self.animatingCrossFade = nil
}
if let snapshotView = self.contentContainerNode.view.snapshotView(afterScreenUpdates: false) {

View File

@@ -917,8 +917,8 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
default:
break
}
if let intensity, intensity < 100 {
dimAlpha = 1.0 - max(0.0, min(1.0, Float(intensity) / 100.0))
if let intensity, intensity > 0 {
dimAlpha = max(0.0, min(1.0, Float(intensity) / 100.0))
}
}
self.dimLayer.opacity = dimAlpha

View File

@@ -38,15 +38,20 @@ public class WebAppCancelButtonNode: ASDisplayNode {
public var state: State = .cancel
private var _theme: PresentationTheme
public var theme: PresentationTheme {
didSet {
self.setState(self.state, animated: false, force: true)
get {
return self._theme
}
set {
self._theme = newValue
self.setState(self.state, animated: false, animateScale: false, force: true)
}
}
private let strings: PresentationStrings
public init(theme: PresentationTheme, strings: PresentationStrings) {
self.theme = theme
self._theme = theme
self.strings = strings
self.buttonNode = HighlightTrackingButtonNode()
@@ -55,6 +60,7 @@ public class WebAppCancelButtonNode: ASDisplayNode {
self.arrowNode.displaysAsynchronously = false
self.labelNode = ImmediateTextNode()
self.labelNode.displaysAsynchronously = false
super.init()
@@ -82,24 +88,41 @@ public class WebAppCancelButtonNode: ASDisplayNode {
self.setState(.cancel, animated: false, force: true)
}
public func setState(_ state: State, animated: Bool, force: Bool = false) {
public func setTheme(_ theme: PresentationTheme, animated: Bool) {
self._theme = theme
var animated = animated
if self.animatingStateChange {
animated = false
}
self.setState(self.state, animated: animated, animateScale: false, force: true)
}
private var animatingStateChange = false
public func setState(_ state: State, animated: Bool, animateScale: Bool = true, force: Bool = false) {
guard self.state != state || force else {
return
}
self.state = state
if animated, let snapshotView = self.buttonNode.view.snapshotContentTree() {
self.animatingStateChange = true
snapshotView.layer.sublayerTransform = self.buttonNode.subnodeTransform
self.view.addSubview(snapshotView)
let duration: Double = animateScale ? 0.25 : 0.3
if animateScale {
snapshotView.layer.animateScale(from: 1.0, to: 0.001, duration: 0.25, removeOnCompletion: false)
snapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.25, removeOnCompletion: false, completion: { [weak snapshotView] _ in
}
snapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: duration, removeOnCompletion: false, completion: { [weak snapshotView] _ in
snapshotView?.removeFromSuperview()
self.animatingStateChange = false
})
self.buttonNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.25)
if animateScale {
self.buttonNode.layer.animateScale(from: 0.001, to: 1.0, duration: 0.25)
}
self.buttonNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: duration)
}
self.arrowNode.isHidden = state == .cancel
self.labelNode.attributedText = NSAttributedString(string: state == .cancel ? self.strings.Common_Cancel : self.strings.Common_Back, font: Font.regular(17.0), textColor: self.theme.rootController.navigationBar.accentTextColor)