mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
GIF-related fixes
This commit is contained in:
parent
00bb2df74e
commit
2a079f808e
@ -12,6 +12,10 @@ private enum FetchError {
|
||||
@available(iOS 10.0, *)
|
||||
private func fetchRawData(prefix: String) -> Signal<Data, FetchError> {
|
||||
return Signal { subscriber in
|
||||
#if targetEnvironment(simulator)
|
||||
return EmptyDisposable
|
||||
#endif
|
||||
|
||||
let container = CKContainer.default()
|
||||
let publicDatabase = container.database(with: .public)
|
||||
let recordId = CKRecord.ID(recordName: "emergency-datacenter-\(prefix)")
|
||||
|
@ -201,6 +201,44 @@ public extension UIColor {
|
||||
return self
|
||||
}
|
||||
|
||||
func blitOver(_ other: UIColor, alpha: CGFloat) -> UIColor {
|
||||
let alpha = min(1.0, max(0.0, alpha))
|
||||
let oneMinusAlpha = 1.0 - alpha
|
||||
|
||||
var r1: CGFloat = 0.0
|
||||
var r2: CGFloat = 0.0
|
||||
var g1: CGFloat = 0.0
|
||||
var g2: CGFloat = 0.0
|
||||
var b1: CGFloat = 0.0
|
||||
var b2: CGFloat = 0.0
|
||||
var a1: CGFloat = 0.0
|
||||
var a2: CGFloat = 0.0
|
||||
if self.getRed(&r1, green: &g1, blue: &b1, alpha: &a1) &&
|
||||
other.getRed(&r2, green: &g2, blue: &b2, alpha: &a2)
|
||||
{
|
||||
let resultingAlpha = max(0.0, min(1.0, alpha * a1))
|
||||
let oneMinusResultingAlpha = 1.0 - resultingAlpha
|
||||
|
||||
let r = r1 * resultingAlpha + r2 * oneMinusResultingAlpha
|
||||
let g = g1 * resultingAlpha + g2 * oneMinusResultingAlpha
|
||||
let b = b1 * resultingAlpha + b2 * oneMinusResultingAlpha
|
||||
let a: CGFloat = 1.0
|
||||
return UIColor(red: r, green: g, blue: b, alpha: a)
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
func withMultipliedAlpha(_ alpha: CGFloat) -> UIColor {
|
||||
var r1: CGFloat = 0.0
|
||||
var g1: CGFloat = 0.0
|
||||
var b1: CGFloat = 0.0
|
||||
var a1: CGFloat = 0.0
|
||||
if self.getRed(&r1, green: &g1, blue: &b1, alpha: &a1) {
|
||||
return UIColor(red: r1, green: g1, blue: b1, alpha: max(0.0, min(1.0, a1 * alpha)))
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
func interpolateTo(_ color: UIColor, fraction: CGFloat) -> UIColor? {
|
||||
let f = min(max(0, fraction), 1)
|
||||
|
||||
|
@ -52,7 +52,8 @@ private final class ShimmerEffectForegroundNode: ASDisplayNode {
|
||||
self.currentBackgroundColor = backgroundColor
|
||||
self.currentForegroundColor = foregroundColor
|
||||
|
||||
self.imageNode.image = generateImage(CGSize(width: 4.0, height: 320.0), opaque: true, scale: 1.0, rotatedContext: { size, context in
|
||||
self.imageNode.image = generateImage(CGSize(width: 16.0, height: 320.0), opaque: false, scale: 1.0, rotatedContext: { size, context in
|
||||
context.clear(CGRect(origin: CGPoint(), size: size))
|
||||
context.setFillColor(backgroundColor.cgColor)
|
||||
context.fill(CGRect(origin: CGPoint(), size: size))
|
||||
|
||||
|
@ -141,6 +141,9 @@ final class ChatMediaInputGifPane: ChatMediaInputPane, UIScrollViewDelegate {
|
||||
|
||||
func setMode(mode: ChatMediaInputGifMode) {
|
||||
if self.mode == mode {
|
||||
if let multiplexedNode = self.multiplexedNode {
|
||||
multiplexedNode.scrollNode.view.setContentOffset(CGPoint(), animated: true)
|
||||
}
|
||||
return
|
||||
}
|
||||
self.mode = mode
|
||||
|
@ -217,9 +217,7 @@ func chatMediaInputPanelEntries(view: ItemCollectionsView, savedStickers: Ordere
|
||||
return entries
|
||||
}
|
||||
|
||||
private let reactions: [String] = ["👍", "👎", "😍", "😂", "😯", "😕", "😢", "😡", "💪", "👏", "🙈", "😒"]
|
||||
|
||||
func chatMediaInputPanelGifModeEntries(theme: PresentationTheme) -> [ChatMediaInputPanelEntry] {
|
||||
func chatMediaInputPanelGifModeEntries(theme: PresentationTheme, reactions: [String]) -> [ChatMediaInputPanelEntry] {
|
||||
var entries: [ChatMediaInputPanelEntry] = []
|
||||
entries.append(.stickersMode(theme))
|
||||
entries.append(.savedGifs(theme))
|
||||
@ -827,10 +825,27 @@ final class ChatMediaInputNode: ChatInputNode {
|
||||
})
|
||||
self.trendingInteraction = trendingInteraction
|
||||
|
||||
let preferencesViewKey: PostboxViewKey = .preferences(keys: Set([PreferencesKeys.appConfiguration]))
|
||||
let reactions: Signal<[String], NoError> = context.account.postbox.combinedView(keys: [preferencesViewKey])
|
||||
|> map { views -> [String] in
|
||||
let defaultReactions: [String] = ["👍", "👎", "😍", "😂", "😯", "😕", "😢", "😡", "💪", "👏", "🙈", "😒"]
|
||||
guard let view = views.views[preferencesViewKey] as? PreferencesView else {
|
||||
return defaultReactions
|
||||
}
|
||||
guard let appConfiguration = view.values[PreferencesKeys.appConfiguration] as? AppConfiguration else {
|
||||
return defaultReactions
|
||||
}
|
||||
guard let data = appConfiguration.data, let emojis = data["gif_search_emojies"] as? [String] else {
|
||||
return defaultReactions
|
||||
}
|
||||
return emojis
|
||||
}
|
||||
|> distinctUntilChanged
|
||||
|
||||
let previousView = Atomic<ItemCollectionsView?>(value: nil)
|
||||
let transitionQueue = Queue()
|
||||
let transitions = combineLatest(queue: transitionQueue, itemCollectionsView, peerSpecificPack, context.account.viewTracker.featuredStickerPacks(), self.themeAndStringsPromise.get())
|
||||
|> map { viewAndUpdate, peerSpecificPack, trendingPacks, themeAndStrings -> (ItemCollectionsView, ChatMediaInputPanelTransition, ChatMediaInputPanelTransition, Bool, ChatMediaInputGridTransition, Bool) in
|
||||
let transitions = combineLatest(queue: transitionQueue, itemCollectionsView, peerSpecificPack, context.account.viewTracker.featuredStickerPacks(), self.themeAndStringsPromise.get(), reactions)
|
||||
|> map { viewAndUpdate, peerSpecificPack, trendingPacks, themeAndStrings, reactions -> (ItemCollectionsView, ChatMediaInputPanelTransition, ChatMediaInputPanelTransition, Bool, ChatMediaInputGridTransition, Bool) in
|
||||
let (view, viewUpdate) = viewAndUpdate
|
||||
let previous = previousView.swap(view)
|
||||
var update = viewUpdate
|
||||
@ -866,7 +881,7 @@ final class ChatMediaInputNode: ChatInputNode {
|
||||
}
|
||||
|
||||
let panelEntries = chatMediaInputPanelEntries(view: view, savedStickers: savedStickers, recentStickers: recentStickers, peerSpecificPack: peerSpecificPack.0, canInstallPeerSpecificPack: peerSpecificPack.1, hasUnreadTrending: hasUnreadTrending, theme: theme)
|
||||
let gifPaneEntries = chatMediaInputPanelGifModeEntries(theme: theme)
|
||||
let gifPaneEntries = chatMediaInputPanelGifModeEntries(theme: theme, reactions: reactions)
|
||||
var gridEntries = chatMediaInputGridEntries(view: view, savedStickers: savedStickers, recentStickers: recentStickers, peerSpecificPack: peerSpecificPack.0, canInstallPeerSpecificPack: peerSpecificPack.1, strings: strings, theme: theme)
|
||||
|
||||
if view.higher == nil {
|
||||
|
@ -312,7 +312,7 @@ final class ChatMediaInputStickerGridItemNode: GridItemNode {
|
||||
placeholderNode.frame = CGRect(origin: CGPoint(), size: size)
|
||||
|
||||
let theme = item.theme
|
||||
placeholderNode.update(backgroundColor: theme.chat.inputMediaPanel.stickersBackgroundColor, foregroundColor: theme.chat.inputMediaPanel.stickersSectionTextColor.mixedWith(theme.chat.inputMediaPanel.stickersBackgroundColor, alpha: 0.9), shimmeringColor: theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.3), shapes: [.roundedRect(rect: placeholderFrame, cornerRadius: 10.0)], size: bounds.size)
|
||||
placeholderNode.update(backgroundColor: theme.chat.inputMediaPanel.stickersBackgroundColor, foregroundColor: theme.chat.inputMediaPanel.stickersSectionTextColor.blitOver(theme.chat.inputMediaPanel.stickersBackgroundColor, alpha: 0.1), shimmeringColor: theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.3), shapes: [.roundedRect(rect: placeholderFrame, cornerRadius: 10.0)], size: bounds.size)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,7 +247,7 @@ final class ChatMediaInputStickerPackItemNode: ListViewItemNode {
|
||||
|
||||
if let placeholderImageNode = self.placeholderImageNode {
|
||||
if placeholderImageNode.image == nil {
|
||||
placeholderImageNode.image = generateStretchableFilledCircleImage(diameter: 10.0, color: theme.chat.inputMediaPanel.panelHighlightedIconBackgroundColor.mixedWith(.clear, alpha: 0.6))
|
||||
placeholderImageNode.image = generateStretchableFilledCircleImage(diameter: 10.0, color: theme.chat.inputMediaPanel.panelHighlightedIconBackgroundColor.withMultipliedAlpha(0.3))
|
||||
}
|
||||
let size = boundingSize
|
||||
let imageSize = boundingImageSize
|
||||
@ -261,7 +261,7 @@ final class ChatMediaInputStickerPackItemNode: ListViewItemNode {
|
||||
let placeholderFrame = CGRect(origin: CGPoint(x: floor((boundingSize.width - imageSize.width) / 2.0) + verticalOffset, y: floor((boundingSize.height - imageSize.height) / 2.0)), size: imageSize)
|
||||
placeholderNode.frame = CGRect(origin: CGPoint(), size: size)
|
||||
|
||||
placeholderNode.update(backgroundColor: theme.chat.inputPanel.panelBackgroundColor, foregroundColor: theme.chat.inputMediaPanel.panelHighlightedIconBackgroundColor.mixedWith(theme.chat.inputPanel.panelBackgroundColor, alpha: 0.8), shimmeringColor: theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.3), shapes: [.roundedRect(rect: placeholderFrame, cornerRadius: 5.0)], size: bounds.size)
|
||||
placeholderNode.update(backgroundColor: theme.chat.inputPanel.panelBackgroundColor, foregroundColor: theme.chat.inputMediaPanel.stickersSectionTextColor.blitOver(theme.chat.inputPanel.panelBackgroundColor, alpha: 0.4), shimmeringColor: theme.chat.inputMediaPanel.panelHighlightedIconBackgroundColor.withMultipliedAlpha(0.2), shapes: [.roundedRect(rect: placeholderFrame, cornerRadius: 5.0)], size: bounds.size)
|
||||
}
|
||||
|
||||
self.updateIsHighlighted()
|
||||
|
@ -30,7 +30,7 @@ final class MultiplexedVideoPlaceholderNode: ASDisplayNode {
|
||||
}
|
||||
|
||||
self.effectNode.frame = CGRect(origin: CGPoint(), size: size)
|
||||
self.effectNode.update(backgroundColor: theme.chat.inputPanel.panelBackgroundColor, foregroundColor: theme.chat.inputMediaPanel.stickersSectionTextColor.mixedWith(theme.chat.inputPanel.panelBackgroundColor, alpha: 0.72), shimmeringColor: theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.3), shapes: [.rect(rect: CGRect(origin: CGPoint(), size: size))], size: bounds.size)
|
||||
self.effectNode.update(backgroundColor: theme.chat.inputMediaPanel.stickersBackgroundColor, foregroundColor: theme.chat.inputMediaPanel.stickersSectionTextColor.blitOver(theme.chat.inputMediaPanel.stickersBackgroundColor, alpha: 0.2), shimmeringColor: theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.3), shapes: [.rect(rect: CGRect(origin: CGPoint(), size: size))], size: bounds.size)
|
||||
}
|
||||
|
||||
func updateAbsoluteRect(_ absoluteRect: CGRect, within containerSize: CGSize) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user