From e4a94cd32cfed887d1f17ca92a7eeebf5a0a7aae Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 3 Dec 2019 18:51:00 +0400 Subject: [PATCH] Fix theme colors issues --- submodules/Display/Display/TextNode.swift | 16 ++++--- .../Sources/LocationAnnotation.swift | 45 ++++++++++++++++++- .../Themes/ThemeAccentColorController.swift | 6 ++- .../Themes/WallpaperColorPanelNode.swift | 2 + .../Themes/WallpaperGalleryController.swift | 3 -- .../Sources/Themes/WallpaperGalleryItem.swift | 1 - .../ChatMessageBubbleItemNode.swift | 8 ++-- .../Sources/WallpaperResources.swift | 45 +++++++++++-------- 8 files changed, 90 insertions(+), 36 deletions(-) diff --git a/submodules/Display/Display/TextNode.swift b/submodules/Display/Display/TextNode.swift index f5a4c9f75f..deab790048 100644 --- a/submodules/Display/Display/TextNode.swift +++ b/submodules/Display/Display/TextNode.swift @@ -1054,13 +1054,15 @@ public class TextNode: ASDisplayNode { context.setShadow(offset: CGSize(width: 0.0, height: 1.0), blur: 0.0, color: textShadowColor.cgColor) } -// if let (textStrokeColor, textStrokeWidth) = layout.textStroke { -// context.setBlendMode(.normal) -// context.setLineCap(.round) -// context.setLineJoin(.round) -// context.setStrokeColor(textStrokeColor.cgColor) -// context.setLineWidth(textStrokeWidth) -// } + if let (textStrokeColor, textStrokeWidth) = layout.textStroke { + context.setBlendMode(.normal) + context.setLineCap(.round) + context.setLineJoin(.round) + context.setStrokeColor(textStrokeColor.cgColor) + context.setFillColor(textStrokeColor.cgColor) + context.setLineWidth(textStrokeWidth) + context.setTextDrawingMode(.fillStroke) + } let textMatrix = context.textMatrix let textPosition = context.textPosition diff --git a/submodules/LocationUI/Sources/LocationAnnotation.swift b/submodules/LocationUI/Sources/LocationAnnotation.swift index a4304c53c4..32d1d82596 100644 --- a/submodules/LocationUI/Sources/LocationAnnotation.swift +++ b/submodules/LocationUI/Sources/LocationAnnotation.swift @@ -80,6 +80,7 @@ class LocationPinAnnotationView: MKAnnotationView { let smallIconNode: TransformImageNode let dotNode: ASImageNode var avatarNode: AvatarNode? + var strokeLabelNode: ImmediateTextNode? var labelNode: ImmediateTextNode? var appeared = false @@ -236,14 +237,26 @@ class LocationPinAnnotationView: MKAnnotationView { self.dotNode.alpha = 1.0 self.dotNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) - if let annotation = self.annotation as? LocationPinAnnotation, let venue = annotation.location?.venue { var textColor = UIColor.black + var strokeTextColor = UIColor.white if #available(iOS 13.0, *) { if self.traitCollection.userInterfaceStyle == .dark { textColor = .white + strokeTextColor = .black } } + let strokeLabelNode = ImmediateTextNode() + strokeLabelNode.displaysAsynchronously = false + strokeLabelNode.isUserInteractionEnabled = false + strokeLabelNode.attributedText = NSAttributedString(string: venue.title, font: Font.medium(10), textColor: strokeTextColor) + strokeLabelNode.maximumNumberOfLines = 2 + strokeLabelNode.textAlignment = .center + strokeLabelNode.truncationType = .end + strokeLabelNode.textStroke = (strokeTextColor, 2.0 - UIScreenPixel) + self.strokeLabelNode = strokeLabelNode + self.addSubnode(strokeLabelNode) + let labelNode = ImmediateTextNode() labelNode.displaysAsynchronously = false labelNode.isUserInteractionEnabled = false @@ -251,7 +264,6 @@ class LocationPinAnnotationView: MKAnnotationView { labelNode.maximumNumberOfLines = 2 labelNode.textAlignment = .center labelNode.truncationType = .end - labelNode.textStroke = (UIColor.white, 1.0) self.labelNode = labelNode self.addSubnode(labelNode) @@ -260,8 +272,16 @@ class LocationPinAnnotationView: MKAnnotationView { labelNode.bounds = CGRect(origin: CGPoint(), size: size) labelNode.position = CGPoint(x: 0.0, y: 10.0 + floor(size.height / 2.0)) + var strokeSize = strokeLabelNode.updateLayout(CGSize(width: 120.0, height: CGFloat.greatestFiniteMagnitude)) + strokeSize.height += 2.0 + strokeLabelNode.bounds = CGRect(origin: CGPoint(), size: strokeSize) + strokeLabelNode.position = CGPoint(x: 0.0, y: 10.0 + floor(strokeSize.height / 2.0)) + + strokeLabelNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.3) labelNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.3) } else { + self.strokeLabelNode?.removeFromSupernode() + self.strokeLabelNode = nil self.labelNode?.removeFromSupernode() self.labelNode = nil } @@ -313,6 +333,13 @@ class LocationPinAnnotationView: MKAnnotationView { labelNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false, completion: { _ in labelNode.removeFromSupernode() }) + + if let strokeLabelNode = self.strokeLabelNode { + self.strokeLabelNode = nil + strokeLabelNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false, completion: { _ in + strokeLabelNode.removeFromSupernode() + }) + } } } } else { @@ -321,6 +348,13 @@ class LocationPinAnnotationView: MKAnnotationView { self.dotNode.alpha = selected ? 1.0 : 0.0 self.smallNode.alpha = 1.0 + if !selected { + self.labelNode?.removeFromSupernode() + self.labelNode = nil + self.strokeLabelNode?.removeFromSupernode() + self.strokeLabelNode = nil + } + self.layoutSubviews() } } @@ -346,13 +380,20 @@ class LocationPinAnnotationView: MKAnnotationView { if let labelNode = self.labelNode { var textColor = UIColor.black + var strokeTextColor = UIColor.white if #available(iOS 13.0, *) { if self.traitCollection.userInterfaceStyle == .dark { textColor = .white + strokeTextColor = .black } } labelNode.attributedText = NSAttributedString(string: labelNode.attributedText?.string ?? "", font: Font.medium(10), textColor: textColor) let _ = labelNode.updateLayout(CGSize(width: 120.0, height: CGFloat.greatestFiniteMagnitude)) + + if let strokeLabelNode = self.strokeLabelNode { + strokeLabelNode.attributedText = NSAttributedString(string: labelNode.attributedText?.string ?? "", font: Font.bold(10), textColor: strokeTextColor) + let _ = strokeLabelNode.updateLayout(CGSize(width: 120.0, height: CGFloat.greatestFiniteMagnitude)) + } } } diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift index d416afcb43..45b73ca51f 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift @@ -80,7 +80,11 @@ final class ThemeAccentColorController: ViewController { } } - self.navigationItem.titleView = self.segmentedTitleView + if case let .builtin(theme) = themeReference, theme != .dayClassic { + self.navigationItem.titleView = self.segmentedTitleView + } else { + self.title = self.presentationData.strings.Wallpaper_Title + } self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: UIView()) } diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift b/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift index 83dd15658c..968a945004 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift @@ -680,6 +680,8 @@ final class WallpaperColorPanelNode: ASDisplayNode { @objc private func addPressed() { self.colorSelected?() + self.firstColorFieldNode.setSkipEndEditingIfNeeded() + self.updateState({ current in var updated = current updated.selection = .second diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift index 8c2eec13af..c86eb3a1de 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift @@ -311,7 +311,6 @@ public class WallpaperGalleryController: ViewController { self.displayNode = WallpaperGalleryControllerNode(controllerInteraction: controllerInteraction, pageGap: 0.0) self.displayNodeDidLoad() - self.galleryNode.statusBar = self.statusBar self.galleryNode.navigationBar = self.navigationBar self.galleryNode.dismiss = { [weak self] in self?.presentingViewController?.dismiss(animated: false, completion: nil) @@ -608,8 +607,6 @@ public class WallpaperGalleryController: ViewController { currentWallpaper = wallpaper } - //let chatPresentationData = ChatPresentationData(theme: ChatPresentationThemeData(theme: self.presentationData.theme, wallpaper: currentWallpaper), fontSize: self.presentationData.fontSize, strings: self.presentationData.strings, dateTimeFormat: self.presentationData.dateTimeFormat, nameDisplayOrder: self.presentationData.nameDisplayOrder, disableAnimations: false, largeEmoji: false) - var topMessageText: String var bottomMessageText: String switch self.source { diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift index a923693a8e..658eff579b 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift @@ -240,7 +240,6 @@ final class WallpaperGalleryItemNode: GalleryItemNode { fetchSignal = .complete() statusSignal = .single(.Local) subtitleSignal = .single(nil) - actionSignal = .single(defaultAction) colorSignal = chatServiceBackgroundColor(wallpaper: wallpaper, mediaBox: self.context.account.postbox.mediaBox) isBlurrable = false case let .file(file): diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift index 30def13154..3902d1af6d 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift @@ -230,7 +230,7 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePrevewItemNode return } strongSelf.backgroundWallpaperNode.setMaskMode(strongSelf.backgroundMaskMode, mediaBox: item.context.account.postbox.mediaBox) - strongSelf.backgroundNode.setMaskMode(isExtractedToContextPreview) + strongSelf.backgroundNode.setMaskMode(strongSelf.backgroundMaskMode) if !isExtractedToContextPreview, let (rect, size) = strongSelf.absoluteRect { strongSelf.updateAbsoluteRect(rect, within: size) } @@ -1640,7 +1640,7 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePrevewItemNode } else { backgroundType = .incoming(mergeType) } - strongSelf.backgroundNode.setType(type: backgroundType, highlighted: strongSelf.highlightedState, graphics: graphics, maskMode: strongSelf.contextSourceNode.isExtractedToContextPreview, transition: transition) + strongSelf.backgroundNode.setType(type: backgroundType, highlighted: strongSelf.highlightedState, graphics: graphics, maskMode: strongSelf.backgroundMaskMode, transition: transition) strongSelf.backgroundWallpaperNode.setType(type: backgroundType, theme: item.presentationData.theme, mediaBox: item.context.account.postbox.mediaBox, essentialGraphics: graphics, maskMode: strongSelf.backgroundMaskMode) strongSelf.backgroundType = backgroundType @@ -2862,6 +2862,8 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePrevewItemNode } private var backgroundMaskMode: Bool { - return self.contextSourceNode.isExtractedToContextPreview || (self.item?.presentationData.theme.wallpaper.hasWallpaper ?? false) + let hasWallpaper = self.item?.presentationData.theme.wallpaper.hasWallpaper ?? false + let isPreview = self.item?.presentationData.isPreview ?? false + return self.contextSourceNode.isExtractedToContextPreview || hasWallpaper || isPreview } } diff --git a/submodules/WallpaperResources/Sources/WallpaperResources.swift b/submodules/WallpaperResources/Sources/WallpaperResources.swift index 109b62c33a..884836a0c8 100644 --- a/submodules/WallpaperResources/Sources/WallpaperResources.swift +++ b/submodules/WallpaperResources/Sources/WallpaperResources.swift @@ -504,7 +504,7 @@ public func gradientImage(_ colors: [UIColor]) -> Signal<(TransformImageArgument return .single({ arguments in let context = DrawingContext(size: arguments.drawingSize, clear: true) - context.withFlippedContext { c in + context.withContext { c in let gradientColors = colors.map { $0.cgColor } as CFArray let delta: CGFloat = 1.0 / (CGFloat(colors.count) - 1.0) @@ -1001,25 +1001,32 @@ public func themeIconImage(account: Account, accountManager: AccountManager, the let backgroundColor: UIColor let incomingColor: UIColor let outgoingColor: (UIColor, UIColor) + var accentColor = accentColor switch theme { - case .dayClassic: - backgroundColor = UIColor(rgb: 0xd6e2ee) - incomingColor = UIColor(rgb: 0xffffff) - outgoingColor = (UIColor(rgb: 0xe1ffc7), UIColor(rgb: 0xe1ffc7)) - case .day: - backgroundColor = UIColor(rgb: 0xffffff) - incomingColor = UIColor(rgb: 0xd5dde6) - outgoingColor = bubbleColors ?? (UIColor(rgb: 0x007aff), UIColor(rgb: 0x007aff)) - case .night: - backgroundColor = UIColor(rgb: 0x000000) - incomingColor = UIColor(rgb: 0x1f1f1f) - outgoingColor = bubbleColors ?? (UIColor(rgb: 0x313131), UIColor(rgb: 0x313131)) - case .nightAccent: - let accentColor = accentColor ?? UIColor(rgb: 0x007aff) - backgroundColor = accentColor.withMultiplied(hue: 1.024, saturation: 0.573, brightness: 0.18) - incomingColor = accentColor.withMultiplied(hue: 1.024, saturation: 0.585, brightness: 0.25) - let accentBubbleColor = accentColor.withMultiplied(hue: 1.019, saturation: 0.731, brightness: 0.59) - outgoingColor = bubbleColors ?? (accentBubbleColor, accentBubbleColor) + case .dayClassic: + backgroundColor = UIColor(rgb: 0xd6e2ee) + incomingColor = UIColor(rgb: 0xffffff) + outgoingColor = (UIColor(rgb: 0xe1ffc7), UIColor(rgb: 0xe1ffc7)) + case .day: + backgroundColor = UIColor(rgb: 0xffffff) + incomingColor = UIColor(rgb: 0xd5dde6) + if accentColor == nil { + accentColor = UIColor(rgb: 0x007aff) + } + outgoingColor = bubbleColors ?? (accentColor!, accentColor!) + case .night: + backgroundColor = UIColor(rgb: 0x000000) + incomingColor = UIColor(rgb: 0x1f1f1f) + if accentColor == nil { + accentColor = UIColor(rgb: 0x313131) + } + outgoingColor = bubbleColors ?? (accentColor!, accentColor!) + case .nightAccent: + let accentColor = accentColor ?? UIColor(rgb: 0x007aff) + backgroundColor = accentColor.withMultiplied(hue: 1.024, saturation: 0.573, brightness: 0.18) + incomingColor = accentColor.withMultiplied(hue: 1.024, saturation: 0.585, brightness: 0.25) + let accentBubbleColor = accentColor.withMultiplied(hue: 1.019, saturation: 0.731, brightness: 0.59) + outgoingColor = bubbleColors ?? (accentBubbleColor, accentBubbleColor) } colorsSignal = .single(((backgroundColor, nil), (incomingColor, incomingColor), outgoingColor, nil)) } else {