Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios

This commit is contained in:
Ilya Laktyushin
2025-12-02 14:28:56 +04:00
15 changed files with 61 additions and 3 deletions

View File

@@ -108,6 +108,7 @@ final class AdminUserActionsPeerComponent: Component {
private weak var state: EmptyComponentState?
public var customUpdateIsHighlighted: ((Bool) -> Void)?
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
public var separatorInset: CGFloat = 0.0
override init(frame: CGRect) {

View File

@@ -100,18 +100,23 @@ private final class ContextOptionComponent: Component {
}
final class ContentContainer: UIScrollView, UIScrollViewDelegate {
private let closeOtherContextOptions: () -> Void
private var itemViews: [AnyHashable: ComponentView<Empty>] = [:]
private var ignoreScrollingEvents: Bool = false
private var draggingBeganInClosedState: Bool = false
private var didProcessScrollingCycle: Bool = false
private var contextOptions: [ListActionItemComponent.ContextOption] = []
private var optionsWidth: CGFloat = 0.0
private var revealedStateTapRecognizer: UITapGestureRecognizer?
override init(frame: CGRect) {
super.init(frame: frame)
init(closeOtherContextOptions: @escaping () -> Void) {
self.closeOtherContextOptions = closeOtherContextOptions
super.init(frame: CGRect())
let revealedStateTapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.onTapGesture(_:)))
self.revealedStateTapRecognizer = revealedStateTapRecognizer
@@ -155,9 +160,16 @@ final class ContentContainer: UIScrollView, UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
self.revealedStateTapRecognizer?.isEnabled = self.contentOffset.x > 0.0
if self.contentOffset.x > 0.0 {
if !self.didProcessScrollingCycle {
self.didProcessScrollingCycle = true
self.closeOtherContextOptions()
}
}
}
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
self.didProcessScrollingCycle = false
self.draggingBeganInClosedState = self.contentOffset.x == 0.0
}
@@ -200,6 +212,10 @@ final class ContentContainer: UIScrollView, UIScrollViewDelegate {
return result
}
func closeContextOptions() {
self.setContentOffset(CGPoint(x: 0.0, y: 0.0), animated: true)
}
func update(size: CGSize, contextOptions: [ListActionItemComponent.ContextOption], transition: ComponentTransition) {
self.contextOptions = contextOptions

View File

@@ -348,10 +348,14 @@ public final class ListActionItemComponent: Component {
}
public var customUpdateIsHighlighted: ((Bool) -> Void)?
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
public var separatorInset: CGFloat = 0.0
public override init(frame: CGRect) {
self.container = ContentContainer(frame: CGRect())
var closeOtherContextOptions: (() -> Void)?
self.container = ContentContainer(closeOtherContextOptions: {
closeOtherContextOptions?()
})
self.button = HighlightTrackingButton()
super.init(frame: CGRect())
@@ -375,6 +379,20 @@ public final class ListActionItemComponent: Component {
customUpdateIsHighlighted(isHighlighted)
}
}
closeOtherContextOptions = { [weak self] in
guard let self else {
return
}
self.enumerateSiblings?({ sibling in
if self === sibling {
return
}
if let view = sibling as? View {
view.container.closeContextOptions()
}
})
}
}
required public init?(coder: NSCoder) {

View File

@@ -425,6 +425,7 @@ public final class ListComposePollOptionComponent: Component {
}
public var customUpdateIsHighlighted: ((Bool) -> Void)?
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
public private(set) var separatorInset: CGFloat = 0.0
public override init(frame: CGRect) {

View File

@@ -130,6 +130,7 @@ public final class ListItemSliderSelectorComponent: Component {
private weak var state: EmptyComponentState?
public var customUpdateIsHighlighted: ((Bool) -> Void)?
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
public private(set) var separatorInset: CGFloat = 0.0
override public init(frame: CGRect) {

View File

@@ -202,6 +202,7 @@ public final class ListMultilineTextFieldItemComponent: Component {
}
public var customUpdateIsHighlighted: ((Bool) -> Void)?
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
public private(set) var separatorInset: CGFloat = 0.0
public override init(frame: CGRect) {

View File

@@ -7,6 +7,7 @@ import DynamicCornerRadiusView
public protocol ListSectionComponentChildView: AnyObject {
var customUpdateIsHighlighted: ((Bool) -> Void)? { get set }
var enumerateSiblings: (((UIView) -> Void) -> Void)? { get set }
var separatorInset: CGFloat { get }
}
@@ -190,6 +191,16 @@ public final class ListSectionContentView: UIView {
}
self.updateHighlightedItem(itemId: isHighlighted ? itemId : nil)
}
itemComponentView.enumerateSiblings = { [weak self, weak itemComponentView] f in
guard let self, let itemComponentView else {
return
}
for (_, itemView) in self.itemViews {
if let otherItemView = itemView.contents.view, otherItemView !== itemComponentView {
f(otherItemView)
}
}
}
}
}
var separatorInset: CGFloat = 0.0
@@ -619,6 +630,7 @@ public final class ListSubSectionComponent: Component {
private var component: ListSubSectionComponent?
public var customUpdateIsHighlighted: ((Bool) -> Void)?
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
public var separatorInset: CGFloat = 0.0
public override init(frame: CGRect) {

View File

@@ -127,6 +127,7 @@ public final class ListTextFieldItemComponent: Component {
}
public var customUpdateIsHighlighted: ((Bool) -> Void)?
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
public private(set) var separatorInset: CGFloat = 0.0
public override init(frame: CGRect) {

View File

@@ -196,6 +196,7 @@ public final class HashtagListItemComponent: Component {
private var isExtractedToContextMenu: Bool = false
public var customUpdateIsHighlighted: ((Bool) -> Void)?
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
public private(set) var separatorInset: CGFloat = 0.0
override init(frame: CGRect) {

View File

@@ -72,6 +72,7 @@ final class GreetingMessageListItemComponent: Component {
private var itemNode: ListViewItemNode?
var customUpdateIsHighlighted: ((Bool) -> Void)?
var enumerateSiblings: (((UIView) -> Void) -> Void)?
private(set) var separatorInset: CGFloat = 0.0
override init(frame: CGRect) {

View File

@@ -73,6 +73,7 @@ final class BusinessLinkListItemComponent: Component {
private weak var componentState: EmptyComponentState?
var customUpdateIsHighlighted: ((Bool) -> Void)?
var enumerateSiblings: (((UIView) -> Void) -> Void)?
private(set) var separatorInset: CGFloat = 0.0
private var isExtractedToContextMenu: Bool = false

View File

@@ -67,6 +67,7 @@ final class ChatIntroItemComponent: Component {
private var emptyNode: ChatEmptyNode?
var customUpdateIsHighlighted: ((Bool) -> Void)?
var enumerateSiblings: (((UIView) -> Void) -> Void)?
private(set) var separatorInset: CGFloat = 0.0
override init(frame: CGRect) {

View File

@@ -56,6 +56,7 @@ final class MapPreviewComponent: Component {
private let pinForegroundView: UIImageView
var customUpdateIsHighlighted: ((Bool) -> Void)?
var enumerateSiblings: (((UIView) -> Void) -> Void)?
private(set) var separatorInset: CGFloat = 0.0
override init(frame: CGRect) {

View File

@@ -74,6 +74,7 @@ final class ChatbotSearchResultItemComponent: Component {
private weak var state: EmptyComponentState?
var customUpdateIsHighlighted: ((Bool) -> Void)?
var enumerateSiblings: (((UIView) -> Void) -> Void)?
private(set) var separatorInset: CGFloat = 0.0
override init(frame: CGRect) {

View File

@@ -464,6 +464,7 @@ public final class PeerListItemComponent: Component {
private var isExtractedToContextMenu: Bool = false
public var customUpdateIsHighlighted: ((Bool) -> Void)?
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
public private(set) var separatorInset: CGFloat = 0.0
override init(frame: CGRect) {