mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-29 09:01:05 +00:00
66 lines
1.6 KiB
Swift
66 lines
1.6 KiB
Swift
|
|
typealias PeerInfoItemSectionId = UInt32
|
|
|
|
protocol PeerInfoItem {
|
|
var sectionId: PeerInfoItemSectionId { get }
|
|
}
|
|
|
|
enum PeerInfoItemNeighbor {
|
|
case none
|
|
case otherSection
|
|
case sameSection
|
|
}
|
|
|
|
struct PeerInfoItemNeighbors {
|
|
let top: PeerInfoItemNeighbor
|
|
let bottom: PeerInfoItemNeighbor
|
|
}
|
|
|
|
func peerInfoItemNeighbors(item: PeerInfoItem, topItem: PeerInfoItem?, bottomItem: PeerInfoItem?) -> PeerInfoItemNeighbors {
|
|
let topNeighbor: PeerInfoItemNeighbor
|
|
if let topItem = topItem {
|
|
if topItem.sectionId != item.sectionId {
|
|
topNeighbor = .otherSection
|
|
} else {
|
|
topNeighbor = .sameSection
|
|
}
|
|
} else {
|
|
topNeighbor = .none
|
|
}
|
|
|
|
let bottomNeighbor: PeerInfoItemNeighbor
|
|
if let bottomItem = bottomItem {
|
|
if bottomItem.sectionId != item.sectionId {
|
|
bottomNeighbor = .otherSection
|
|
} else {
|
|
bottomNeighbor = .sameSection
|
|
}
|
|
} else {
|
|
bottomNeighbor = .none
|
|
}
|
|
|
|
return PeerInfoItemNeighbors(top: topNeighbor, bottom: bottomNeighbor)
|
|
}
|
|
|
|
enum PeerInfoListStyle {
|
|
case plain
|
|
case blocks
|
|
}
|
|
|
|
func peerInfoItemNeighborsPlainInsets(_ neighbors: PeerInfoItemNeighbors) -> UIEdgeInsets {
|
|
var insets = UIEdgeInsets()
|
|
switch neighbors.top {
|
|
case .otherSection:
|
|
insets.top += 22.0
|
|
case .none, .sameSection:
|
|
break
|
|
}
|
|
switch neighbors.bottom {
|
|
case .none:
|
|
insets.bottom += 22.0
|
|
case .otherSection, .sameSection:
|
|
break
|
|
}
|
|
return insets
|
|
}
|