mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Emoji improvements
This commit is contained in:
parent
eac396f944
commit
2aefab5b03
.bazelrc
submodules
SSignalKit/SwiftSignalKit/Source
StickerPackPreviewUI/Sources
TelegramUI
Components
EmojiTextAttachmentView/Sources
MultiAnimationRenderer/Sources
Sources
3
.bazelrc
3
.bazelrc
@ -31,3 +31,6 @@ build --spawn_strategy=standalone
|
||||
|
||||
build --strategy=SwiftCompile=standalone
|
||||
build --define RULES_SWIFT_BUILD_DUMMY_WORKER=1
|
||||
|
||||
#build --linkopt=-fuse-ld=/Users/ali/build/zld/build/Build/Products/Release/zld
|
||||
#build --linkopt=-Wl,-zld_original_ld_path,__BAZEL_XCODE_DEVELOPER_DIR__/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
|
||||
|
@ -1,5 +1,9 @@
|
||||
import Foundation
|
||||
|
||||
public enum AtomicLockError: Error {
|
||||
case isLocked
|
||||
}
|
||||
|
||||
public final class Atomic<T> {
|
||||
private var lock: pthread_mutex_t
|
||||
private var value: T
|
||||
@ -23,6 +27,16 @@ public final class Atomic<T> {
|
||||
return result
|
||||
}
|
||||
|
||||
public func tryWith<R>(_ f: (T) -> R) throws -> R {
|
||||
if pthread_mutex_trylock(&self.lock) == 0 {
|
||||
let result = f(self.value)
|
||||
pthread_mutex_unlock(&self.lock)
|
||||
return result
|
||||
} else {
|
||||
throw AtomicLockError.isLocked
|
||||
}
|
||||
}
|
||||
|
||||
public func modify(_ f: (T) -> T) -> T {
|
||||
pthread_mutex_lock(&self.lock)
|
||||
let result = f(self.value)
|
||||
|
@ -283,7 +283,7 @@ final class StickerPackEmojisItemNode: GridItemNode {
|
||||
context: context,
|
||||
dimensions: item.file.dimensions?.cgSize ?? CGSize(width: 512.0, height: 512.0),
|
||||
immediateThumbnailData: item.file.immediateThumbnailData,
|
||||
shimmerView: strongSelf.shimmerHostView,
|
||||
shimmerView: nil,//strongSelf.shimmerHostView,
|
||||
color: theme.chat.inputPanel.primaryTextColor.withMultipliedAlpha(0.08),
|
||||
size: itemNativeFitSize
|
||||
)
|
||||
|
@ -184,13 +184,14 @@ public final class InlineStickerItemLayer: MultiAnimationRenderTarget {
|
||||
} else {
|
||||
let pointSize = self.pointSize
|
||||
let placeholderColor = self.placeholderColor
|
||||
let isThumbnailCancelled = Atomic<Bool>(value: false)
|
||||
self.loadDisposable = self.renderer.loadFirstFrame(target: self, cache: self.cache, itemId: file.resource.id.stringRepresentation, size: self.pixelSize, fetch: animationCacheFetchFile(context: self.context, resource: .media(media: .standalone(media: file), resource: file.resource), type: AnimationCacheAnimationType(file: file), keyframeOnly: true), completion: { [weak self] result, isFinal in
|
||||
if !result {
|
||||
MultiAnimationRendererImpl.firstFrameQueue.async {
|
||||
let image = generateStickerPlaceholderImage(data: file.immediateThumbnailData, size: pointSize, scale: min(2.0, UIScreenScale), imageSize: file.dimensions?.cgSize ?? CGSize(width: 512.0, height: 512.0), backgroundColor: nil, foregroundColor: placeholderColor)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
guard let strongSelf = self else {
|
||||
guard let strongSelf = self, !isThumbnailCancelled.with({ $0 }) else {
|
||||
return
|
||||
}
|
||||
if let image = image {
|
||||
@ -207,6 +208,7 @@ public final class InlineStickerItemLayer: MultiAnimationRenderTarget {
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
let _ = isThumbnailCancelled.swap(true)
|
||||
strongSelf.loadAnimation()
|
||||
}
|
||||
})
|
||||
|
@ -78,9 +78,11 @@ open class MultiAnimationRenderTarget: SimpleLayer {
|
||||
|
||||
private final class LoadFrameGroupTask {
|
||||
let task: () -> () -> Void
|
||||
let queueAffinity: Int
|
||||
|
||||
init(task: @escaping () -> () -> Void) {
|
||||
init(task: @escaping () -> () -> Void, queueAffinity: Int) {
|
||||
self.task = task
|
||||
self.queueAffinity = queueAffinity
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,11 +224,12 @@ private final class ItemAnimationContext {
|
||||
static let queue1 = Queue(name: "ItemAnimationContext-1", qos: .default)
|
||||
|
||||
private let cache: AnimationCache
|
||||
let queueAffinity: Int
|
||||
private let stateUpdated: () -> Void
|
||||
|
||||
private var disposable: Disposable?
|
||||
private var displayLink: ConstantDisplayLinkAnimator?
|
||||
private var item: AnimationCacheItem?
|
||||
private var item: Atomic<AnimationCacheItem>?
|
||||
|
||||
private var currentFrame: Frame?
|
||||
private var isLoadingFrame: Bool = false
|
||||
@ -241,8 +244,9 @@ private final class ItemAnimationContext {
|
||||
|
||||
let targets = Bag<Weak<MultiAnimationRenderTarget>>()
|
||||
|
||||
init(cache: AnimationCache, itemId: String, size: CGSize, fetch: @escaping (AnimationCacheFetchOptions) -> Disposable, stateUpdated: @escaping () -> Void) {
|
||||
init(cache: AnimationCache, queueAffinity: Int, itemId: String, size: CGSize, fetch: @escaping (AnimationCacheFetchOptions) -> Disposable, stateUpdated: @escaping () -> Void) {
|
||||
self.cache = cache
|
||||
self.queueAffinity = queueAffinity
|
||||
self.stateUpdated = stateUpdated
|
||||
|
||||
self.disposable = cache.get(sourceId: itemId, size: size, fetch: fetch).start(next: { [weak self] result in
|
||||
@ -250,7 +254,9 @@ private final class ItemAnimationContext {
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
strongSelf.item = result.item
|
||||
if let item = result.item {
|
||||
strongSelf.item = Atomic(value: item)
|
||||
}
|
||||
strongSelf.updateIsPlaying()
|
||||
}
|
||||
})
|
||||
@ -330,9 +336,14 @@ private final class ItemAnimationContext {
|
||||
|
||||
return LoadFrameGroupTask(task: { [weak self] in
|
||||
let currentFrame: Frame?
|
||||
if let frame = item.advance(advance: frameAdvance, requestedFormat: .rgba) {
|
||||
currentFrame = Frame(frame: frame)
|
||||
} else {
|
||||
do {
|
||||
if let frame = try item.tryWith({ $0.advance(advance: frameAdvance, requestedFormat: .rgba) }) {
|
||||
currentFrame = Frame(frame: frame)
|
||||
} else {
|
||||
currentFrame = nil
|
||||
}
|
||||
} catch {
|
||||
assertionFailure()
|
||||
currentFrame = nil
|
||||
}
|
||||
|
||||
@ -356,7 +367,7 @@ private final class ItemAnimationContext {
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}, queueAffinity: self.queueAffinity)
|
||||
}
|
||||
|
||||
if let _ = self.currentFrame {
|
||||
@ -383,6 +394,7 @@ public final class MultiAnimationRendererImpl: MultiAnimationRenderer {
|
||||
}
|
||||
|
||||
private var itemContexts: [ItemKey: ItemAnimationContext] = [:]
|
||||
private var nextQueueAffinity: Int = 0
|
||||
|
||||
private(set) var isPlaying: Bool = false {
|
||||
didSet {
|
||||
@ -403,7 +415,9 @@ public final class MultiAnimationRendererImpl: MultiAnimationRenderer {
|
||||
if let current = self.itemContexts[itemKey] {
|
||||
itemContext = current
|
||||
} else {
|
||||
itemContext = ItemAnimationContext(cache: cache, itemId: itemId, size: size, fetch: fetch, stateUpdated: { [weak self] in
|
||||
let queueAffinity = self.nextQueueAffinity
|
||||
self.nextQueueAffinity += 1
|
||||
itemContext = ItemAnimationContext(cache: cache, queueAffinity: queueAffinity, itemId: itemId, size: size, fetch: fetch, stateUpdated: { [weak self] in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
@ -668,59 +682,40 @@ public final class MultiAnimationRendererImpl: MultiAnimationRenderer {
|
||||
}
|
||||
|
||||
if !tasks.isEmpty {
|
||||
if tasks.count > 2 {
|
||||
let tasks0 = Array(tasks.prefix(tasks.count / 2))
|
||||
let tasks1 = Array(tasks.suffix(tasks.count - tasks0.count))
|
||||
|
||||
var tasks0Completions: [() -> Void]?
|
||||
var tasks1Completions: [() -> Void]?
|
||||
|
||||
let complete: (Int, [() -> Void]) -> Void = { index, completions in
|
||||
Queue.mainQueue().async {
|
||||
if index == 0 {
|
||||
tasks0Completions = completions
|
||||
} else if index == 1 {
|
||||
tasks1Completions = completions
|
||||
}
|
||||
if let tasks0Completions = tasks0Completions, let tasks1Completions = tasks1Completions {
|
||||
for completion in tasks0Completions {
|
||||
completion()
|
||||
}
|
||||
for completion in tasks1Completions {
|
||||
completion()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ItemAnimationContext.queue0.async {
|
||||
let tasks0 = tasks.filter { $0.queueAffinity % 2 == 0 }
|
||||
let tasks1 = tasks.filter { $0.queueAffinity % 2 == 1 }
|
||||
let allTasks = [tasks0, tasks1]
|
||||
|
||||
let taskCompletions = Atomic<[Int: [() -> Void]]>(value: [:])
|
||||
let queues: [Queue] = [ItemAnimationContext.queue0, ItemAnimationContext.queue1]
|
||||
|
||||
for i in 0 ..< 2 {
|
||||
let partTasks = allTasks[i]
|
||||
let id = i
|
||||
queues[i].async {
|
||||
var completions: [() -> Void] = []
|
||||
for task in tasks0 {
|
||||
let complete = task.task()
|
||||
completions.append(complete)
|
||||
}
|
||||
complete(0, completions)
|
||||
}
|
||||
ItemAnimationContext.queue1.async {
|
||||
var completions: [() -> Void] = []
|
||||
for task in tasks1 {
|
||||
let complete = task.task()
|
||||
completions.append(complete)
|
||||
}
|
||||
complete(1, completions)
|
||||
}
|
||||
} else {
|
||||
ItemAnimationContext.queue0.async {
|
||||
var completions: [() -> Void] = []
|
||||
for task in tasks {
|
||||
for task in partTasks {
|
||||
let complete = task.task()
|
||||
completions.append(complete)
|
||||
}
|
||||
|
||||
if !completions.isEmpty {
|
||||
var complete = false
|
||||
let _ = taskCompletions.modify { current in
|
||||
var current = current
|
||||
current[id] = completions
|
||||
if current.count == 2 {
|
||||
complete = true
|
||||
}
|
||||
return current
|
||||
}
|
||||
|
||||
if complete {
|
||||
Queue.mainQueue().async {
|
||||
for completion in completions {
|
||||
completion()
|
||||
let allCompletions = taskCompletions.with { $0 }
|
||||
for (_, fs) in allCompletions {
|
||||
for f in fs {
|
||||
f()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -283,7 +283,9 @@ final class ChatEntityKeyboardInputNode: ChatInputNode {
|
||||
itemGroupIndexById[groupId] = itemGroups.count
|
||||
|
||||
var headerItem: EntityKeyboardAnimationData?
|
||||
if let thumbnail = featuredEmojiPack.info.thumbnail {
|
||||
if let thumbnailFileId = featuredEmojiPack.info.thumbnailFileId, let file = featuredEmojiPack.topItems.first(where: { $0.file.fileId.id == thumbnailFileId }) {
|
||||
headerItem = EntityKeyboardAnimationData(file: file.file)
|
||||
} else if let thumbnail = featuredEmojiPack.info.thumbnail {
|
||||
let info = featuredEmojiPack.info
|
||||
let type: EntityKeyboardAnimationData.ItemType
|
||||
if item.file.isAnimatedSticker {
|
||||
@ -323,6 +325,23 @@ final class ChatEntityKeyboardInputNode: ChatInputNode {
|
||||
hasClear = true
|
||||
}
|
||||
|
||||
var headerItem = group.headerItem
|
||||
|
||||
if let groupId = group.id.base as? ItemCollectionId {
|
||||
outer: for (id, info, _) in view.collectionInfos {
|
||||
if id == groupId, let info = info as? StickerPackCollectionInfo {
|
||||
if let thumbnailFileId = info.thumbnailFileId {
|
||||
for item in group.items {
|
||||
if let itemFile = item.itemFile, itemFile.fileId.id == thumbnailFileId {
|
||||
headerItem = EntityKeyboardAnimationData(file: itemFile)
|
||||
break outer
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EmojiPagerContentComponent.ItemGroup(
|
||||
supergroupId: group.supergroupId,
|
||||
groupId: group.id,
|
||||
@ -335,7 +354,7 @@ final class ChatEntityKeyboardInputNode: ChatInputNode {
|
||||
hasClear: hasClear,
|
||||
isExpandable: group.isExpandable,
|
||||
displayPremiumBadges: false,
|
||||
headerItem: group.headerItem,
|
||||
headerItem: headerItem,
|
||||
items: group.items
|
||||
)
|
||||
},
|
||||
@ -697,7 +716,9 @@ final class ChatEntityKeyboardInputNode: ChatInputNode {
|
||||
let subtitle: String = strings.StickerPack_StickerCount(Int32(featuredStickerPack.info.count))
|
||||
var headerItem: EntityKeyboardAnimationData?
|
||||
|
||||
if let thumbnail = featuredStickerPack.info.thumbnail {
|
||||
if let thumbnailFileId = featuredStickerPack.info.thumbnailFileId, let file = featuredStickerPack.topItems.first(where: { $0.file.fileId.id == thumbnailFileId }) {
|
||||
headerItem = EntityKeyboardAnimationData(file: file.file)
|
||||
} else if let thumbnail = featuredStickerPack.info.thumbnail {
|
||||
let info = featuredStickerPack.info
|
||||
let type: EntityKeyboardAnimationData.ItemType
|
||||
if item.file.isAnimatedSticker {
|
||||
|
@ -2610,7 +2610,8 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
|
||||
if replaceRange.location < 0 {
|
||||
break
|
||||
}
|
||||
if inputText.attributedSubstring(from: replaceRange).string != previousText.string {
|
||||
let adjacentString = inputText.attributedSubstring(from: replaceRange)
|
||||
if adjacentString.string != previousText.string || adjacentString.attribute(ChatTextInputAttributes.customEmoji, at: 0, effectiveRange: nil) != nil {
|
||||
break
|
||||
}
|
||||
inputText.replaceCharacters(in: replaceRange, with: NSAttributedString(string: text, attributes: [ChatTextInputAttributes.customEmoji: ChatTextInputTextCustomEmojiAttribute(stickerPack: emojiAttribute.stickerPack, fileId: emojiAttribute.fileId, file: emojiAttribute.file)]))
|
||||
|
Loading…
x
Reference in New Issue
Block a user