Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ekazaev committed Apr 7, 2023
1 parent 1e8cff1 commit 6b4ec06
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 37 deletions.
23 changes: 15 additions & 8 deletions ChatLayout/Classes/Core/CollectionViewChatLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import Foundation
import UIKit

/// A collection view layout that can display items in a grid similar to `UITableView` but aligning them
/// to the leading or trailing edge of the `UICollectionView`. Helps to maintain chat like behavior by keeping
/// content offset from the bottom constant. Can deal with autosizing cells and supplementary views.
/// A collection view layout designed to display items in a grid similar to `UITableView`, while aligning them to the
/// leading or trailing edge of the `UICollectionView`. This layout facilitates chat-like behavior by maintaining
/// a constant content offset from the bottom. Additionally, it is capable of handling autosizing cells and
/// supplementary views.
///
/// ### Custom Properties:
/// `CollectionViewChatLayout.delegate`
///
Expand Down Expand Up @@ -433,7 +435,8 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
}

/// Retrieves the layout attributes for the specified supplementary view.
public override func layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
public override func layoutAttributesForSupplementaryView(ofKind elementKind: String,
at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
guard !dontReturnAttributes else {
return nil
}
Expand Down Expand Up @@ -479,7 +482,8 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
// MARK: Context Invalidation

/// Asks the layout object if changes to a self-sizing cell require a layout update.
public override func shouldInvalidateLayout(forPreferredLayoutAttributes preferredAttributes: UICollectionViewLayoutAttributes, withOriginalAttributes originalAttributes: UICollectionViewLayoutAttributes) -> Bool {
public override func shouldInvalidateLayout(forPreferredLayoutAttributes preferredAttributes: UICollectionViewLayoutAttributes,
withOriginalAttributes originalAttributes: UICollectionViewLayoutAttributes) -> Bool {
let preferredAttributesItemPath = preferredAttributes.indexPath.itemPath
guard let preferredMessageAttributes = preferredAttributes as? ChatLayoutAttributes,
let item = controller.item(for: preferredAttributesItemPath, kind: preferredMessageAttributes.kind, at: state) else {
Expand All @@ -492,7 +496,8 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
}

/// Retrieves a context object that identifies the portions of the layout that should change in response to dynamic cell changes.
public override func invalidationContext(forPreferredLayoutAttributes preferredAttributes: UICollectionViewLayoutAttributes, withOriginalAttributes originalAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutInvalidationContext {
public override func invalidationContext(forPreferredLayoutAttributes preferredAttributes: UICollectionViewLayoutAttributes,
withOriginalAttributes originalAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutInvalidationContext {
guard let preferredMessageAttributes = preferredAttributes as? ChatLayoutAttributes else {
return super.invalidationContext(forPreferredLayoutAttributes: preferredAttributes, withOriginalAttributes: originalAttributes)
}
Expand Down Expand Up @@ -789,7 +794,8 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
// MARK: - Supplementary View Appearance Animation

/// Retrieves the starting layout information for a supplementary view being inserted into the collection view.
public override func initialLayoutAttributesForAppearingSupplementaryElement(ofKind elementKind: String, at elementIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
public override func initialLayoutAttributesForAppearingSupplementaryElement(ofKind elementKind: String,
at elementIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
var attributes: ChatLayoutAttributes?

let kind = ItemKind(elementKind)
Expand Down Expand Up @@ -828,7 +834,8 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
}

/// Retrieves the final layout information for a supplementary view that is about to be removed from the collection view.
public override func finalLayoutAttributesForDisappearingSupplementaryElement(ofKind elementKind: String, at elementIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
public override func finalLayoutAttributesForDisappearingSupplementaryElement(ofKind elementKind: String,
at elementIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
var attributes: ChatLayoutAttributes?

let kind = ItemKind(elementKind)
Expand Down
3 changes: 2 additions & 1 deletion ChatLayout/Classes/Core/Model/ItemModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ struct ItemModel {
calculatedOnce = configuration.calculatedSize != nil
}

// We are just resetting `calculatedSize` if needed as the actual size will be found in invalidationContext(forPreferredLayoutAttributes:, withOriginalAttributes:)
// We are just resetting `calculatedSize` if needed as the actual size will be found in
// `invalidationContext(forPreferredLayoutAttributes:, withOriginalAttributes:)`.
// It is important for the rotation to keep previous frame size.
mutating func resetSize() {
guard let calculatedSize else {
Expand Down
6 changes: 4 additions & 2 deletions ChatLayout/Classes/Core/Model/ItemSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import UIKit
/// Represents desired item size.
public enum ItemSize: Hashable {

/// Item size should be fully calculated by the `CollectionViewChatLayout`. Initial estimated size will be taken from `ChatLayoutSettings`.
/// Item size should be fully calculated by the `CollectionViewChatLayout`.
/// Initial estimated size will be taken from `ChatLayoutSettings`.
case auto

/// Item size should be fully calculated by the `CollectionViewChatLayout`. Initial estimated size should be taken from the value provided.
/// Item size should be fully calculated by the `CollectionViewChatLayout`.
/// Initial estimated size should be taken from the value provided.
case estimated(CGSize)

/// Item size should be exactly equal to the value provided.
Expand Down
15 changes: 12 additions & 3 deletions ChatLayout/Classes/Core/Model/StateController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,11 @@ final class StateController<Layout: ChatLayoutRepresentation> {
}
}

func update(preferredSize: CGSize, alignment: ChatItemAlignment, for itemPath: ItemPath, kind: ItemKind, at state: ModelState) {
func update(preferredSize: CGSize,
alignment: ChatItemAlignment,
for itemPath: ItemPath,
kind: ItemKind,
at state: ModelState) {
guard var item = item(for: itemPath, kind: kind, at: state) else {
assertionFailure("Item at index path (\(itemPath.section) - \(itemPath.item)) does not exist.")
return
Expand Down Expand Up @@ -840,7 +844,10 @@ final class StateController<Layout: ChatLayoutRepresentation> {
}
}

private func compensateOffsetIfNeeded(for itemPath: ItemPath, kind: ItemKind, action: CompensatingAction, visibleBounds: CGRect? = nil) {
private func compensateOffsetIfNeeded(for itemPath: ItemPath,
kind: ItemKind,
action: CompensatingAction,
visibleBounds: CGRect? = nil) {
guard layoutRepresentation.keepContentOffsetAtBottomOnBatchUpdates else {
return
}
Expand Down Expand Up @@ -879,7 +886,9 @@ final class StateController<Layout: ChatLayoutRepresentation> {

}

private func compensateOffsetOfSectionIfNeeded(for sectionIndex: Int, action: CompensatingAction, visibleBounds: CGRect? = nil) {
private func compensateOffsetOfSectionIfNeeded(for sectionIndex: Int,
action: CompensatingAction,
visibleBounds: CGRect? = nil) {
guard layoutRepresentation.keepContentOffsetAtBottomOnBatchUpdates else {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@ import Foundation
import UIKit

extension NSLayoutAnchor {
@objc func constraint(equalTo anchor: NSLayoutAnchor<AnchorType>, constant c: CGFloat = 0, priority: UILayoutPriority) -> NSLayoutConstraint {
@objc func constraint(equalTo anchor: NSLayoutAnchor<AnchorType>,
constant c: CGFloat = 0,
priority: UILayoutPriority) -> NSLayoutConstraint {
let constraint = constraint(equalTo: anchor, constant: c)
constraint.priority = priority
return constraint
}

@objc func constraint(greaterThanOrEqualTo anchor: NSLayoutAnchor<AnchorType>, constant c: CGFloat = 0, priority: UILayoutPriority) -> NSLayoutConstraint {
@objc func constraint(greaterThanOrEqualTo anchor: NSLayoutAnchor<AnchorType>,
constant c: CGFloat = 0,
priority: UILayoutPriority) -> NSLayoutConstraint {
let constraint = constraint(greaterThanOrEqualTo: anchor, constant: c)
constraint.priority = priority
return constraint
}

@objc func constraint(lessThanOrEqualTo anchor: NSLayoutAnchor<AnchorType>, constant c: CGFloat = 0, priority: UILayoutPriority) -> NSLayoutConstraint {
@objc func constraint(lessThanOrEqualTo anchor: NSLayoutAnchor<AnchorType>,
constant c: CGFloat = 0,
priority: UILayoutPriority) -> NSLayoutConstraint {
let constraint = constraint(lessThanOrEqualTo: anchor, constant: c)
constraint.priority = priority
return constraint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,49 @@ import Foundation
import UIKit

extension NSLayoutDimension {
@objc func constraint(equalTo anchor: NSLayoutDimension, multiplier m: CGFloat = 1, constant c: CGFloat = 0, priority: UILayoutPriority) -> NSLayoutConstraint {
@objc func constraint(equalTo anchor: NSLayoutDimension,
multiplier m: CGFloat = 1,
constant c: CGFloat = 0,
priority: UILayoutPriority) -> NSLayoutConstraint {
let constraint = constraint(equalTo: anchor, multiplier: m, constant: c)
constraint.priority = priority
return constraint
}

@objc func constraint(greaterThanOrEqualTo anchor: NSLayoutDimension, multiplier m: CGFloat = 1, constant c: CGFloat = 0, priority: UILayoutPriority) -> NSLayoutConstraint {
@objc func constraint(greaterThanOrEqualTo anchor: NSLayoutDimension,
multiplier m: CGFloat = 1,
constant c: CGFloat = 0,
priority: UILayoutPriority) -> NSLayoutConstraint {
let constraint = constraint(greaterThanOrEqualTo: anchor, multiplier: m, constant: c)
constraint.priority = priority
return constraint
}

@objc func constraint(lessThanOrEqualTo anchor: NSLayoutDimension, multiplier m: CGFloat = 1, constant c: CGFloat = 0, priority: UILayoutPriority) -> NSLayoutConstraint {
@objc func constraint(lessThanOrEqualTo anchor: NSLayoutDimension,
multiplier m: CGFloat = 1,
constant c: CGFloat = 0,
priority: UILayoutPriority) -> NSLayoutConstraint {
let constraint = constraint(lessThanOrEqualTo: anchor, multiplier: m, constant: c)
constraint.priority = priority
return constraint
}

@objc func constraint(equalToConstant c: CGFloat, priority: UILayoutPriority) -> NSLayoutConstraint {
@objc func constraint(equalToConstant c: CGFloat,
priority: UILayoutPriority) -> NSLayoutConstraint {
let constraint = constraint(equalToConstant: c)
constraint.priority = priority
return constraint
}

@objc func constraint(greaterThanOrEqualToConstant c: CGFloat, priority: UILayoutPriority) -> NSLayoutConstraint {
@objc func constraint(greaterThanOrEqualToConstant c: CGFloat,
priority: UILayoutPriority) -> NSLayoutConstraint {
let constraint = constraint(greaterThanOrEqualToConstant: c)
constraint.priority = priority
return constraint
}

@objc func constraint(lessThanOrEqualToConstant c: CGFloat, priority: UILayoutPriority) -> NSLayoutConstraint {
@objc func constraint(lessThanOrEqualToConstant c: CGFloat,
priority: UILayoutPriority) -> NSLayoutConstraint {
let constraint = constraint(lessThanOrEqualToConstant: c)
constraint.priority = priority
return constraint
Expand Down
7 changes: 4 additions & 3 deletions docs/Classes/CollectionViewChatLayout.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ <h1>CollectionViewChatLayout</h1>

</div>
</div>
<p>A collection view layout that can display items in a grid similar to <code>UITableView</code> but aligning them
to the leading or trailing edge of the <code>UICollectionView</code>. Helps to maintain chat like behavior by keeping
content offset from the bottom constant. Can deal with autosizing cells and supplementary views.</p>
<p>A collection view layout designed to display items in a grid similar to <code>UITableView</code>, while aligning them to the
leading or trailing edge of the <code>UICollectionView</code>. This layout facilitates chat-like behavior by maintaining
a constant content offset from the bottom. Additionally, it is capable of handling autosizing cells and
supplementary views.</p>
<h3 id='custom-properties' class='heading'>Custom Properties:</h3>

<p><code><a href="../Classes/CollectionViewChatLayout.html#/s:10ChatLayout014CollectionViewaB0C8delegateAA0aB8Delegate_pSgvp">CollectionViewChatLayout.delegate</a></code></p>
Expand Down
7 changes: 4 additions & 3 deletions docs/Core.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ <h1>Core</h1>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>A collection view layout that can display items in a grid similar to <code>UITableView</code> but aligning them
to the leading or trailing edge of the <code>UICollectionView</code>. Helps to maintain chat like behavior by keeping
content offset from the bottom constant. Can deal with autosizing cells and supplementary views.</p>
<p>A collection view layout designed to display items in a grid similar to <code>UITableView</code>, while aligning them to the
leading or trailing edge of the <code>UICollectionView</code>. This layout facilitates chat-like behavior by maintaining
a constant content offset from the bottom. Additionally, it is capable of handling autosizing cells and
supplementary views.</p>
<h3 id='custom-properties' class='heading'>Custom Properties:</h3>

<p><code><a href="Classes/CollectionViewChatLayout.html#/s:10ChatLayout014CollectionViewaB0C8delegateAA0aB8Delegate_pSgvp">CollectionViewChatLayout.delegate</a></code></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ <h1>CollectionViewChatLayout</h1>

</div>
</div>
<p>A collection view layout that can display items in a grid similar to <code>UITableView</code> but aligning them
to the leading or trailing edge of the <code>UICollectionView</code>. Helps to maintain chat like behavior by keeping
content offset from the bottom constant. Can deal with autosizing cells and supplementary views.</p>
<p>A collection view layout designed to display items in a grid similar to <code>UITableView</code>, while aligning them to the
leading or trailing edge of the <code>UICollectionView</code>. This layout facilitates chat-like behavior by maintaining
a constant content offset from the bottom. Additionally, it is capable of handling autosizing cells and
supplementary views.</p>
<h3 id='custom-properties' class='heading'>Custom Properties:</h3>

<p><code><a href="../Classes/CollectionViewChatLayout.html#/s:10ChatLayout014CollectionViewaB0C8delegateAA0aB8Delegate_pSgvp">CollectionViewChatLayout.delegate</a></code></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ <h1>Core</h1>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>A collection view layout that can display items in a grid similar to <code>UITableView</code> but aligning them
to the leading or trailing edge of the <code>UICollectionView</code>. Helps to maintain chat like behavior by keeping
content offset from the bottom constant. Can deal with autosizing cells and supplementary views.</p>
<p>A collection view layout designed to display items in a grid similar to <code>UITableView</code>, while aligning them to the
leading or trailing edge of the <code>UICollectionView</code>. This layout facilitates chat-like behavior by maintaining
a constant content offset from the bottom. Additionally, it is capable of handling autosizing cells and
supplementary views.</p>
<h3 id='custom-properties' class='heading'>Custom Properties:</h3>

<p><code><a href="Classes/CollectionViewChatLayout.html#/s:10ChatLayout014CollectionViewaB0C8delegateAA0aB8Delegate_pSgvp">CollectionViewChatLayout.delegate</a></code></p>
Expand Down

Large diffs are not rendered by default.

Binary file modified docs/docsets/ChatLayout.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/search.json

Large diffs are not rendered by default.

0 comments on commit 6b4ec06

Please sign in to comment.