diff --git a/submodules/SettingsUI/Sources/Themes/CustomWallpaperPicker.swift b/submodules/SettingsUI/Sources/Themes/CustomWallpaperPicker.swift index c5d5b92ee7..4ce31af850 100644 --- a/submodules/SettingsUI/Sources/Themes/CustomWallpaperPicker.swift +++ b/submodules/SettingsUI/Sources/Themes/CustomWallpaperPicker.swift @@ -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) diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift index 6de92eefa2..9c1b0cc225 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift @@ -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 } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift b/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift index 406394d937..8e97221e71 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Themes/ChatThemes.swift @@ -125,6 +125,14 @@ func _internal_setChatWallpaper(postbox: Postbox, network: Network, stateManager return .complete() } return postbox.transaction { transaction -> Signal 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 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 + if applyUpdates { + stateManager.addUpdates(updates) } + return .single(updates) } } |> switchToLatest } diff --git a/submodules/TelegramUI/Sources/ChatThemeScreen.swift b/submodules/TelegramUI/Sources/ChatThemeScreen.swift index 1ca1e7719e..bb157f8e4a 100644 --- a/submodules/TelegramUI/Sources/ChatThemeScreen.swift +++ b/submodules/TelegramUI/Sources/ChatThemeScreen.swift @@ -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) { diff --git a/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift b/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift index 7076506512..957db88bfb 100644 --- a/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift +++ b/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift @@ -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 diff --git a/submodules/WebUI/Sources/WebAppController.swift b/submodules/WebUI/Sources/WebAppController.swift index ca54875593..f6b4df4f4c 100644 --- a/submodules/WebUI/Sources/WebAppController.swift +++ b/submodules/WebUI/Sources/WebAppController.swift @@ -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,23 +88,40 @@ 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) - 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 + 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: 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) - self.buttonNode.layer.animateScale(from: 0.001, 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