Theme fixes

This commit is contained in:
Ilya Laktyushin 2019-12-27 18:19:28 +03:00
parent 8518bc5e32
commit 7aa978e827
7 changed files with 52 additions and 26 deletions

View File

@ -41,6 +41,8 @@ public final class ThemePreviewController: ViewController {
return self._ready return self._ready
} }
private var validLayout: ContainerViewLayout?
private var didPlayPresentationAnimation = false private var didPlayPresentationAnimation = false
private var presentationData: PresentationData private var presentationData: PresentationData
@ -399,11 +401,11 @@ public final class ThemePreviewController: ViewController {
} }
} }
|> deliverOnMainQueue).start(next: { [weak self] previousDefaultTheme in |> deliverOnMainQueue).start(next: { [weak self] previousDefaultTheme in
if let strongSelf = self { if let strongSelf = self, let layout = strongSelf.validLayout, layout.size.width >= 375.0 {
Queue.mainQueue().after(0.3) { Queue.mainQueue().after(0.3) {
let navigationController = strongSelf.navigationController as? NavigationController let navigationController = strongSelf.navigationController as? NavigationController
if let (previousDefaultTheme, autoNightMode) = previousDefaultTheme { if let (previousDefaultTheme, autoNightMode) = previousDefaultTheme {
strongSelf.present(UndoOverlayController(presentationData: strongSelf.presentationData, content: .actionSucceeded(title: strongSelf.presentationData.strings.Theme_ThemeChanged, text: strongSelf.presentationData.strings.Theme_ThemeChangedText, cancel: strongSelf.presentationData.strings.Undo_Undo), elevatedLayout: false, animateInAsReplacement: false, action: { value in strongSelf.present(UndoOverlayController(presentationData: strongSelf.presentationData, content: .actionSucceeded(title: strongSelf.presentationData.strings.Theme_ThemeChanged, text: strongSelf.presentationData.strings.Theme_ThemeChangedText, cancel: strongSelf.presentationData.strings.Undo_Undo), elevatedLayout: true, animateInAsReplacement: false, action: { value in
if value == .undo { if value == .undo {
let _ = updatePresentationThemeSettingsInteractively(accountManager: context.sharedContext.accountManager, { current -> PresentationThemeSettings in let _ = updatePresentationThemeSettingsInteractively(accountManager: context.sharedContext.accountManager, { current -> PresentationThemeSettings in
var updated: PresentationThemeSettings var updated: PresentationThemeSettings
@ -435,6 +437,8 @@ public final class ThemePreviewController: ViewController {
override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) { override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
super.containerLayoutUpdated(layout, transition: transition) super.containerLayoutUpdated(layout, transition: transition)
self.validLayout = layout
self.controllerNode.containerLayoutUpdated(layout, navigationBarHeight: self.navigationHeight, transition: transition) self.controllerNode.containerLayoutUpdated(layout, navigationBarHeight: self.navigationHeight, transition: transition)
} }

View File

@ -26,7 +26,7 @@ private struct ThemeSettingsThemeEntry: Comparable, Identifiable {
let wallpaper: TelegramWallpaper? let wallpaper: TelegramWallpaper?
var stableId: Int64 { var stableId: Int64 {
return self.themeReference.index return self.themeReference.generalThemeReference.index
} }
static func ==(lhs: ThemeSettingsThemeEntry, rhs: ThemeSettingsThemeEntry) -> Bool { static func ==(lhs: ThemeSettingsThemeEntry, rhs: ThemeSettingsThemeEntry) -> Bool {

View File

@ -30,8 +30,10 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
} }
} }
private let cancelButton = HighlightableButtonNode() private let cancelButton = HighlightTrackingButtonNode()
private let doneButton = HighlightableButtonNode() private let cancelHighlightBackgroundNode = ASDisplayNode()
private let doneButton = HighlightTrackingButtonNode()
private let doneHighlightBackgroundNode = ASDisplayNode()
private let separatorNode = ASDisplayNode() private let separatorNode = ASDisplayNode()
private let topSeparatorNode = ASDisplayNode() private let topSeparatorNode = ASDisplayNode()
@ -46,7 +48,9 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
super.init() super.init()
self.addSubnode(self.cancelHighlightBackgroundNode)
self.addSubnode(self.cancelButton) self.addSubnode(self.cancelButton)
self.addSubnode(self.doneHighlightBackgroundNode)
self.addSubnode(self.doneButton) self.addSubnode(self.doneButton)
self.addSubnode(self.separatorNode) self.addSubnode(self.separatorNode)
self.addSubnode(self.topSeparatorNode) self.addSubnode(self.topSeparatorNode)
@ -56,11 +60,11 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
self.cancelButton.highligthedChanged = { [weak self] highlighted in self.cancelButton.highligthedChanged = { [weak self] highlighted in
if let strongSelf = self { if let strongSelf = self {
if highlighted { if highlighted {
strongSelf.cancelButton.backgroundColor = strongSelf.theme.list.itemHighlightedBackgroundColor strongSelf.cancelHighlightBackgroundNode.layer.removeAnimation(forKey: "opacity")
strongSelf.cancelHighlightBackgroundNode.alpha = 1.0
} else { } else {
UIView.animate(withDuration: 0.3, animations: { strongSelf.cancelHighlightBackgroundNode.alpha = 0.0
strongSelf.cancelButton.backgroundColor = .clear strongSelf.cancelHighlightBackgroundNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3)
})
} }
} }
} }
@ -68,11 +72,11 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
self.doneButton.highligthedChanged = { [weak self] highlighted in self.doneButton.highligthedChanged = { [weak self] highlighted in
if let strongSelf = self { if let strongSelf = self {
if highlighted { if highlighted {
strongSelf.doneButton.backgroundColor = strongSelf.theme.list.itemHighlightedBackgroundColor strongSelf.doneHighlightBackgroundNode.layer.removeAnimation(forKey: "opacity")
strongSelf.doneHighlightBackgroundNode.alpha = 1.0
} else { } else {
UIView.animate(withDuration: 0.3, animations: { strongSelf.doneHighlightBackgroundNode.alpha = 0.0
strongSelf.doneButton.backgroundColor = .clear strongSelf.doneHighlightBackgroundNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3)
})
} }
} }
} }
@ -91,6 +95,8 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
self.backgroundColor = theme.rootController.tabBar.backgroundColor self.backgroundColor = theme.rootController.tabBar.backgroundColor
self.separatorNode.backgroundColor = theme.rootController.tabBar.separatorColor self.separatorNode.backgroundColor = theme.rootController.tabBar.separatorColor
self.topSeparatorNode.backgroundColor = theme.rootController.tabBar.separatorColor self.topSeparatorNode.backgroundColor = theme.rootController.tabBar.separatorColor
self.cancelHighlightBackgroundNode.backgroundColor = theme.list.itemHighlightedBackgroundColor
self.doneHighlightBackgroundNode.backgroundColor = theme.list.itemHighlightedBackgroundColor
let cancelTitle: String let cancelTitle: String
switch self.cancelButtonType { switch self.cancelButtonType {
@ -114,7 +120,9 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
func updateLayout(size: CGSize, layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) { func updateLayout(size: CGSize, layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
self.cancelButton.frame = CGRect(origin: CGPoint(), size: CGSize(width: floor(size.width / 2.0), height: size.height)) self.cancelButton.frame = CGRect(origin: CGPoint(), size: CGSize(width: floor(size.width / 2.0), height: size.height))
self.cancelHighlightBackgroundNode.frame = CGRect(origin: CGPoint(), size: CGSize(width: floor(size.width / 2.0), height: size.height))
self.doneButton.frame = CGRect(origin: CGPoint(x: floor(size.width / 2.0), y: 0.0), size: CGSize(width: size.width - floor(size.width / 2.0), height: size.height)) self.doneButton.frame = CGRect(origin: CGPoint(x: floor(size.width / 2.0), y: 0.0), size: CGSize(width: size.width - floor(size.width / 2.0), height: size.height))
self.doneHighlightBackgroundNode.frame = CGRect(origin: CGPoint(x: floor(size.width / 2.0), y: 0.0), size: CGSize(width: size.width - floor(size.width / 2.0), height: size.height))
self.separatorNode.frame = CGRect(origin: CGPoint(x: floor(size.width / 2.0), y: 0.0), size: CGSize(width: UIScreenPixel, height: size.height + layout.intrinsicInsets.bottom)) self.separatorNode.frame = CGRect(origin: CGPoint(x: floor(size.width / 2.0), y: 0.0), size: CGSize(width: UIScreenPixel, height: size.height + layout.intrinsicInsets.bottom))
self.topSeparatorNode.frame = CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: UIScreenPixel)) self.topSeparatorNode.frame = CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: UIScreenPixel))
} }

View File

@ -25,11 +25,11 @@ public final class TelegramThemeSettings: PostboxCoding, Equatable {
} }
public let baseTheme: TelegramBaseTheme public let baseTheme: TelegramBaseTheme
public let accentColor: Int32 public let accentColor: UInt32
public let messageColors: (top: Int32, bottom: Int32)? public let messageColors: (top: UInt32, bottom: UInt32)?
public let wallpaper: TelegramWallpaper? public let wallpaper: TelegramWallpaper?
public init(baseTheme: TelegramBaseTheme, accentColor: Int32, messageColors: (top: Int32, bottom: Int32)?, wallpaper: TelegramWallpaper?) { public init(baseTheme: TelegramBaseTheme, accentColor: UInt32, messageColors: (top: UInt32, bottom: UInt32)?, wallpaper: TelegramWallpaper?) {
self.baseTheme = baseTheme self.baseTheme = baseTheme
self.accentColor = accentColor self.accentColor = accentColor
self.messageColors = messageColors self.messageColors = messageColors
@ -38,9 +38,9 @@ public final class TelegramThemeSettings: PostboxCoding, Equatable {
public init(decoder: PostboxDecoder) { public init(decoder: PostboxDecoder) {
self.baseTheme = TelegramBaseTheme(rawValue: decoder.decodeInt32ForKey("baseTheme", orElse: 0)) ?? .classic self.baseTheme = TelegramBaseTheme(rawValue: decoder.decodeInt32ForKey("baseTheme", orElse: 0)) ?? .classic
self.accentColor = decoder.decodeInt32ForKey("accent", orElse: 0) self.accentColor = UInt32(bitPattern: decoder.decodeInt32ForKey("accent", orElse: 0))
if let topMessageColor = decoder.decodeOptionalInt32ForKey("topMessage"), let bottomMessageColor = decoder.decodeOptionalInt32ForKey("bottomMessage") { if let topMessageColor = decoder.decodeOptionalInt32ForKey("topMessage"), let bottomMessageColor = decoder.decodeOptionalInt32ForKey("bottomMessage") {
self.messageColors = (topMessageColor, bottomMessageColor) self.messageColors = (UInt32(bitPattern: topMessageColor), UInt32(bitPattern: bottomMessageColor))
} else { } else {
self.messageColors = nil self.messageColors = nil
} }
@ -49,10 +49,10 @@ public final class TelegramThemeSettings: PostboxCoding, Equatable {
public func encode(_ encoder: PostboxEncoder) { public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.baseTheme.rawValue, forKey: "baseTheme") encoder.encodeInt32(self.baseTheme.rawValue, forKey: "baseTheme")
encoder.encodeInt32(self.accentColor, forKey: "accent") encoder.encodeInt32(Int32(bitPattern: self.accentColor), forKey: "accent")
if let (topMessageColor, bottomMessageColor) = self.messageColors { if let (topMessageColor, bottomMessageColor) = self.messageColors {
encoder.encodeInt32(topMessageColor, forKey: "topMessage") encoder.encodeInt32(Int32(bitPattern: topMessageColor), forKey: "topMessage")
encoder.encodeInt32(bottomMessageColor, forKey: "bottomMessage") encoder.encodeInt32(Int32(bitPattern: bottomMessageColor), forKey: "bottomMessage")
} else { } else {
encoder.encodeNil(forKey: "topMessage") encoder.encodeNil(forKey: "topMessage")
encoder.encodeNil(forKey: "bottomMessage") encoder.encodeNil(forKey: "bottomMessage")

View File

@ -48,11 +48,11 @@ extension TelegramThemeSettings {
convenience init?(apiThemeSettings: Api.ThemeSettings) { convenience init?(apiThemeSettings: Api.ThemeSettings) {
switch apiThemeSettings { switch apiThemeSettings {
case let .themeSettings(flags, baseTheme, accentColor, messageTopColor, messageBottomColor, wallpaper): case let .themeSettings(flags, baseTheme, accentColor, messageTopColor, messageBottomColor, wallpaper):
var messageColors: (Int32, Int32)? var messageColors: (UInt32, UInt32)?
if let messageTopColor = messageTopColor, let messageBottomColor = messageBottomColor { if let messageTopColor = messageTopColor, let messageBottomColor = messageBottomColor {
messageColors = (messageTopColor, messageBottomColor) messageColors = (UInt32(bitPattern: messageTopColor), UInt32(bitPattern: messageBottomColor))
} }
self.init(baseTheme: TelegramBaseTheme(apiBaseTheme: baseTheme) ?? .classic, accentColor: accentColor, messageColors: messageColors, wallpaper: wallpaper.flatMap(TelegramWallpaper.init(apiWallpaper:))) self.init(baseTheme: TelegramBaseTheme(apiBaseTheme: baseTheme) ?? .classic, accentColor: UInt32(bitPattern: accentColor), messageColors: messageColors, wallpaper: wallpaper.flatMap(TelegramWallpaper.init(apiWallpaper:)))
default: default:
return nil return nil
} }
@ -72,6 +72,15 @@ extension TelegramThemeSettings {
flags |= 1 << 1 flags |= 1 << 1
} }
return .inputThemeSettings(flags: flags, baseTheme: self.baseTheme.apiBaseTheme, accentColor: self.accentColor, messageTopColor: self.messageColors?.0, messageBottomColor: self.messageColors?.1, wallpaper: inputWallpaper, wallpaperSettings: inputWallpaperSettings) var messageTopColor: Int32?
var messageBottomColor: Int32?
if let color = self.messageColors?.0 {
messageTopColor = Int32(bitPattern: color)
}
if let color = self.messageColors?.1 {
messageBottomColor = Int32(bitPattern: color)
}
return .inputThemeSettings(flags: flags, baseTheme: self.baseTheme.apiBaseTheme, accentColor: Int32(bitPattern: self.accentColor), messageTopColor: messageTopColor, messageBottomColor: messageBottomColor, wallpaper: inputWallpaper, wallpaperSettings: inputWallpaperSettings)
} }
} }

View File

@ -535,7 +535,12 @@ final class UndoOverlayControllerNode: ViewControllerTracingNode {
self.checkTimer() self.checkTimer()
} }
var dismissed = false
func animateOut(completion: @escaping () -> Void) { func animateOut(completion: @escaping () -> Void) {
guard !self.dismissed else {
return
}
self.dismissed = true
self.panelNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.25, delay: 0.0, timingFunction: CAMediaTimingFunctionName.easeOut.rawValue, removeOnCompletion: false, completion: { _ in }) self.panelNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.25, delay: 0.0, timingFunction: CAMediaTimingFunctionName.easeOut.rawValue, removeOnCompletion: false, completion: { _ in })
self.panelWrapperNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.25, delay: 0.0, timingFunction: CAMediaTimingFunctionName.easeOut.rawValue, removeOnCompletion: false) { _ in self.panelWrapperNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.25, delay: 0.0, timingFunction: CAMediaTimingFunctionName.easeOut.rawValue, removeOnCompletion: false) { _ in
completion() completion()

View File

@ -527,7 +527,7 @@ public func patternColor(for color: UIColor, intensity: CGFloat, prominent: Bool
} else { } else {
brightness = max(0.0, min(1.0, 1.0 - brightness * 0.65)) brightness = max(0.0, min(1.0, 1.0 - brightness * 0.65))
} }
let alpha = (prominent ? 0.5 : 0.4) * intensity let alpha = (prominent ? 0.6 : 0.55) * intensity
return UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: alpha) return UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: alpha)
} }
return .black return .black