Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios

This commit is contained in:
Ilya Laktyushin 2021-05-29 14:35:23 +04:00
commit 78e3cbbd62
26 changed files with 159 additions and 182 deletions

View File

@ -38,7 +38,7 @@ open class GalleryControllerNode: ASDisplayNode, UIScrollViewDelegate, UIGesture
}
}
public init(controllerInteraction: GalleryControllerInteraction, pageGap: CGFloat = 20.0) {
public init(controllerInteraction: GalleryControllerInteraction, pageGap: CGFloat = 20.0, disableTapNavigation: Bool = false) {
self.backgroundNode = ASDisplayNode()
self.backgroundNode.backgroundColor = UIColor.black
self.scrollView = UIScrollView()
@ -48,7 +48,7 @@ open class GalleryControllerNode: ASDisplayNode, UIScrollViewDelegate, UIGesture
self.scrollView.contentInsetAdjustmentBehavior = .never
}
self.pager = GalleryPagerNode(pageGap: pageGap)
self.pager = GalleryPagerNode(pageGap: pageGap, disableTapNavigation: disableTapNavigation)
self.footerNode = GalleryFooterNode(controllerInteraction: controllerInteraction)
super.init()

View File

@ -78,6 +78,7 @@ public struct GalleryPagerTransaction {
public final class GalleryPagerNode: ASDisplayNode, UIScrollViewDelegate, UIGestureRecognizerDelegate {
private let pageGap: CGFloat
private let disableTapNavigation: Bool
private let scrollView: UIScrollView
@ -111,8 +112,10 @@ public final class GalleryPagerNode: ASDisplayNode, UIScrollViewDelegate, UIGest
public var completeCustomDismiss: () -> Void = { }
public var baseNavigationController: () -> NavigationController? = { return nil }
public init(pageGap: CGFloat) {
public init(pageGap: CGFloat, disableTapNavigation: Bool) {
self.pageGap = pageGap
self.disableTapNavigation = disableTapNavigation
self.scrollView = UIScrollView()
if #available(iOSApplicationExtension 11.0, iOS 11.0, *) {
self.scrollView.contentInsetAdjustmentBehavior = .never
@ -434,6 +437,9 @@ public final class GalleryPagerNode: ASDisplayNode, UIScrollViewDelegate, UIGest
}
private func canGoToPreviousItem() -> Bool {
if self.disableTapNavigation {
return false
}
if let index = self.centralItemIndex, index > 0 {
return true
} else {
@ -442,6 +448,9 @@ public final class GalleryPagerNode: ASDisplayNode, UIScrollViewDelegate, UIGest
}
private func canGoToNextItem() -> Bool {
if self.disableTapNavigation {
return false
}
if let index = self.centralItemIndex, index < self.items.count - 1 {
return true
} else {

View File

@ -3,6 +3,6 @@ import UIKit
import Display
import AsyncDisplayKit
public func createGradientBackgroundNode() -> GradientBackgroundNode {
return GradientBackgroundNode()
public func createGradientBackgroundNode(useSharedAnimationPhase: Bool = false) -> GradientBackgroundNode {
return GradientBackgroundNode(useSharedAnimationPhase: useSharedAnimationPhase)
}

View File

@ -180,15 +180,23 @@ public final class GradientBackgroundNode: ASDisplayNode {
private let cloneNodes = SparseBag<Weak<CloneNode>>()
override public init() {
private let useSharedAnimationPhase: Bool
static var sharedPhase: Int = 0
public init(useSharedAnimationPhase: Bool = false) {
self.useSharedAnimationPhase = useSharedAnimationPhase
self.contentView = UIImageView()
super.init()
self.view.addSubview(self.contentView)
if useSharedAnimationPhase {
self.phase = GradientBackgroundNode.sharedPhase
} else {
self.phase = 0
}
}
deinit {
}
@ -280,6 +288,9 @@ public final class GradientBackgroundNode: ASDisplayNode {
} else {
self.phase = self.phase - 1
}
if self.useSharedAnimationPhase {
GradientBackgroundNode.sharedPhase = self.phase
}
if let size = self.validLayout {
self.updateLayout(size: size, transition: transition)
}

View File

@ -147,34 +147,31 @@ public final class CachedPatternWallpaperMaskRepresentation: CachedMediaResource
public final class CachedPatternWallpaperRepresentation: CachedMediaResourceRepresentation {
public let keepDuration: CachedMediaRepresentationKeepDuration = .general
public let color: UInt32
public let bottomColor: UInt32?
public let colors: [UInt32]
public let intensity: Int32
public let rotation: Int32?
public var uniqueId: String {
var id: String
if let bottomColor = self.bottomColor {
id = "pattern-wallpaper-\(self.color)-\(bottomColor)-\(self.intensity)"
} else {
id = "pattern-wallpaper-\(self.color)-\(self.intensity)"
var id: String = "pattern-wallpaper"
for color in self.colors {
id.append("-\(color)")
}
id.append("-\(self.intensity)")
if let rotation = self.rotation, rotation != 0 {
id += "-\(rotation)deg"
}
return id
}
public init(color: UInt32, bottomColor: UInt32?, intensity: Int32, rotation: Int32?) {
self.color = color
self.bottomColor = bottomColor
public init(colors: [UInt32], intensity: Int32, rotation: Int32?) {
self.colors = colors
self.intensity = intensity
self.rotation = rotation
}
public func isEqual(to: CachedMediaResourceRepresentation) -> Bool {
if let to = to as? CachedPatternWallpaperRepresentation {
return self.color == to.color && self.bottomColor == to.bottomColor && self.intensity == intensity && self.rotation == to.rotation
return self.colors == to.colors && self.intensity == intensity && self.rotation == to.rotation
} else {
return false
}

View File

@ -514,7 +514,7 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
let prepare: Signal<CreateThemeResult, CreateThemeError>
if let resolvedWallpaper = resolvedWallpaper, case let .file(file) = resolvedWallpaper, resolvedWallpaper.isPattern {
let resource = file.file.resource
let representation = CachedPatternWallpaperRepresentation(color: file.settings.colors.count >= 1 ? file.settings.colors[0] : 0xd6e2ee, bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: file.settings.intensity ?? 50, rotation: file.settings.rotation)
let representation = CachedPatternWallpaperRepresentation(colors: file.settings.colors.count >= 1 ? file.settings.colors : [0xd6e2ee], intensity: file.settings.intensity ?? 50, rotation: file.settings.rotation)
var data: Data?
if let path = context.account.postbox.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {

View File

@ -69,10 +69,7 @@ final class ThemeAccentColorController: ViewController {
self.mode = mode
self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
var section: ThemeColorSection = .accent
if case .background = mode {
section = .background
}
var section: ThemeColorSection = .background
self.section = section
self.segmentedTitleView = ThemeColorSegmentedTitleView(theme: self.presentationData.theme, strings: self.presentationData.strings, selectedSection: section)
@ -173,7 +170,7 @@ final class ThemeAccentColorController: ViewController {
let prepareWallpaper: Signal<CreateThemeResult, CreateThemeError>
if let patternWallpaper = state.patternWallpaper, case let .file(file) = patternWallpaper, !state.backgroundColors.isEmpty {
let resource = file.file.resource
let representation = CachedPatternWallpaperRepresentation(color: state.backgroundColors.count >= 1 ? state.backgroundColors[0] : 0, bottomColor: state.backgroundColors.count >= 2 ? state.backgroundColors[1] : 0, intensity: state.patternIntensity, rotation: state.rotation)
let representation = CachedPatternWallpaperRepresentation(colors: state.backgroundColors.count >= 1 ? state.backgroundColors : [0], intensity: state.patternIntensity, rotation: state.rotation)
var data: Data?
if let path = strongSelf.context.account.postbox.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {
@ -455,12 +452,14 @@ final class ThemeAccentColorController: ViewController {
let themeSpecificAccentColor = settings.themeSpecificAccentColors[themeReference.index]
accentColor = themeSpecificAccentColor?.color ?? defaultDayAccentColor
var referenceTheme: PresentationTheme?
if let accentColor = themeSpecificAccentColor, let customWallpaper = settings.themeSpecificChatWallpapers[coloredThemeIndex(reference: themeReference, accentColor: accentColor)] {
wallpaper = customWallpaper
} else if let customWallpaper = settings.themeSpecificChatWallpapers[themeReference.index] {
wallpaper = customWallpaper
} else {
let theme = makePresentationTheme(mediaBox: strongSelf.context.sharedContext.accountManager.mediaBox, themeReference: themeReference, accentColor: themeSpecificAccentColor?.color, wallpaper: themeSpecificAccentColor?.wallpaper) ?? defaultPresentationTheme
referenceTheme = theme
wallpaper = theme.chat.defaultWallpaper
}
@ -485,6 +484,8 @@ final class ThemeAccentColorController: ViewController {
} else {
if let themeReference = strongSelf.mode.themeReference, themeReference == .builtin(.dayClassic), settings.themeSpecificAccentColors[themeReference.index] == nil {
messageColors = (UIColor(rgb: 0xe1ffc7), nil)
} else if let referenceTheme = referenceTheme {
messageColors = (referenceTheme.chat.message.outgoing.bubble.withoutWallpaper.fill, referenceTheme.chat.message.outgoing.bubble.withoutWallpaper.gradientFill)
} else {
messageColors = nil
}

View File

@ -30,8 +30,8 @@ private func generateMaskImage(color: UIColor) -> UIImage? {
}
enum ThemeColorSection: Int {
case accent
case background
case accent
case messages
}

View File

@ -31,7 +31,7 @@ final class ThemeColorSegmentedTitleView: UIView {
init(theme: PresentationTheme, strings: PresentationStrings, selectedSection: ThemeColorSection) {
self.theme = theme
let sections = [strings.Theme_Colors_Accent, strings.Theme_Colors_Background, strings.Theme_Colors_Messages]
let sections = [strings.Theme_Colors_Background, strings.Theme_Colors_Accent, strings.Theme_Colors_Messages]
self.segmentedControlNode = SegmentedControlNode(theme: SegmentedControlTheme(theme: theme), items: sections.map { SegmentedControlItem(title: $0) }, selectedIndex: selectedSection.rawValue)
super.init(frame: CGRect())

View File

@ -1240,7 +1240,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
|> mapToSignal { cachedWallpaper in
if let wallpaper = cachedWallpaper?.wallpaper, case let .file(file) = wallpaper {
let resource = file.file.resource
let representation = CachedPatternWallpaperRepresentation(color: file.settings.colors.count >= 1 ? file.settings.colors[0] : 0xd6e2ee, bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : 0xd6e2ee, intensity: file.settings.intensity ?? 50, rotation: file.settings.rotation)
let representation = CachedPatternWallpaperRepresentation(colors: file.settings.colors.count >= 1 ? file.settings.colors : [0xd6e2ee], intensity: file.settings.intensity ?? 50, rotation: file.settings.rotation)
let _ = fetchedMediaResource(mediaBox: context.account.postbox.mediaBox, reference: .wallpaper(wallpaper: .slug(file.slug), resource: file.file.resource)).start()

View File

@ -479,95 +479,6 @@ final class WallpaperColorPanelNode: ASDisplayNode {
}, animated: strongSelf.state.colors.count >= 2)
}
}
/*self.multiColorFieldNode.colorSelected = { [weak self] in
if let strongSelf = self {
strongSelf.secondColorFieldNode.setSkipEndEditingIfNeeded()
strongSelf.updateState({ current in
var updated = current
if updated.selection != .none {
updated.selection = .index(0)
}
return updated
})
strongSelf.colorSelected?()
}
}*/
/*self.firstColorFieldNode.colorChanged = { [weak self] color, ended in
if let strongSelf = self {
strongSelf.updateState({ current in
var updated = current
updated.firstColor = color
return updated
})
}
}
self.firstColorFieldNode.colorRemoved = { [weak self] in
if let strongSelf = self {
strongSelf.colorRemoved?()
strongSelf.updateState({ current in
var updated = current
updated.selection = .index(0)
if let defaultColor = current.defaultColor, updated.secondColor == nil {
updated.firstColor = nil
} else {
updated.firstColor = updated.secondColor ?? updated.firstColor
}
updated.secondColor = nil
return updated
}, animated: strongSelf.state.secondColor != nil)
}
}
self.firstColorFieldNode.colorSelected = { [weak self] in
if let strongSelf = self {
strongSelf.secondColorFieldNode.setSkipEndEditingIfNeeded()
strongSelf.updateState({ current in
var updated = current
if updated.selection != .none {
updated.selection = .index(0)
}
return updated
})
strongSelf.colorSelected?()
}
}
self.secondColorFieldNode.colorChanged = { [weak self] color, ended in
if let strongSelf = self {
strongSelf.updateState({ current in
var updated = current
updated.secondColor = color
return updated
})
}
}
self.secondColorFieldNode.colorRemoved = { [weak self] in
if let strongSelf = self {
strongSelf.colorRemoved?()
strongSelf.updateState({ current in
var updated = current
if updated.selection != .none {
updated.selection = .index(0)
}
updated.secondColor = nil
return updated
})
}
}
self.secondColorFieldNode.colorSelected = { [weak self] in
if let strongSelf = self {
strongSelf.firstColorFieldNode.setSkipEndEditingIfNeeded()
strongSelf.updateState({ current in
var updated = current
updated.selection = .index(1)
return updated
})
strongSelf.colorSelected?()
}
}*/
self.colorPickerNode.colorChanged = { [weak self] color in
if let strongSelf = self {

View File

@ -238,6 +238,7 @@ final class WallpaperColorPickerNode: ASDisplayNode {
self.brightnessNode.hitTestSlop = UIEdgeInsets(top: -16.0, left: -16.0, bottom: -16.0, right: -16.0)
self.brightnessKnobNode = ASImageNode()
self.brightnessKnobNode.image = pointerImage
self.brightnessKnobNode.isUserInteractionEnabled = false
self.colorNode = WallpaperColorHueSaturationNode()
self.colorNode.hitTestSlop = UIEdgeInsets(top: -16.0, left: -16.0, bottom: -16.0, right: -16.0)
self.colorKnobNode = WallpaperColorKnobNode()

View File

@ -360,7 +360,7 @@ public class WallpaperGalleryController: ViewController {
}, replaceRootController: { controller, ready in
}, editMedia: { _ in
})
self.displayNode = WallpaperGalleryControllerNode(controllerInteraction: controllerInteraction, pageGap: 0.0)
self.displayNode = WallpaperGalleryControllerNode(controllerInteraction: controllerInteraction, pageGap: 0.0, disableTapNavigation: true)
self.displayNodeDidLoad()
(self.displayNode as? WallpaperGalleryControllerNode)?.nativeStatusBar = self.statusBar
@ -370,9 +370,12 @@ public class WallpaperGalleryController: ViewController {
self?.presentingViewController?.dismiss(animated: false, completion: nil)
}
var currentCentralItemIndex: Int?
self.galleryNode.pager.centralItemIndexUpdated = { [weak self] index in
if let strongSelf = self {
strongSelf.bindCentralItemNode(animated: true)
let updated = currentCentralItemIndex != index
currentCentralItemIndex = index
strongSelf.bindCentralItemNode(animated: true, updated: updated)
}
}
@ -498,7 +501,7 @@ public class WallpaperGalleryController: ViewController {
}
} else if case let .file(file) = wallpaper, let resource = resource {
if wallpaper.isPattern, !file.settings.colors.isEmpty, let intensity = file.settings.intensity {
let representation = CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation)
let representation = CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation)
var data: Data?
if let path = strongSelf.context.account.postbox.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {
@ -585,10 +588,10 @@ public class WallpaperGalleryController: ViewController {
super.viewDidAppear(animated)
self.galleryNode.modalAnimateIn()
self.bindCentralItemNode(animated: false)
self.bindCentralItemNode(animated: false, updated: false)
}
private func bindCentralItemNode(animated: Bool) {
private func bindCentralItemNode(animated: Bool, updated: Bool) {
if let node = self.galleryNode.pager.centralItemNode() as? WallpaperGalleryItemNode {
self.centralItemSubtitle.set(node.subtitle.get())
self.centralItemStatus.set(node.status.get())
@ -599,6 +602,7 @@ public class WallpaperGalleryController: ViewController {
node.requestPatternPanel = { [weak self] enabled, initialWallpaper in
if let strongSelf = self, let (layout, _) = strongSelf.validLayout {
strongSelf.colorsPanelEnabled = false
strongSelf.colorsPanelNode?.view.endEditing(true)
strongSelf.patternInitialWallpaper = enabled ? initialWallpaper : nil
switch initialWallpaper {
@ -637,12 +641,13 @@ public class WallpaperGalleryController: ViewController {
}
}
node.requestColorsPanel = { [weak self] colors in
if let strongSelf = self, let (layout, _) = strongSelf.validLayout {
node.toggleColorsPanel = { [weak self] colors in
if let strongSelf = self, let (layout, _) = strongSelf.validLayout, let colors = colors, let itemNode = strongSelf.galleryNode.pager.centralItemNode() as? WallpaperGalleryItemNode {
strongSelf.patternPanelEnabled = false
strongSelf.colorsPanelEnabled = colors != nil
strongSelf.galleryNode.scrollView.isScrollEnabled = colors == nil
if let colors = colors {
strongSelf.colorsPanelEnabled = !strongSelf.colorsPanelEnabled
strongSelf.galleryNode.scrollView.isScrollEnabled = !strongSelf.colorsPanelEnabled
if strongSelf.colorsPanelEnabled {
strongSelf.colorsPanelNode?.updateState({ _ in
return WallpaperColorPanelNodeState(
selection: 0,
@ -654,9 +659,10 @@ public class WallpaperGalleryController: ViewController {
simpleGradientGeneration: false
)
}, animated: false)
} else {
//strongSelf.updateEntries(pattern: .color(0), preview: false)
}
itemNode.updateIsColorsPanelActive(strongSelf.colorsPanelEnabled, animated: true)
strongSelf.containerLayoutUpdated(layout, transition: .animated(duration: 0.3, curve: .spring))
}
}
@ -671,14 +677,25 @@ public class WallpaperGalleryController: ViewController {
}
if let entry = self.currentEntry(), case let .wallpaper(wallpaper, _) = entry, case let .file(_, _, _, _, true, _, _, _ , settings) = wallpaper, !settings.colors.isEmpty {
if self.patternPanelNode?.backgroundColors != nil, let snapshotView = self.patternPanelNode?.scrollNode.view.snapshotContentTree() {
/*if self.patternPanelNode?.backgroundColors != nil, let snapshotView = self.patternPanelNode?.scrollNode.view.snapshotContentTree() {
self.patternPanelNode?.view.addSubview(snapshotView)
snapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false) { [weak snapshotView] _ in
snapshotView?.removeFromSuperview()
}
}
}*/
//self.patternPanelNode?.backgroundColors = ([settings.colors[0]], nil)
}
if updated {
if self.colorsPanelEnabled || self.patternPanelEnabled {
self.colorsPanelEnabled = false
self.patternPanelEnabled = false
if let (layout, _) = self.validLayout {
self.containerLayoutUpdated(layout, transition: .animated(duration: 0.3, curve: .spring))
}
}
}
}
}

View File

@ -101,6 +101,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
private var patternButtonNode: WallpaperOptionButtonNode
private var colorsButtonNode: WallpaperOptionButtonNode
private var playButtonNode: HighlightableButtonNode
private let playButtonBackgroundNode: NavigationBackgroundNode
private let messagesContainerNode: ASDisplayNode
private var messageNodes: [ListViewItemNode]?
@ -115,7 +116,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
let actionButton = Promise<UIBarButtonItem?>(nil)
var action: (() -> Void)?
var requestPatternPanel: ((Bool, TelegramWallpaper) -> Void)?
var requestColorsPanel: (([UIColor]?) -> Void)?
var toggleColorsPanel: (([UIColor]?) -> Void)?
var requestRotateGradient: ((Int32) -> Void)?
private var validLayout: (ContainerViewLayout, CGFloat)?
@ -153,7 +154,9 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
self.patternButtonNode.setEnabled(false)
self.colorsButtonNode = WallpaperOptionButtonNode(title: self.presentationData.strings.WallpaperPreview_WallpaperColors, value: .colors(false, [.clear]))
self.playButtonBackgroundNode = NavigationBackgroundNode(color: UIColor(white: 0.0, alpha: 0.3))
self.playButtonNode = HighlightableButtonNode()
self.playButtonNode.insertSubnode(self.playButtonBackgroundNode, at: 0)
self.playButtonPlayImage = generateImage(CGSize(width: 48.0, height: 48.0), rotatedContext: { size, context in
context.clear(CGRect(origin: CGPoint(), size: size))
@ -284,9 +287,10 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
switch entry {
case let .wallpaper(wallpaper, _):
self.nativeNode.update(wallpaper: wallpaper)
if case let .file(_, _, _, _, isPattern, _, _, _, settings) = wallpaper, isPattern {
self.nativeNode.isHidden = false
self.nativeNode.update(wallpaper: wallpaper)
self.patternButtonNode.isSelected = isPattern
if isPattern && settings.colors.count >= 3 {
@ -438,7 +442,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
} else {
subtitleSignal = .single(nil)
}
if file.id == 0 {
if file.slug.isEmpty {
actionSignal = .single(nil)
} else {
actionSignal = .single(defaultAction)
@ -625,17 +629,17 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
strongSelf.motionButtonNode.buttonColor = color
strongSelf.colorsButtonNode.buttonColor = color
strongSelf.playButtonNode.setBackgroundImage(generateFilledCircleImage(diameter: 48.0, color: color), for: [])
strongSelf.playButtonBackgroundNode.color = color
}))
} else if self.arguments.patternEnabled != previousArguments.patternEnabled {
self.patternButtonNode.isSelected = self.arguments.patternEnabled
}
if let (layout, _) = self.validLayout {
self.updateButtonsLayout(layout: layout, offset: CGPoint(), transition: .immediate)
self.updateMessagesLayout(layout: layout, offset: CGPoint(), transition: .immediate)
}
}
}
override func screenFrameUpdated(_ frame: CGRect) {
let offset = -frame.minX
@ -685,6 +689,10 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
return self.calculateGradientColors()?.map({ $0.rgb })
}
func updateIsColorsPanelActive(_ value: Bool, animated: Bool) {
self.colorsButtonNode.setSelected(value, animated: false)
}
@objc func toggleBlur() {
let value = !self.blurButtonNode.isSelected
self.blurButtonNode.setSelected(value, animated: true)
@ -795,10 +803,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
guard let currentGradientColors = self.calculateGradientColors() else {
return
}
let value = !self.colorsButtonNode.isSelected
self.colorsButtonNode.setSelected(value, animated: false)
self.requestColorsPanel?(value ? currentGradientColors : nil)
self.toggleColorsPanel?(currentGradientColors)
}
@objc private func togglePlay() {
@ -949,9 +954,8 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
motionAlpha = 0.0
patternAlpha = 1.0
patternFrame = leftButtonFrame.offsetBy(dx: -centerOffset, dy: 0.0)
colorsFrame = colorsFrame.offsetBy(dx: centerOffset, dy: 0.0)
playAlpha = 1.0
patternFrame = leftButtonFrame
playAlpha = 0.0
colorsAlpha = 1.0
case .image:
@ -959,13 +963,18 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
blurFrame = leftButtonFrame
motionAlpha = 1.0
motionFrame = rightButtonFrame
case .gradient:
case let .gradient(colors, _):
motionAlpha = 0.0
patternAlpha = 1.0
if colors.count >= 2 {
playAlpha = 1.0
patternFrame = leftButtonFrame.offsetBy(dx: -centerOffset, dy: 0.0)
colorsFrame = colorsFrame.offsetBy(dx: centerOffset, dy: 0.0)
playAlpha = 1.0
} else {
playAlpha = 0.0
patternFrame = leftButtonFrame
}
colorsAlpha = 1.0
case let .file(file):
@ -973,9 +982,14 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
motionAlpha = 0.0
patternAlpha = 1.0
if file.settings.colors.count >= 2 {
playAlpha = 1.0
patternFrame = leftButtonFrame.offsetBy(dx: -centerOffset, dy: 0.0)
colorsFrame = colorsFrame.offsetBy(dx: centerOffset, dy: 0.0)
playAlpha = 1.0
} else {
playAlpha = 0.0
patternFrame = leftButtonFrame
}
colorsAlpha = 1.0
} else {
@ -1012,6 +1026,8 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
transition.updateAlpha(node: self.colorsButtonNode, alpha: colorsAlpha * alpha)
transition.updateFrame(node: self.playButtonNode, frame: playFrame)
transition.updateFrame(node: self.playButtonBackgroundNode, frame: CGRect(origin: CGPoint(), size: playFrame.size))
self.playButtonBackgroundNode.update(size: playFrame.size, cornerRadius: playFrame.size.height / 2.0, transition: transition)
transition.updateAlpha(node: self.playButtonNode, alpha: playAlpha * alpha)
transition.updateSublayerTransformScale(node: self.playButtonNode, scale: max(0.1, playAlpha))
}

View File

@ -35,7 +35,7 @@ private func generateColorsImage(diameter: CGFloat, colors: [UIColor]) -> UIImag
}
final class WallpaperOptionButtonNode: HighlightTrackingButtonNode {
private let backgroundNode: ASDisplayNode
private let backgroundNode: NavigationBackgroundNode
private let checkNode: CheckNode
private let colorNode: ASImageNode
private let textNode: ASTextNode
@ -66,8 +66,7 @@ final class WallpaperOptionButtonNode: HighlightTrackingButtonNode {
init(title: String, value: WallpaperOptionButtonValue) {
self._value = value
self.backgroundNode = ASDisplayNode()
self.backgroundNode.backgroundColor = UIColor(rgb: 0x000000, alpha: 0.3)
self.backgroundNode = NavigationBackgroundNode(color: UIColor(rgb: 0x000000, alpha: 0.3))
self.backgroundNode.cornerRadius = 14.0
self.checkNode = CheckNode(theme: CheckNodeTheme(backgroundColor: .white, strokeColor: .clear, borderColor: .white, overlayBorder: false, hasInset: false, hasShadow: false, borderWidth: 1.5))
@ -133,7 +132,7 @@ final class WallpaperOptionButtonNode: HighlightTrackingButtonNode {
var buttonColor: UIColor = UIColor(rgb: 0x000000, alpha: 0.3) {
didSet {
self.backgroundNode.backgroundColor = self.buttonColor
self.backgroundNode.color = self.buttonColor
}
}
@ -224,8 +223,9 @@ final class WallpaperOptionButtonNode: HighlightTrackingButtonNode {
super.layout()
self.backgroundNode.frame = self.bounds
self.backgroundNode.update(size: self.backgroundNode.bounds.size, cornerRadius: 15.0, transition: .immediate)
guard let textSize = self.textSize else {
guard let _ = self.textSize else {
return
}

View File

@ -75,7 +75,7 @@ public func chatControllerBackgroundImage(theme: PresentationTheme?, wallpaper i
case let .file(file):
if wallpaper.isPattern, !file.settings.colors.isEmpty, let intensity = file.settings.intensity {
var image: UIImage?
let _ = mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: true).start(next: { data in
let _ = mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: true).start(next: { data in
if data.complete {
image = UIImage(contentsOfFile: data.path)?.precomposed()
}
@ -175,7 +175,7 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
}
case let .file(file):
if wallpaper.isPattern, !file.settings.colors.isEmpty, let intensity = file.settings.intensity {
let representation = CachedPatternWallpaperRepresentation(color: file.settings.colors.count >= 1 ? file.settings.colors[0] : 0, bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : 0, intensity: intensity, rotation: file.settings.rotation)
let representation = CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation)
let effectiveMediaBox: MediaBox
if FileManager.default.fileExists(atPath: mediaBox.cachedRepresentationCompletePath(file.file.resource.id, representation: representation)) {
@ -214,7 +214,7 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
}
})
return .single((interrimImage, false)) |> then(effectiveMediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 1 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: false)
return .single((interrimImage, false)) |> then(effectiveMediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: false)
|> map { data -> (UIImage?, Bool)? in
return (UIImage(contentsOfFile: data.path)?.precomposed(), true)
})

View File

@ -432,7 +432,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
self.botStart = botStart
self.peekData = peekData
self.chatBackgroundNode = WallpaperBackgroundNode(context: context)
self.chatBackgroundNode = WallpaperBackgroundNode(context: context, useSharedAnimationPhase: true)
var locationBroadcastPanelSource: LocationBroadcastPanelSource
var groupCallPanelSource: GroupCallPanelSource

View File

@ -1610,6 +1610,8 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
}
self.updatePlainInputSeparator(transition: .immediate)
self.inputPanelBackgroundSeparatorNode.backgroundColor = self.chatPresentationInterfaceState.theme.chat.inputPanel.panelSeparatorColor
self.backgroundNode.updateBubbleTheme(bubbleTheme: chatPresentationInterfaceState.theme, bubbleCorners: chatPresentationInterfaceState.bubbleCorners)
}
let keepSendButtonEnabled = chatPresentationInterfaceState.interfaceState.forwardMessageIds != nil || chatPresentationInterfaceState.interfaceState.editMessage != nil

View File

@ -101,7 +101,7 @@ final class ChatMessageBubbleBackdrop: ASDisplayNode {
let maskMode = self.fixedMaskMode ?? inputMaskMode
if self.currentType != type || self.theme != theme || self.currentMaskMode != maskMode || self.essentialGraphics !== essentialGraphics || self.backgroundNode !== backgroundNode {
let typeUpdated = self.currentType != type
let typeUpdated = self.currentType != type || self.theme != theme || self.currentMaskMode != maskMode || self.backgroundNode !== backgroundNode
self.currentType = type
self.theme = theme

View File

@ -2211,6 +2211,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
backgroundView.frame = self.textInputBackgroundNode.frame
func updateIsCaretHidden(view: UIView, isHidden: Bool) {
return;
if String(describing: type(of: view)).contains("TextSelectionView") {
view.isHidden = isHidden
} else {

View File

@ -19,6 +19,7 @@ import WallpaperResources
import Svg
import GZip
import TelegramUniversalVideoContent
import GradientBackground
public func fetchCachedResourceRepresentation(account: Account, resource: MediaResource, representation: CachedMediaResourceRepresentation) -> Signal<CachedMediaResourceRepresentationResult, NoError> {
if let representation = representation as? CachedStickerAJpegRepresentation {
@ -480,11 +481,7 @@ private func fetchCachedPatternWallpaperRepresentation(resource: MediaResource,
let path = NSTemporaryDirectory() + "\(Int64.random(in: Int64.min ... Int64.max))"
let url = URL(fileURLWithPath: path)
var colors: [UIColor] = []
if let bottomColor = representation.bottomColor {
colors.append(UIColor(rgb: bottomColor))
}
colors.append(UIColor(rgb: representation.color))
let colors: [UIColor] = representation.colors.map(UIColor.init(rgb:))
let intensity = CGFloat(representation.intensity) / 100.0
@ -510,6 +507,16 @@ private func fetchCachedPatternWallpaperRepresentation(resource: MediaResource,
if colors.count == 1, let color = colors.first {
c.setFillColor(color.cgColor)
c.fill(rect)
} else if colors.count >= 3 {
let drawingRect = rect
let image = GradientBackgroundNode.generatePreview(size: CGSize(width: 60.0, height: 60.0), colors: colors)
c.translateBy(x: drawingRect.midX, y: drawingRect.midY)
c.scaleBy(x: 1.0, y: -1.0)
c.translateBy(x: -drawingRect.midX, y: -drawingRect.midY)
c.draw(image.cgImage!, in: drawingRect)
c.translateBy(x: drawingRect.midX, y: drawingRect.midY)
c.scaleBy(x: 1.0, y: -1.0)
c.translateBy(x: -drawingRect.midX, y: -drawingRect.midY)
} else {
let gradientColors = colors.map { $0.cgColor } as CFArray
let delta: CGFloat = 1.0 / (CGFloat(colors.count) - 1.0)
@ -535,6 +542,10 @@ private func fetchCachedPatternWallpaperRepresentation(resource: MediaResource,
c.clip(to: rect, mask: cgImage)
}
if colors.count >= 3 {
c.setBlendMode(.softLight)
}
if colors.count == 1, let color = colors.first {
c.setFillColor(patternColor(for: color, intensity: intensity).cgColor)
c.fill(rect)

View File

@ -167,7 +167,7 @@ public func upgradedAccounts(accountManager: AccountManager, rootPath: String, e
let _ = accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: true, fetch: true).start()
if wallpaper.isPattern {
if !file.settings.colors.isEmpty, let intensity = file.settings.intensity {
let _ = accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true).start()
let _ = accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true).start()
}
} else {
if file.settings.blur {

@ -1 +1 @@
Subproject commit 66671a2df214183f36400c34eabb3e7ecd9fe275
Subproject commit c918c50087466adf5fdca47f2f62de58eccf514b

View File

@ -178,6 +178,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
}
private let context: AccountContext
private let useSharedAnimationPhase: Bool
private let contentNode: ASDisplayNode
private var gradientBackgroundNode: GradientBackgroundNode?
@ -245,8 +246,9 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
}
}
public init(context: AccountContext) {
public init(context: AccountContext, useSharedAnimationPhase: Bool = false) {
self.context = context
self.useSharedAnimationPhase = useSharedAnimationPhase
self.imageContentMode = .scaleAspectFill
self.contentNode = ASDisplayNode()
@ -289,7 +291,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
if gradientColors.count >= 3 {
if self.gradientBackgroundNode == nil {
let gradientBackgroundNode = createGradientBackgroundNode()
let gradientBackgroundNode = createGradientBackgroundNode(useSharedAnimationPhase: self.useSharedAnimationPhase)
self.gradientBackgroundNode = gradientBackgroundNode
self.insertSubnode(gradientBackgroundNode, aboveSubnode: self.contentNode)
gradientBackgroundNode.addSubnode(self.patternImageNode)

View File

@ -810,10 +810,8 @@ public func drawThemeImage(context c: CGContext, theme: PresentationTheme, wallp
let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)!
c.drawLinearGradient(gradient, start: CGPoint(x: 0.0, y: drawingRect.height), end: CGPoint(x: 0.0, y: 0.0), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation])
}
case .file:
case let .file(file):
c.setFillColor(theme.chatList.backgroundColor.cgColor)
c.fill(drawingRect)
if let image = wallpaperImage, let cgImage = image.cgImage {
let size = image.size.aspectFilled(drawingRect.size)
c.draw(cgImage, in: CGRect(origin: CGPoint(x: (drawingRect.size.width - size.width) / 2.0, y: (drawingRect.size.height - size.height) / 2.0), size: size))
@ -1026,7 +1024,7 @@ public func themeImage(account: Account, accountManager: AccountManager, source:
let _ = accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: true, fetch: true).start()
if wallpaper.wallpaper.isPattern, !file.settings.colors.isEmpty, let intensity = file.settings.intensity {
return accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true)
return accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true)
|> mapToSignal { data in
if data.complete, let data = try? Data(contentsOf: URL(fileURLWithPath: data.path)), let image = UIImage(data: data) {
return .single((theme, image, thumbnailData))
@ -1325,7 +1323,7 @@ public func themeIconImage(account: Account, accountManager: AccountManager, the
if wallpaper.wallpaper.isPattern {
if !file.settings.colors.isEmpty, let intensity = file.settings.intensity {
return accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true)
return accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true)
|> mapToSignal { _ in
return .single((effectiveBackgroundColor, incomingColor, outgoingColor, nil, rotation))
}

View File

@ -9,8 +9,8 @@ config_setting(
)
optimization_flags = select({
":debug_build": ["-Os"],
"//conditions:default": [],
":debug_build": ["-Os", "-DNDEBUG"],
"//conditions:default": ["-DNDEBUG"],
})
rnnoise_sources = [ "dependencies/third_party/rnnoise/src/" + x for x in [