mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +00:00
Implement reaction switch [skip ci]
This commit is contained in:
parent
74c56e6adf
commit
a10b815fa8
24
submodules/Components/ReactionImageComponent/BUILD
Normal file
24
submodules/Components/ReactionImageComponent/BUILD
Normal file
@ -0,0 +1,24 @@
|
||||
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
|
||||
|
||||
swift_library(
|
||||
name = "ReactionImageComponent",
|
||||
module_name = "ReactionImageComponent",
|
||||
srcs = glob([
|
||||
"Sources/**/*.swift",
|
||||
]),
|
||||
copts = [
|
||||
"-warnings-as-errors",
|
||||
],
|
||||
deps = [
|
||||
"//submodules/Display:Display",
|
||||
"//submodules/ComponentFlow:ComponentFlow",
|
||||
"//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit",
|
||||
"//submodules/Postbox:Postbox",
|
||||
"//submodules/TelegramCore:TelegramCore",
|
||||
"//submodules/AccountContext:AccountContext",
|
||||
"//submodules/WebPBinding:WebPBinding",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
)
|
@ -0,0 +1,96 @@
|
||||
import Foundation
|
||||
import AsyncDisplayKit
|
||||
import Display
|
||||
import ComponentFlow
|
||||
import SwiftSignalKit
|
||||
import Postbox
|
||||
import TelegramCore
|
||||
import AccountContext
|
||||
import TelegramPresentationData
|
||||
import UIKit
|
||||
import WebPBinding
|
||||
|
||||
public final class ReactionImageNode: ASImageNode {
|
||||
private var disposable: Disposable?
|
||||
public let size: CGSize
|
||||
|
||||
public init(context: AccountContext, availableReactions: AvailableReactions?, reaction: String) {
|
||||
var file: TelegramMediaFile?
|
||||
if let availableReactions = availableReactions {
|
||||
for availableReaction in availableReactions.reactions {
|
||||
if availableReaction.value == reaction {
|
||||
file = availableReaction.staticIcon
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if let file = file {
|
||||
self.size = file.dimensions?.cgSize ?? CGSize(width: 18.0, height: 18.0)
|
||||
|
||||
super.init()
|
||||
|
||||
self.disposable = (context.account.postbox.mediaBox.resourceData(file.resource)
|
||||
|> deliverOnMainQueue).start(next: { [weak self] data in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
|
||||
if data.complete, let dataValue = try? Data(contentsOf: URL(fileURLWithPath: data.path)) {
|
||||
if let image = WebP.convert(fromWebP: dataValue) {
|
||||
strongSelf.image = image
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
self.size = CGSize(width: 18.0, height: 18.0)
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.disposable?.dispose()
|
||||
}
|
||||
}
|
||||
|
||||
public final class ReactionFileImageNode: ASImageNode {
|
||||
private let disposable = MetaDisposable()
|
||||
|
||||
private var currentFile: TelegramMediaFile?
|
||||
|
||||
override public init() {
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.disposable.dispose()
|
||||
}
|
||||
|
||||
public func asyncLayout() -> (_ context: AccountContext, _ file: TelegramMediaFile?) -> (size: CGSize, apply: () -> Void) {
|
||||
return { [weak self] context, file in
|
||||
let size = file?.dimensions?.cgSize ?? CGSize(width: 18.0, height: 18.0)
|
||||
|
||||
return (size, {
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
if strongSelf.currentFile != file {
|
||||
strongSelf.currentFile = file
|
||||
|
||||
if let file = file {
|
||||
strongSelf.disposable.set((context.account.postbox.mediaBox.resourceData(file.resource)
|
||||
|> deliverOnMainQueue).start(next: { data in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
|
||||
if data.complete, let dataValue = try? Data(contentsOf: URL(fileURLWithPath: data.path)) {
|
||||
if let image = WebP.convert(fromWebP: dataValue) {
|
||||
strongSelf.image = image
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ swift_library(
|
||||
"//submodules/AnimatedAvatarSetNode:AnimatedAvatarSetNode",
|
||||
"//submodules/ContextUI:ContextUI",
|
||||
"//submodules/AvatarNode:AvatarNode",
|
||||
"//submodules/Components/ReactionImageComponent:ReactionImageComponent",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
|
@ -12,48 +12,7 @@ import WebPBinding
|
||||
import AnimatedAvatarSetNode
|
||||
import ContextUI
|
||||
import AvatarNode
|
||||
|
||||
private final class ReactionImageNode: ASImageNode {
|
||||
private var disposable: Disposable?
|
||||
let size: CGSize
|
||||
|
||||
init(context: AccountContext, availableReactions: AvailableReactions?, reaction: String) {
|
||||
var file: TelegramMediaFile?
|
||||
if let availableReactions = availableReactions {
|
||||
for availableReaction in availableReactions.reactions {
|
||||
if availableReaction.value == reaction {
|
||||
file = availableReaction.staticIcon
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if let file = file {
|
||||
self.size = file.dimensions?.cgSize ?? CGSize(width: 18.0, height: 18.0)
|
||||
|
||||
super.init()
|
||||
|
||||
self.disposable = (context.account.postbox.mediaBox.resourceData(file.resource)
|
||||
|> deliverOnMainQueue).start(next: { [weak self] data in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
|
||||
if data.complete, let dataValue = try? Data(contentsOf: URL(fileURLWithPath: data.path)) {
|
||||
if let image = WebP.convert(fromWebP: dataValue) {
|
||||
strongSelf.image = image
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
self.size = CGSize(width: 18.0, height: 18.0)
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.disposable?.dispose()
|
||||
}
|
||||
}
|
||||
import ReactionImageComponent
|
||||
|
||||
private let avatarFont = avatarPlaceholderFont(size: 16.0)
|
||||
|
||||
|
@ -73,6 +73,7 @@ swift_library(
|
||||
"//submodules/UIKitRuntimeUtils:UIKitRuntimeUtils",
|
||||
"//submodules/AnimatedStickerNode:AnimatedStickerNode",
|
||||
"//submodules/TelegramAnimatedStickerNode:TelegramAnimatedStickerNode",
|
||||
"//submodules/Components/ReactionImageComponent:ReactionImageComponent",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -127,10 +127,18 @@ private enum PeerAllowedReactionListControllerEntry: ItemListNodeEntry {
|
||||
case let .itemsHeader(text):
|
||||
return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section)
|
||||
case let .item(_, value, file, text, isEnabled):
|
||||
let _ = file
|
||||
return ItemListSwitchItem(presentationData: presentationData, title: "\(value) \(text)", value: isEnabled, sectionId: self.section, style: .blocks, updated: { _ in
|
||||
arguments.toggleItem(value)
|
||||
})
|
||||
return ItemListReactionItem(
|
||||
context: arguments.context,
|
||||
presentationData: presentationData,
|
||||
file: file,
|
||||
title: text,
|
||||
value: isEnabled,
|
||||
sectionId: self.section,
|
||||
style: .blocks,
|
||||
updated: { _ in
|
||||
arguments.toggleItem(value)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user