Refactoring

This commit is contained in:
Ali 2023-10-08 22:20:39 +04:00
parent bb2bf7c51e
commit da9cf8a30f
21 changed files with 81 additions and 244 deletions

View File

@ -353,6 +353,7 @@ swift_library(
"//submodules/TelegramUI/Components/Chat/ChatOverscrollControl",
"//submodules/TelegramUI/Components/AudioWaveformNode",
"//submodules/TelegramUI/Components/Chat/ChatBotInfoItem",
"//submodules/TelegramUI/Components/Chat/ChatInputPanelNode",
] + select({
"@build_bazel_rules_apple//apple:ios_arm64": appcenter_targets,
"//build-system:ios_sim_arm64": [],

View File

@ -0,0 +1,23 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "ChatInputPanelNode",
module_name = "ChatInputPanelNode",
srcs = glob([
"Sources/**/*.swift",
]),
copts = [
"-warnings-as-errors",
],
deps = [
"//submodules/AsyncDisplayKit",
"//submodules/Display",
"//submodules/Postbox",
"//submodules/TelegramCore",
"//submodules/AccountContext",
"//submodules/ChatPresentationInterfaceState",
],
visibility = [
"//visibility:public",
],
)

View File

@ -0,0 +1,43 @@
import Foundation
import UIKit
import AsyncDisplayKit
import Display
import Postbox
import TelegramCore
import AccountContext
import ChatPresentationInterfaceState
public protocol ChatInputPanelViewForOverlayContent: UIView {
func maybeDismissContent(point: CGPoint)
}
open class ChatInputPanelNode: ASDisplayNode {
open var context: AccountContext?
open var interfaceInteraction: ChatPanelInterfaceInteraction?
open var prevInputPanelNode: ChatInputPanelNode?
open var viewForOverlayContent: ChatInputPanelViewForOverlayContent?
open func updateAbsoluteRect(_ rect: CGRect, within containerSize: CGSize, transition: ContainedViewLayoutTransition) {
}
open func updateLayout(width: CGFloat, leftInset: CGFloat, rightInset: CGFloat, bottomInset: CGFloat, additionalSideInsets: UIEdgeInsets, maxHeight: CGFloat, isSecondary: Bool, transition: ContainedViewLayoutTransition, interfaceState: ChatPresentationInterfaceState, metrics: LayoutMetrics, isMediaInputExpanded: Bool) -> CGFloat {
return 0.0
}
open func minimalHeight(interfaceState: ChatPresentationInterfaceState, metrics: LayoutMetrics) -> CGFloat {
return 0.0
}
open func defaultHeight(metrics: LayoutMetrics) -> CGFloat {
if case .regular = metrics.widthClass, case .regular = metrics.heightClass {
return 49.0
} else {
return 45.0
}
}
open func canHandleTransition(from prevInputPanelNode: ChatInputPanelNode?) -> Bool {
return false
}
}

View File

@ -9,6 +9,7 @@ import TelegramPresentationData
import ChatPresentationInterfaceState
import SolidRoundedButtonNode
import TooltipUI
import ChatInputPanelNode
final class ChatBotStartInputPanelNode: ChatInputPanelNode {
private let button: SolidRoundedButtonNode

View File

@ -11,6 +11,7 @@ import PresentationDataUtils
import PeerInfoUI
import UndoUI
import ChatPresentationInterfaceState
import ChatInputPanelNode
private enum SubscriberAction: Equatable {
case join

View File

@ -28,6 +28,7 @@ import ChatAvatarNavigationNode
import AccessoryPanelNode
import ForwardAccessoryPanelNode
import ChatOverscrollControl
import ChatInputPanelNode
final class VideoNavigationControllerDropContentItem: NavigationControllerDropContentItem {
let itemNode: OverlayMediaItemNode

View File

@ -1,75 +0,0 @@
import Foundation
import UIKit
import AsyncDisplayKit
import Display
import TelegramCore
import Postbox
import SwiftSignalKit
import TelegramPresentationData
import ChatPresentationInterfaceState
final class ChatFeedNavigationInputPanelNode: ChatInputPanelNode {
private let button: HighlightableButtonNode
private var presentationInterfaceState: ChatPresentationInterfaceState?
private var theme: PresentationTheme
private var strings: PresentationStrings
init(theme: PresentationTheme, strings: PresentationStrings) {
self.theme = theme
self.strings = strings
self.button = HighlightableButtonNode()
super.init()
self.addSubnode(self.button)
self.button.setAttributedTitle(NSAttributedString(string: "Show Next", font: Font.regular(17.0), textColor: theme.chat.inputPanel.panelControlAccentColor), for: [])
self.button.addTarget(self, action: #selector(self.buttonPressed), forControlEvents: [.touchUpInside])
}
deinit {
}
func updateThemeAndStrings(theme: PresentationTheme, strings: PresentationStrings) {
if self.theme !== theme || self.strings !== strings {
self.theme = theme
self.strings = strings
self.button.setAttributedTitle(NSAttributedString(string: strings.Conversation_Unblock, font: Font.regular(17.0), textColor: theme.chat.inputPanel.panelControlAccentColor), for: [])
}
}
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if self.bounds.contains(point) {
return self.button.view
} else {
return nil
}
}
@objc func buttonPressed() {
self.interfaceInteraction?.navigateFeed()
}
override func updateLayout(width: CGFloat, leftInset: CGFloat, rightInset: CGFloat, bottomInset: CGFloat, additionalSideInsets: UIEdgeInsets, maxHeight: CGFloat, isSecondary: Bool, transition: ContainedViewLayoutTransition, interfaceState: ChatPresentationInterfaceState, metrics: LayoutMetrics, isMediaInputExpanded: Bool) -> CGFloat {
if self.presentationInterfaceState != interfaceState {
self.presentationInterfaceState = interfaceState
}
let buttonSize = self.button.measure(CGSize(width: width - leftInset - rightInset - 80.0, height: 100.0))
let panelHeight = defaultHeight(metrics: metrics)
self.button.frame = CGRect(origin: CGPoint(x: leftInset + floor((width - leftInset - rightInset - buttonSize.width) / 2.0), y: floor((panelHeight - buttonSize.height) / 2.0)), size: buttonSize)
return panelHeight
}
override func minimalHeight(interfaceState: ChatPresentationInterfaceState, metrics: LayoutMetrics) -> CGFloat {
return defaultHeight(metrics: metrics)
}
}

View File

@ -1,119 +0,0 @@
import Foundation
import UIKit
import Postbox
import AsyncDisplayKit
import Display
import SwiftSignalKit
import TelegramPresentationData
import ChatMessageItemCommon
private let titleFont = UIFont.systemFont(ofSize: 13.0)
class ChatHoleItem: ListViewItem {
let index: MessageIndex
let presentationData: ChatPresentationData
//let header: ChatMessageDateHeader
init(index: MessageIndex, presentationData: ChatPresentationData) {
self.index = index
self.presentationData = presentationData
//self.header = ChatMessageDateHeader(timestamp: index.timestamp, theme: theme, strings: strings)
}
func nodeConfiguredForParams(async: @escaping (@escaping () -> Void) -> Void, params: ListViewItemLayoutParams, synchronousLoads: Bool, previousItem: ListViewItem?, nextItem: ListViewItem?, completion: @escaping (ListViewItemNode, @escaping () -> (Signal<Void, NoError>?, (ListViewItemApply) -> Void)) -> Void) {
async {
let node = ChatHoleItemNode()
node.layoutForParams(params, item: self, previousItem: previousItem, nextItem: nextItem)
Queue.mainQueue().async {
completion(node, {
return (nil, { _ in })
})
}
}
}
func updateNode(async: @escaping (@escaping () -> Void) -> Void, node: @escaping () -> ListViewItemNode, params: ListViewItemLayoutParams, previousItem: ListViewItem?, nextItem: ListViewItem?, animation: ListViewItemUpdateAnimation, completion: @escaping (ListViewItemNodeLayout, @escaping (ListViewItemApply) -> Void) -> Void) {
Queue.mainQueue().async {
completion(ListViewItemNodeLayout(contentSize: node().contentSize, insets: node().insets), { _ in
})
}
}
}
class ChatHoleItemNode: ListViewItemNode {
var item: ChatHoleItem?
let backgroundNode: ASImageNode
let labelNode: TextNode
private let layoutConstants = ChatMessageItemLayoutConstants.default
init() {
self.backgroundNode = ASImageNode()
self.backgroundNode.isLayerBacked = true
self.backgroundNode.displayWithoutProcessing = true
self.backgroundNode.displaysAsynchronously = false
self.labelNode = TextNode()
self.labelNode.isUserInteractionEnabled = false
super.init(layerBacked: false)
self.addSubnode(self.backgroundNode)
self.addSubnode(self.labelNode)
self.transform = CATransform3DMakeRotation(CGFloat.pi, 0.0, 0.0, 1.0)
}
override func layoutForParams(_ params: ListViewItemLayoutParams, item: ListViewItem, previousItem: ListViewItem?, nextItem: ListViewItem?) {
if let item = item as? ChatHoleItem {
let dateAtBottom = false//!chatItemsHaveCommonDateHeader(item, nextItem)
let (layout, apply) = self.asyncLayout()(item, params, dateAtBottom)
apply()
self.contentSize = layout.contentSize
self.insets = layout.insets
}
}
func asyncLayout() -> (_ item: ChatHoleItem, _ params: ListViewItemLayoutParams, _ dateAtBottom: Bool) -> (ListViewItemNodeLayout, () -> Void) {
let labelLayout = TextNode.asyncLayout(self.labelNode)
let layoutConstants = self.layoutConstants
let currentItem = self.item
return { item, params, dateAtBottom in
var updatedBackground: UIImage?
if item.presentationData.theme !== currentItem?.presentationData.theme {
let graphics = PresentationResourcesChat.additionalGraphics(item.presentationData.theme.theme, wallpaper: item.presentationData.theme.wallpaper, bubbleCorners: item.presentationData.chatBubbleCorners)
updatedBackground = graphics.chatServiceBubbleFillImage
}
let serviceColor = serviceMessageColorComponents(theme: item.presentationData.theme.theme, wallpaper: item.presentationData.theme.wallpaper)
let (size, apply) = labelLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: item.presentationData.strings.Channel_NotificationLoading, font: titleFont, textColor: serviceColor.primaryText), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
let backgroundSize = CGSize(width: size.size.width + 8.0 + 8.0, height: 20.0)
return (ListViewItemNodeLayout(contentSize: CGSize(width: params.width, height: 20.0), insets: UIEdgeInsets(top: 4.0 + (dateAtBottom ? layoutConstants.timestampHeaderHeight : 0.0), left: 0.0, bottom: 4.0, right: 0.0)), { [weak self] in
if let strongSelf = self {
strongSelf.item = item
if let updatedBackground = updatedBackground {
strongSelf.backgroundNode.image = updatedBackground
}
let _ = apply()
strongSelf.backgroundNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((params.width - backgroundSize.width) / 2.0), y: 0.0), size: backgroundSize)
strongSelf.labelNode.frame = CGRect(origin: CGPoint(x: strongSelf.backgroundNode.frame.origin.x + 8.0, y: floorToScreenPixels((backgroundSize.height - size.size.height) / 2.0)), size: size.size)
}
})
}
}
override public func animateAdded(_ currentTimestamp: Double, duration: Double) {
self.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
}
override public func animateRemoved(_ currentTimestamp: Double, duration: Double) {
self.layer.animateAlpha(from: 1.0, to: 0.0, duration: duration * 0.5, removeOnCompletion: false)
}
}

View File

@ -1,43 +0,0 @@
import Foundation
import UIKit
import AsyncDisplayKit
import Display
import Postbox
import TelegramCore
import AccountContext
import ChatPresentationInterfaceState
protocol ChatInputPanelViewForOverlayContent: UIView {
func maybeDismissContent(point: CGPoint)
}
class ChatInputPanelNode: ASDisplayNode {
var context: AccountContext?
var interfaceInteraction: ChatPanelInterfaceInteraction?
var prevInputPanelNode: ChatInputPanelNode?
var viewForOverlayContent: ChatInputPanelViewForOverlayContent?
func updateAbsoluteRect(_ rect: CGRect, within containerSize: CGSize, transition: ContainedViewLayoutTransition) {
}
func updateLayout(width: CGFloat, leftInset: CGFloat, rightInset: CGFloat, bottomInset: CGFloat, additionalSideInsets: UIEdgeInsets, maxHeight: CGFloat, isSecondary: Bool, transition: ContainedViewLayoutTransition, interfaceState: ChatPresentationInterfaceState, metrics: LayoutMetrics, isMediaInputExpanded: Bool) -> CGFloat {
return 0.0
}
func minimalHeight(interfaceState: ChatPresentationInterfaceState, metrics: LayoutMetrics) -> CGFloat {
return 0.0
}
func defaultHeight(metrics: LayoutMetrics) -> CGFloat {
if case .regular = metrics.widthClass, case .regular = metrics.heightClass {
return 49.0
} else {
return 45.0
}
}
func canHandleTransition(from prevInputPanelNode: ChatInputPanelNode?) -> Bool {
return false
}
}

View File

@ -8,6 +8,7 @@ import ChatPresentationInterfaceState
import ChatControllerInteraction
import ChatInputNode
import ChatEntityKeyboardInputNode
import ChatInputPanelNode
func inputNodeForChatPresentationIntefaceState(_ chatPresentationInterfaceState: ChatPresentationInterfaceState, context: AccountContext, currentNode: ChatInputNode?, interfaceInteraction: ChatPanelInterfaceInteraction?, controllerInteraction: ChatControllerInteraction, inputPanelNode: ChatInputPanelNode?, makeMediaInputNode: () -> ChatInputNode?) -> ChatInputNode? {
if let inputPanelNode = inputPanelNode, !(inputPanelNode is ChatTextInputPanelNode) {

View File

@ -4,6 +4,7 @@ import AsyncDisplayKit
import TelegramCore
import AccountContext
import ChatPresentationInterfaceState
import ChatInputPanelNode
func inputPanelForChatPresentationIntefaceState(_ chatPresentationInterfaceState: ChatPresentationInterfaceState, context: AccountContext, currentPanel: ChatInputPanelNode?, currentSecondaryPanel: ChatInputPanelNode?, textInputPanelNode: ChatTextInputPanelNode?, interfaceInteraction: ChatPanelInterfaceInteraction?) -> (primary: ChatInputPanelNode?, secondary: ChatInputPanelNode?) {
if let renderedPeer = chatPresentationInterfaceState.renderedPeer, renderedPeer.peer?.restrictionText(platform: "ios", contentSettings: context.currentContentSettings.with { $0 }) != nil {

View File

@ -205,8 +205,6 @@ func chatItemsHaveCommonDateHeader(_ lhs: ListViewItem, _ rhs: ListViewItem?) -
let rhsHeader: ChatMessageDateHeader?
if let lhs = lhs as? ChatMessageItem {
lhsHeader = lhs.dateHeader
} else if let _ = lhs as? ChatHoleItem {
lhsHeader = nil
} else if let lhs = lhs as? ChatUnreadItem {
lhsHeader = lhs.header
} else if let lhs = lhs as? ChatReplyCountItem {
@ -217,9 +215,6 @@ func chatItemsHaveCommonDateHeader(_ lhs: ListViewItem, _ rhs: ListViewItem?) -
if let rhs = rhs {
if let rhs = rhs as? ChatMessageItem {
rhsHeader = rhs.dateHeader
} else if let _ = rhs as? ChatHoleItem {
//rhsHeader = rhs.header
rhsHeader = nil
} else if let rhs = rhs as? ChatUnreadItem {
rhsHeader = rhs.header
} else if let rhs = rhs as? ChatReplyCountItem {
@ -564,8 +559,6 @@ public final class ChatMessageItem: ListViewItem, CustomStringConvertible {
if bottom.header.id != self.dateHeader.id {
dateAtBottom = true
}
} else if let _ = bottom as? ChatHoleItem {
dateAtBottom = true
} else {
dateAtBottom = true
}

View File

@ -9,6 +9,7 @@ import TelegramPresentationData
import AccountContext
import AppBundle
import ChatPresentationInterfaceState
import ChatInputPanelNode
final class ChatMessageReportInputPanelNode: ChatInputPanelNode {
private let reportButton: HighlightableButtonNode

View File

@ -9,6 +9,7 @@ import TelegramPresentationData
import AccountContext
import AppBundle
import ChatPresentationInterfaceState
import ChatInputPanelNode
final class ChatMessageSelectionInputPanelNode: ChatInputPanelNode {
private let deleteButton: HighlightableButtonNode

View File

@ -14,6 +14,7 @@ import ManagedAnimationNode
import ChatPresentationInterfaceState
import ChatSendButtonRadialStatusNode
import AudioWaveformNode
import ChatInputPanelNode
extension AudioWaveformNode: CustomMediaPlayerScrubbingForegroundNode {
}

View File

@ -8,6 +8,7 @@ import SwiftSignalKit
import TelegramStringFormatting
import ChatPresentationInterfaceState
import TelegramPresentationData
import ChatInputPanelNode
final class ChatRestrictedInputPanelNode: ChatInputPanelNode {
private let textNode: ImmediateTextNode

View File

@ -9,6 +9,7 @@ import TelegramNotices
import TelegramPresentationData
import ActivityIndicator
import ChatPresentationInterfaceState
import ChatInputPanelNode
private let labelFont = Font.regular(15.0)

View File

@ -39,6 +39,7 @@ import TooltipUI
import ChatTextInputMediaRecordingButton
import ChatContextQuery
import ChatInputTextNode
import ChatInputPanelNode
private let accessoryButtonFont = Font.medium(14.0)
private let counterFont = Font.with(size: 14.0, design: .regular, traits: [.monospacedNumbers])

View File

@ -7,6 +7,7 @@ import Postbox
import SwiftSignalKit
import TelegramPresentationData
import ChatPresentationInterfaceState
import ChatInputPanelNode
final class ChatUnblockInputPanelNode: ChatInputPanelNode {
private let button: HighlightableButtonNode

View File

@ -6,6 +6,7 @@ import TelegramCore
import Postbox
import SwiftSignalKit
import ChatPresentationInterfaceState
import ChatInputPanelNode
final class DeleteChatInputPanelNode: ChatInputPanelNode {
private let button: HighlightableButtonNode

View File

@ -7,6 +7,7 @@ import Postbox
import SwiftSignalKit
import LocalizedPeerData
import ChatPresentationInterfaceState
import ChatInputPanelNode
final class SecretChatHandshakeStatusInputPanelNode: ChatInputPanelNode {
private let button: HighlightableButtonNode