Skip to content

Commit 0ac2602

Browse files
committed
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
2 parents 653ee1b + 6dba110 commit 0ac2602

File tree

15 files changed

+61
-3
lines changed

15 files changed

+61
-3
lines changed

submodules/TelegramUI/Components/AdminUserActionsSheet/Sources/AdminUserActionsPeerComponent.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ final class AdminUserActionsPeerComponent: Component {
108108
private weak var state: EmptyComponentState?
109109

110110
public var customUpdateIsHighlighted: ((Bool) -> Void)?
111+
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
111112
public var separatorInset: CGFloat = 0.0
112113

113114
override init(frame: CGRect) {

submodules/TelegramUI/Components/ListActionItemComponent/Sources/ContentContainer.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,23 @@ private final class ContextOptionComponent: Component {
100100
}
101101

102102
final class ContentContainer: UIScrollView, UIScrollViewDelegate {
103+
private let closeOtherContextOptions: () -> Void
104+
103105
private var itemViews: [AnyHashable: ComponentView<Empty>] = [:]
104106

105107
private var ignoreScrollingEvents: Bool = false
106108
private var draggingBeganInClosedState: Bool = false
109+
private var didProcessScrollingCycle: Bool = false
107110

108111
private var contextOptions: [ListActionItemComponent.ContextOption] = []
109112
private var optionsWidth: CGFloat = 0.0
110113

111114
private var revealedStateTapRecognizer: UITapGestureRecognizer?
112115

113-
override init(frame: CGRect) {
114-
super.init(frame: frame)
116+
init(closeOtherContextOptions: @escaping () -> Void) {
117+
self.closeOtherContextOptions = closeOtherContextOptions
118+
119+
super.init(frame: CGRect())
115120

116121
let revealedStateTapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.onTapGesture(_:)))
117122
self.revealedStateTapRecognizer = revealedStateTapRecognizer
@@ -155,9 +160,16 @@ final class ContentContainer: UIScrollView, UIScrollViewDelegate {
155160

156161
func scrollViewDidScroll(_ scrollView: UIScrollView) {
157162
self.revealedStateTapRecognizer?.isEnabled = self.contentOffset.x > 0.0
163+
if self.contentOffset.x > 0.0 {
164+
if !self.didProcessScrollingCycle {
165+
self.didProcessScrollingCycle = true
166+
self.closeOtherContextOptions()
167+
}
168+
}
158169
}
159170

160171
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
172+
self.didProcessScrollingCycle = false
161173
self.draggingBeganInClosedState = self.contentOffset.x == 0.0
162174
}
163175

@@ -200,6 +212,10 @@ final class ContentContainer: UIScrollView, UIScrollViewDelegate {
200212
return result
201213
}
202214

215+
func closeContextOptions() {
216+
self.setContentOffset(CGPoint(x: 0.0, y: 0.0), animated: true)
217+
}
218+
203219
func update(size: CGSize, contextOptions: [ListActionItemComponent.ContextOption], transition: ComponentTransition) {
204220
self.contextOptions = contextOptions
205221

submodules/TelegramUI/Components/ListActionItemComponent/Sources/ListActionItemComponent.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,14 @@ public final class ListActionItemComponent: Component {
348348
}
349349

350350
public var customUpdateIsHighlighted: ((Bool) -> Void)?
351+
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
351352
public var separatorInset: CGFloat = 0.0
352353

353354
public override init(frame: CGRect) {
354-
self.container = ContentContainer(frame: CGRect())
355+
var closeOtherContextOptions: (() -> Void)?
356+
self.container = ContentContainer(closeOtherContextOptions: {
357+
closeOtherContextOptions?()
358+
})
355359
self.button = HighlightTrackingButton()
356360

357361
super.init(frame: CGRect())
@@ -375,6 +379,20 @@ public final class ListActionItemComponent: Component {
375379
customUpdateIsHighlighted(isHighlighted)
376380
}
377381
}
382+
383+
closeOtherContextOptions = { [weak self] in
384+
guard let self else {
385+
return
386+
}
387+
self.enumerateSiblings?({ sibling in
388+
if self === sibling {
389+
return
390+
}
391+
if let view = sibling as? View {
392+
view.container.closeContextOptions()
393+
}
394+
})
395+
}
378396
}
379397

380398
required public init?(coder: NSCoder) {

submodules/TelegramUI/Components/ListComposePollOptionComponent/Sources/ListComposePollOptionComponent.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ public final class ListComposePollOptionComponent: Component {
425425
}
426426

427427
public var customUpdateIsHighlighted: ((Bool) -> Void)?
428+
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
428429
public private(set) var separatorInset: CGFloat = 0.0
429430

430431
public override init(frame: CGRect) {

submodules/TelegramUI/Components/ListItemSliderSelectorComponent/Sources/ListItemSliderSelectorComponent.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public final class ListItemSliderSelectorComponent: Component {
130130
private weak var state: EmptyComponentState?
131131

132132
public var customUpdateIsHighlighted: ((Bool) -> Void)?
133+
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
133134
public private(set) var separatorInset: CGFloat = 0.0
134135

135136
override public init(frame: CGRect) {

submodules/TelegramUI/Components/ListMultilineTextFieldItemComponent/Sources/ListMultilineTextFieldItemComponent.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ public final class ListMultilineTextFieldItemComponent: Component {
202202
}
203203

204204
public var customUpdateIsHighlighted: ((Bool) -> Void)?
205+
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
205206
public private(set) var separatorInset: CGFloat = 0.0
206207

207208
public override init(frame: CGRect) {

submodules/TelegramUI/Components/ListSectionComponent/Sources/ListSectionComponent.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import DynamicCornerRadiusView
77

88
public protocol ListSectionComponentChildView: AnyObject {
99
var customUpdateIsHighlighted: ((Bool) -> Void)? { get set }
10+
var enumerateSiblings: (((UIView) -> Void) -> Void)? { get set }
1011
var separatorInset: CGFloat { get }
1112
}
1213

@@ -190,6 +191,16 @@ public final class ListSectionContentView: UIView {
190191
}
191192
self.updateHighlightedItem(itemId: isHighlighted ? itemId : nil)
192193
}
194+
itemComponentView.enumerateSiblings = { [weak self, weak itemComponentView] f in
195+
guard let self, let itemComponentView else {
196+
return
197+
}
198+
for (_, itemView) in self.itemViews {
199+
if let otherItemView = itemView.contents.view, otherItemView !== itemComponentView {
200+
f(otherItemView)
201+
}
202+
}
203+
}
193204
}
194205
}
195206
var separatorInset: CGFloat = 0.0
@@ -619,6 +630,7 @@ public final class ListSubSectionComponent: Component {
619630
private var component: ListSubSectionComponent?
620631

621632
public var customUpdateIsHighlighted: ((Bool) -> Void)?
633+
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
622634
public var separatorInset: CGFloat = 0.0
623635

624636
public override init(frame: CGRect) {

submodules/TelegramUI/Components/ListTextFieldItemComponent/Sources/ListTextFieldItemComponent.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public final class ListTextFieldItemComponent: Component {
127127
}
128128

129129
public var customUpdateIsHighlighted: ((Bool) -> Void)?
130+
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
130131
public private(set) var separatorInset: CGFloat = 0.0
131132

132133
public override init(frame: CGRect) {

submodules/TelegramUI/Components/MessageInputPanelComponent/Sources/HashtagListItemComponent.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ public final class HashtagListItemComponent: Component {
196196
private var isExtractedToContextMenu: Bool = false
197197

198198
public var customUpdateIsHighlighted: ((Bool) -> Void)?
199+
public var enumerateSiblings: (((UIView) -> Void) -> Void)?
199200
public private(set) var separatorInset: CGFloat = 0.0
200201

201202
override init(frame: CGRect) {

submodules/TelegramUI/Components/Settings/AutomaticBusinessMessageSetupScreen/Sources/AutomaticBusinessMessageListItemComponent.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ final class GreetingMessageListItemComponent: Component {
7272
private var itemNode: ListViewItemNode?
7373

7474
var customUpdateIsHighlighted: ((Bool) -> Void)?
75+
var enumerateSiblings: (((UIView) -> Void) -> Void)?
7576
private(set) var separatorInset: CGFloat = 0.0
7677

7778
override init(frame: CGRect) {

0 commit comments

Comments
 (0)