Skip to content

Instantly share code, notes, and snippets.

View sreshetnyak's full-sized avatar

Sergey Reshetnyak sreshetnyak

  • Ukraine, Mykolaiv
View GitHub Profile
@sreshetnyak
sreshetnyak / ChatCollectionViewFlowLayout.swift
Created August 10, 2021 13:14 — forked from jochenschoellig/ChatCollectionViewFlowLayout.swift
A subclass of UICollectionViewFlowLayout to get chat behavior without turning collection view upside-down. This layout is written in Swift 3 and absolutely usable with RxSwift and RxDataSources because UI is completely separated from any logic or binding.
import UIKit
class ChatCollectionViewFlowLayout: UICollectionViewFlowLayout {
private var topMostVisibleItem = Int.max
private var bottomMostVisibleItem = -Int.max
private var offset: CGFloat = 0.0
private var visibleAttributes: [UICollectionViewLayoutAttributes]?