mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Various theme editing fixes
This commit is contained in:
parent
b4dbb9698b
commit
3fd9c0aa5f
@ -232,7 +232,7 @@ public final class GradientBackgroundNode: ASDisplayNode {
|
|||||||
if let current = self._dimmedImage {
|
if let current = self._dimmedImage {
|
||||||
return current
|
return current
|
||||||
} else if let (size, colors, positions) = self.dimmedImageParams {
|
} else if let (size, colors, positions) = self.dimmedImageParams {
|
||||||
self._dimmedImage = generateGradient(size: size, colors: colors, positions: positions, adjustSaturation: 1.7)
|
self._dimmedImage = generateGradient(size: size, colors: colors, positions: positions, adjustSaturation: self.saturation)
|
||||||
return self._dimmedImage
|
return self._dimmedImage
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
@ -245,8 +245,11 @@ public final class GradientBackgroundNode: ASDisplayNode {
|
|||||||
private let useSharedAnimationPhase: Bool
|
private let useSharedAnimationPhase: Bool
|
||||||
static var sharedPhase: Int = 0
|
static var sharedPhase: Int = 0
|
||||||
|
|
||||||
public init(colors: [UIColor]? = nil, useSharedAnimationPhase: Bool = false) {
|
private let saturation: CGFloat
|
||||||
|
|
||||||
|
public init(colors: [UIColor]? = nil, useSharedAnimationPhase: Bool = false, adjustSaturation: Bool = true) {
|
||||||
self.useSharedAnimationPhase = useSharedAnimationPhase
|
self.useSharedAnimationPhase = useSharedAnimationPhase
|
||||||
|
self.saturation = adjustSaturation ? 1.7 : 1.0
|
||||||
self.contentView = UIImageView()
|
self.contentView = UIImageView()
|
||||||
let defaultColors: [UIColor] = [
|
let defaultColors: [UIColor] = [
|
||||||
UIColor(rgb: 0x7FA381),
|
UIColor(rgb: 0x7FA381),
|
||||||
@ -345,7 +348,7 @@ public final class GradientBackgroundNode: ASDisplayNode {
|
|||||||
|
|
||||||
images.append(generateGradient(size: imageSize, colors: self.colors, positions: morphedPositions))
|
images.append(generateGradient(size: imageSize, colors: self.colors, positions: morphedPositions))
|
||||||
if needDimmedImages {
|
if needDimmedImages {
|
||||||
dimmedImages.append(generateGradient(size: imageSize, colors: self.colors, positions: morphedPositions, adjustSaturation: 1.7))
|
dimmedImages.append(generateGradient(size: imageSize, colors: self.colors, positions: morphedPositions, adjustSaturation: self.saturation))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,7 +396,7 @@ public final class GradientBackgroundNode: ASDisplayNode {
|
|||||||
let image = generateGradient(size: imageSize, colors: self.colors, positions: positions)
|
let image = generateGradient(size: imageSize, colors: self.colors, positions: positions)
|
||||||
self.contentView.image = image
|
self.contentView.image = image
|
||||||
|
|
||||||
let dimmedImage = generateGradient(size: imageSize, colors: self.colors, positions: positions, adjustSaturation: 1.7)
|
let dimmedImage = generateGradient(size: imageSize, colors: self.colors, positions: positions, adjustSaturation: self.saturation)
|
||||||
self._dimmedImage = dimmedImage
|
self._dimmedImage = dimmedImage
|
||||||
self.dimmedImageParams = (imageSize, self.colors, positions)
|
self.dimmedImageParams = (imageSize, self.colors, positions)
|
||||||
|
|
||||||
@ -406,7 +409,7 @@ public final class GradientBackgroundNode: ASDisplayNode {
|
|||||||
let image = generateGradient(size: imageSize, colors: self.colors, positions: positions)
|
let image = generateGradient(size: imageSize, colors: self.colors, positions: positions)
|
||||||
self.contentView.image = image
|
self.contentView.image = image
|
||||||
|
|
||||||
let dimmedImage = generateGradient(size: imageSize, colors: self.colors, positions: positions, adjustSaturation: 1.7)
|
let dimmedImage = generateGradient(size: imageSize, colors: self.colors, positions: positions, adjustSaturation: self.saturation)
|
||||||
self.dimmedImageParams = (imageSize, self.colors, positions)
|
self.dimmedImageParams = (imageSize, self.colors, positions)
|
||||||
|
|
||||||
for cloneNode in self.cloneNodes {
|
for cloneNode in self.cloneNodes {
|
||||||
|
@ -268,6 +268,7 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
|
|||||||
let previewThemePromise = Promise<PresentationTheme>()
|
let previewThemePromise = Promise<PresentationTheme>()
|
||||||
let settingsPromise = Promise<TelegramThemeSettings?>(nil)
|
let settingsPromise = Promise<TelegramThemeSettings?>(nil)
|
||||||
let hasSettings: Bool
|
let hasSettings: Bool
|
||||||
|
let mayHaveSettings: Bool
|
||||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||||
switch mode {
|
switch mode {
|
||||||
case let .create(existingTheme, settings):
|
case let .create(existingTheme, settings):
|
||||||
@ -278,16 +279,19 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
|
|||||||
wallpaper = theme.chat.defaultWallpaper
|
wallpaper = theme.chat.defaultWallpaper
|
||||||
settingsPromise.set(.single(settings))
|
settingsPromise.set(.single(settings))
|
||||||
hasSettings = settings != nil
|
hasSettings = settings != nil
|
||||||
|
mayHaveSettings = settings != nil
|
||||||
} else {
|
} else {
|
||||||
theme = presentationData.theme
|
theme = presentationData.theme
|
||||||
wallpaper = presentationData.chatWallpaper
|
wallpaper = presentationData.chatWallpaper
|
||||||
settingsPromise.set(.single(nil))
|
settingsPromise.set(.single(nil))
|
||||||
hasSettings = false
|
hasSettings = false
|
||||||
|
mayHaveSettings = true
|
||||||
}
|
}
|
||||||
initialState = EditThemeControllerState(mode: mode, title: generateThemeName(accentColor: theme.rootController.navigationBar.buttonColor), slug: "", updatedTheme: nil, updating: false)
|
initialState = EditThemeControllerState(mode: mode, title: generateThemeName(accentColor: theme.rootController.navigationBar.buttonColor), slug: "", updatedTheme: nil, updating: false)
|
||||||
previewThemePromise.set(.single(theme.withUpdated(name: "", defaultWallpaper: wallpaper)))
|
previewThemePromise.set(.single(theme.withUpdated(name: "", defaultWallpaper: wallpaper)))
|
||||||
case let .edit(info):
|
case let .edit(info):
|
||||||
hasSettings = info.theme.settings != nil
|
hasSettings = info.theme.settings != nil
|
||||||
|
mayHaveSettings = hasSettings
|
||||||
settingsPromise.set(.single(info.theme.settings))
|
settingsPromise.set(.single(info.theme.settings))
|
||||||
if let file = info.theme.file, let path = context.sharedContext.accountManager.mediaBox.completedResourcePath(file.resource), let data = try? Data(contentsOf: URL(fileURLWithPath: path)), let theme = makePresentationTheme(data: data, resolvedWallpaper: info.resolvedWallpaper) {
|
if let file = info.theme.file, let path = context.sharedContext.accountManager.mediaBox.completedResourcePath(file.resource), let data = try? Data(contentsOf: URL(fileURLWithPath: path)), let theme = makePresentationTheme(data: data, resolvedWallpaper: info.resolvedWallpaper) {
|
||||||
if case let .file(file) = theme.chat.defaultWallpaper, file.id == 0 {
|
if case let .file(file) = theme.chat.defaultWallpaper, file.id == 0 {
|
||||||
@ -323,6 +327,8 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
|
|||||||
var generalThemeReference: PresentationThemeReference?
|
var generalThemeReference: PresentationThemeReference?
|
||||||
if case let .edit(cloudTheme) = mode {
|
if case let .edit(cloudTheme) = mode {
|
||||||
generalThemeReference = PresentationThemeReference.cloud(cloudTheme).generalThemeReference
|
generalThemeReference = PresentationThemeReference.cloud(cloudTheme).generalThemeReference
|
||||||
|
} else if case let .create(existingTheme, _) = mode, existingTheme == nil {
|
||||||
|
generalThemeReference = PresentationThemeReference.builtin(presentationData.theme.referenceTheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
let arguments = EditThemeControllerArguments(context: context, updateState: { f in
|
let arguments = EditThemeControllerArguments(context: context, updateState: { f in
|
||||||
@ -338,7 +344,7 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
|
|||||||
state.updatedTheme = updatedTheme
|
state.updatedTheme = updatedTheme
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
if previousSettings != nil {
|
if previousSettings != nil || mayHaveSettings {
|
||||||
settingsPromise.set(.single(settings))
|
settingsPromise.set(.single(settings))
|
||||||
}
|
}
|
||||||
controllerDismissImpl?()
|
controllerDismissImpl?()
|
||||||
|
@ -186,8 +186,8 @@ final class ThemeAccentColorController: ViewController {
|
|||||||
|
|
||||||
if case let .edit(theme, _, generalThemeReference, _, _, completion) = strongSelf.mode {
|
if case let .edit(theme, _, generalThemeReference, _, _, completion) = strongSelf.mode {
|
||||||
let _ = (prepareWallpaper
|
let _ = (prepareWallpaper
|
||||||
|> deliverOnMainQueue).start(completed: { let updatedTheme: PresentationTheme
|
|> deliverOnMainQueue).start(completed: {
|
||||||
|
let updatedTheme: PresentationTheme
|
||||||
var settings: TelegramThemeSettings?
|
var settings: TelegramThemeSettings?
|
||||||
var hasSettings = false
|
var hasSettings = false
|
||||||
var baseTheme: TelegramBaseTheme?
|
var baseTheme: TelegramBaseTheme?
|
||||||
|
@ -944,7 +944,7 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate
|
|||||||
snapshot.frame = itemNode.bounds
|
snapshot.frame = itemNode.bounds
|
||||||
itemNode.view.addSubview(snapshot)
|
itemNode.view.addSubview(snapshot)
|
||||||
|
|
||||||
snapshot.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, completion: { [weak snapshot] _ in
|
snapshot.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false, completion: { [weak snapshot] _ in
|
||||||
snapshot?.removeFromSuperview()
|
snapshot?.removeFromSuperview()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ class ThemeSettingsChatPreviewItemNode: ListViewItemNode {
|
|||||||
currentBackgroundNode = WallpaperBackgroundNode(context: item.context)
|
currentBackgroundNode = WallpaperBackgroundNode(context: item.context)
|
||||||
}
|
}
|
||||||
currentBackgroundNode?.update(wallpaper: item.wallpaper)
|
currentBackgroundNode?.update(wallpaper: item.wallpaper)
|
||||||
currentBackgroundNode?.updateBubbleTheme(bubbleTheme: item.theme, bubbleCorners: item.chatBubbleCorners)
|
currentBackgroundNode?.updateBubbleTheme(bubbleTheme: item.componentTheme, bubbleCorners: item.chatBubbleCorners)
|
||||||
|
|
||||||
let insets: UIEdgeInsets
|
let insets: UIEdgeInsets
|
||||||
let separatorHeight = UIScreenPixel
|
let separatorHeight = UIScreenPixel
|
||||||
@ -261,13 +261,13 @@ class ThemeSettingsChatPreviewItemNode: ListViewItemNode {
|
|||||||
strongSelf.bottomStripeNode.isHidden = hasCorners
|
strongSelf.bottomStripeNode.isHidden = hasCorners
|
||||||
}
|
}
|
||||||
|
|
||||||
strongSelf.maskNode.image = hasCorners ? PresentationResourcesItemList.cornersImage(item.theme, top: hasTopCorners, bottom: hasBottomCorners) : nil
|
strongSelf.maskNode.image = hasCorners ? PresentationResourcesItemList.cornersImage(item.componentTheme, top: hasTopCorners, bottom: hasBottomCorners) : nil
|
||||||
|
|
||||||
let backgroundFrame = CGRect(origin: CGPoint(x: 0.0, y: -min(insets.top, separatorHeight)), size: CGSize(width: params.width, height: contentSize.height + min(insets.top, separatorHeight) + min(insets.bottom, separatorHeight)))
|
let backgroundFrame = CGRect(origin: CGPoint(x: 0.0, y: -min(insets.top, separatorHeight)), size: CGSize(width: params.width, height: contentSize.height + min(insets.top, separatorHeight) + min(insets.bottom, separatorHeight)))
|
||||||
if let backgroundNode = strongSelf.backgroundNode {
|
if let backgroundNode = strongSelf.backgroundNode {
|
||||||
backgroundNode.frame = backgroundFrame.insetBy(dx: 0.0, dy: -100.0)
|
backgroundNode.frame = backgroundFrame.insetBy(dx: 0.0, dy: -100.0)
|
||||||
backgroundNode.update(wallpaper: item.wallpaper)
|
backgroundNode.update(wallpaper: item.wallpaper)
|
||||||
backgroundNode.updateBubbleTheme(bubbleTheme: item.theme, bubbleCorners: item.chatBubbleCorners)
|
backgroundNode.updateBubbleTheme(bubbleTheme: item.componentTheme, bubbleCorners: item.chatBubbleCorners)
|
||||||
backgroundNode.updateLayout(size: backgroundNode.bounds.size, transition: .immediate)
|
backgroundNode.updateLayout(size: backgroundNode.bounds.size, transition: .immediate)
|
||||||
}
|
}
|
||||||
strongSelf.maskNode.frame = backgroundFrame.insetBy(dx: params.leftInset, dy: 0.0)
|
strongSelf.maskNode.frame = backgroundFrame.insetBy(dx: params.leftInset, dy: 0.0)
|
||||||
|
@ -115,7 +115,7 @@ extension TelegramWallpaper: Codable {
|
|||||||
colors.append(value.rgb)
|
colors.append(value.rgb)
|
||||||
} else if component.count <= 3, let value = Int32(component) {
|
} else if component.count <= 3, let value = Int32(component) {
|
||||||
if intensity == nil {
|
if intensity == nil {
|
||||||
if value >= 0 && value <= 100 {
|
if value >= -100 && value <= 100 {
|
||||||
intensity = value
|
intensity = value
|
||||||
} else {
|
} else {
|
||||||
intensity = 50
|
intensity = 50
|
||||||
|
@ -775,7 +775,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
|
|||||||
|
|
||||||
if bubbleTheme.chat.message.outgoing.bubble.withoutWallpaper.fill.count >= 3 && bubbleTheme.chat.animateMessageColors {
|
if bubbleTheme.chat.message.outgoing.bubble.withoutWallpaper.fill.count >= 3 && bubbleTheme.chat.animateMessageColors {
|
||||||
if self.outgoingBubbleGradientBackgroundNode == nil {
|
if self.outgoingBubbleGradientBackgroundNode == nil {
|
||||||
let outgoingBubbleGradientBackgroundNode = GradientBackgroundNode()
|
let outgoingBubbleGradientBackgroundNode = GradientBackgroundNode(adjustSaturation: false)
|
||||||
if let size = self.validLayout {
|
if let size = self.validLayout {
|
||||||
outgoingBubbleGradientBackgroundNode.frame = CGRect(origin: CGPoint(), size: size)
|
outgoingBubbleGradientBackgroundNode.frame = CGRect(origin: CGPoint(), size: size)
|
||||||
outgoingBubbleGradientBackgroundNode.updateLayout(size: size, transition: .immediate)
|
outgoingBubbleGradientBackgroundNode.updateLayout(size: size, transition: .immediate)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user