mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Various improvements
This commit is contained in:
@@ -24,59 +24,7 @@ import SolidRoundedButtonComponent
|
||||
import AnimationCache
|
||||
import EmojiTextAttachmentView
|
||||
import MediaEditor
|
||||
|
||||
enum AvatarBackground: Equatable {
|
||||
case gradient([UInt32])
|
||||
|
||||
var colors: [UInt32] {
|
||||
switch self {
|
||||
case let .gradient(colors):
|
||||
return colors
|
||||
}
|
||||
}
|
||||
|
||||
var isLight: Bool {
|
||||
switch self {
|
||||
case let .gradient(colors):
|
||||
if colors.count == 1 {
|
||||
return UIColor(rgb: colors.first!).lightness > 0.99
|
||||
} else if colors.count == 2 {
|
||||
return UIColor(rgb: colors.first!).lightness > 0.99 || UIColor(rgb: colors.last!).lightness > 0.99
|
||||
} else {
|
||||
var lightCount = 0
|
||||
for color in colors {
|
||||
if UIColor(rgb: color).lightness > 0.99 {
|
||||
lightCount += 1
|
||||
}
|
||||
}
|
||||
return lightCount >= 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func generateImage(size: CGSize) -> UIImage {
|
||||
switch self {
|
||||
case let .gradient(colors):
|
||||
if colors.count == 1 {
|
||||
return generateSingleColorImage(size: size, color: UIColor(rgb: colors.first!))!
|
||||
} else if colors.count == 2 {
|
||||
return generateGradientImage(size: size, colors: colors.map { UIColor(rgb: $0) }, locations: [0.0, 1.0])!
|
||||
} else {
|
||||
return GradientBackgroundNode.generatePreview(size: size, colors: colors.map { UIColor(rgb: $0) })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private let defaultBackgrounds: [AvatarBackground] = [
|
||||
.gradient([0xFF5A7FFF, 0xFF2CA0F2, 0xFF4DFF89, 0xFF6BFCEB]),
|
||||
.gradient([0xFFFF011D, 0xFFFF530D, 0xFFFE64DC, 0xFFFFDC61]),
|
||||
.gradient([0xFFFE64DC, 0xFFFF6847, 0xFFFFDD02, 0xFFFFAE10]),
|
||||
.gradient([0xFF84EC00, 0xFF00B7C2, 0xFF00C217, 0xFFFFE600]),
|
||||
.gradient([0xFF86B0FF, 0xFF35FFCF, 0xFF69FFFF, 0xFF76DEFF]),
|
||||
.gradient([0xFFFAE100, 0xFFFF54EE, 0xFFFC2B78, 0xFFFF52D9]),
|
||||
.gradient([0xFF73A4FF, 0xFF5F55FF, 0xFFFF49F8, 0xFFEC76FF]),
|
||||
]
|
||||
import AvatarBackground
|
||||
|
||||
public struct AvatarKeyboardInputData: Equatable {
|
||||
var emoji: EmojiPagerContentComponent
|
||||
@@ -147,7 +95,7 @@ final class AvatarEditorScreenComponent: Component {
|
||||
self.context = context
|
||||
self.ready = ready
|
||||
|
||||
self.selectedBackground = defaultBackgrounds.first!
|
||||
self.selectedBackground = AvatarBackground.defaultBackgrounds.first!
|
||||
self.previousColor = self.selectedBackground
|
||||
|
||||
super.init()
|
||||
@@ -181,7 +129,7 @@ final class AvatarEditorScreenComponent: Component {
|
||||
self.selectedBackground = .gradient(markup.backgroundColors.map { UInt32(bitPattern: $0) })
|
||||
self.previousColor = self.selectedBackground
|
||||
} else {
|
||||
self.selectedBackground = defaultBackgrounds.first!
|
||||
self.selectedBackground = AvatarBackground.defaultBackgrounds.first!
|
||||
}
|
||||
|
||||
self.previousColor = self.selectedBackground
|
||||
@@ -1046,7 +994,7 @@ final class AvatarEditorScreenComponent: Component {
|
||||
transition: transition,
|
||||
component: AnyComponent(BackgroundColorComponent(
|
||||
theme: environment.theme,
|
||||
values: defaultBackgrounds,
|
||||
values: AvatarBackground.defaultBackgrounds,
|
||||
selectedValue: state.selectedBackground,
|
||||
customValue: state.customColor,
|
||||
updateValue: { [weak state] value in
|
||||
|
||||
Reference in New Issue
Block a user