mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Collapse sibling options
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user