Skip to content

Commit

Permalink
Reformatted code to swift 5.10
Browse files Browse the repository at this point in the history
  • Loading branch information
ekazaev committed Mar 11, 2024
1 parent 411b9bb commit 1f8b917
Show file tree
Hide file tree
Showing 105 changed files with 171 additions and 471 deletions.
13 changes: 7 additions & 6 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@
--octalgrouping none
--operatorfunc spaced
--patternlet hoist
--self remove
--selfrequired
--selfrequired
--semicolons inline
--stripunusedargs closure-only
--tabwidth unspecified
--trailingclosures
--trimwhitespace always
--wraparguments preserve
--wrapcollections preserve
--xcodeindentation disabled
--modifierorder public,override
--disable blankLinesAtEndOfScope,blankLinesAtStartOfScope,wrapMultilineStatementBraces,preferKeyPath,preferForLoop
--enable isEmpty
--exclude Pods,docs,Example/Pods
--nevertrailing map, flatMap, compactMap
--funcattributes prev-line
--typeattributes prev-line
--disable wrapMultilineStatementBraces, preferKeyPath, trailingclosures, preferForLoop,conditionalAssignment
--enable isEmpty,wrapConditionalBodies,noExplicitOwnership,wrapEnumCases,wrapSwitchCases,sortSwitchCases,wrapAttributes
--exclude Pods,docs,Example/Pods,RecyclerView/Classes/Utils/Stolen
2 changes: 0 additions & 2 deletions ChatLayout/Classes/Core/ChatItemAlignment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import UIKit

/// Represent item alignment in collection view layout
public enum ChatItemAlignment: Hashable {

/// Should be aligned at the leading edge of the layout. That includes all the additional content offsets.
case leading

Expand All @@ -27,5 +26,4 @@ public enum ChatItemAlignment: Hashable {

/// Should be aligned using the full width of the available content width.
case fullWidth

}
8 changes: 3 additions & 5 deletions ChatLayout/Classes/Core/ChatLayoutAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import UIKit

/// Custom implementation of `UICollectionViewLayoutAttributes`
public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes {

/// Alignment of the current item. Can be changed within `UICollectionViewCell.preferredLayoutAttributesFitting(...)`
public var alignment: ChatItemAlignment = .fullWidth

Expand Down Expand Up @@ -79,11 +78,11 @@ public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes {
public var kind: ItemKind {
switch (representedElementCategory, representedElementKind) {
case (.cell, nil):
return .cell
.cell
case (.supplementaryView, .some(UICollectionView.elementKindSectionHeader)):
return .header
.header
case (.supplementaryView, .some(UICollectionView.elementKindSectionFooter)):
return .footer
.footer
default:
preconditionFailure("Unsupported element kind.")
}
Expand All @@ -95,5 +94,4 @@ public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes {
}
return typedCopy
}

}
6 changes: 0 additions & 6 deletions ChatLayout/Classes/Core/ChatLayoutDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@ import UIKit

/// Represents the point in time when `CollectionViewChatLayout` asks about layout attributes modification.
public enum InitialAttributesRequestType: Hashable {

/// `UICollectionView` initially asks about the layout of an item.
case initial

/// An item is being invalidated.
case invalidation

}

/// `CollectionViewChatLayout` delegate
public protocol ChatLayoutDelegate: AnyObject {

/// `CollectionViewChatLayout` will call this method to ask if it should present the header in the current layout.
/// - Parameters:
/// - chatLayout: `CollectionViewChatLayout` reference.
Expand Down Expand Up @@ -121,12 +118,10 @@ public protocol ChatLayoutDelegate: AnyObject {
/// - sectionIndex: Index of the section.
func interSectionSpacing(_ chatLayout: CollectionViewChatLayout,
after sectionIndex: Int) -> CGFloat?

}

/// Default extension.
public extension ChatLayoutDelegate {

/// Default implementation returns: `false`.
func shouldPresentHeader(_ chatLayout: CollectionViewChatLayout,
at sectionIndex: Int) -> Bool {
Expand Down Expand Up @@ -182,5 +177,4 @@ public extension ChatLayoutDelegate {
after sectionIndex: Int) -> CGFloat? {
nil
}

}
2 changes: 0 additions & 2 deletions ChatLayout/Classes/Core/ChatLayoutInvalidationContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import UIKit

/// Custom implementation of `UICollectionViewLayoutInvalidationContext`
public final class ChatLayoutInvalidationContext: UICollectionViewLayoutInvalidationContext {

/// Indicates whether to recompute the positions and sizes of the items based on the current
/// collection view and delegate layout metrics.
public var invalidateLayoutMetrics = true

}
4 changes: 0 additions & 4 deletions ChatLayout/Classes/Core/ChatLayoutPositionSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ import UIKit

/// Represents content offset position expressed by the specific item and it offset from the top or bottom edge.
public struct ChatLayoutPositionSnapshot: Hashable {

/// Represents the edge.
public enum Edge: Hashable {

/// Top edge of the `UICollectionView`
case top

/// Bottom edge of the `UICollectionView`
case bottom

}

/// Item's `IndexPath`
Expand Down Expand Up @@ -54,5 +51,4 @@ public struct ChatLayoutPositionSnapshot: Hashable {
self.offset = offset
self.kind = kind
}

}
2 changes: 0 additions & 2 deletions ChatLayout/Classes/Core/ChatLayoutSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import UIKit

/// `CollectionViewChatLayout` settings.
public struct ChatLayoutSettings: Equatable {

/// Estimated item size for `CollectionViewChatLayout`. This value will be used as the initial size of the item and the final size
/// will be calculated using `UICollectionViewCell.preferredLayoutAttributesFitting(...)`.
public var estimatedItemSize: CGSize?
Expand All @@ -28,5 +27,4 @@ public struct ChatLayoutSettings: Equatable {

/// Additional insets for the `CollectionViewChatLayout` content.
public var additionalInsets: UIEdgeInsets = .zero

}
26 changes: 11 additions & 15 deletions ChatLayout/Classes/Core/CollectionViewChatLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import UIKit
///
/// `CollectionViewChatLayout.restoreContentOffset(...)`
open class CollectionViewChatLayout: UICollectionViewLayout {

// MARK: Custom Properties

/// `CollectionViewChatLayout` delegate.
Expand Down Expand Up @@ -169,23 +168,19 @@ open class CollectionViewChatLayout: UICollectionViewLayout {
// MARK: Private Properties

private struct PrepareActions: OptionSet {

let rawValue: UInt

static let recreateSectionModels = PrepareActions(rawValue: 1 << 0)
static let updateLayoutMetrics = PrepareActions(rawValue: 1 << 1)
static let cachePreviousWidth = PrepareActions(rawValue: 1 << 2)
static let cachePreviousContentInsets = PrepareActions(rawValue: 1 << 3)
static let switchStates = PrepareActions(rawValue: 1 << 4)

}

private struct InvalidationActions: OptionSet {

let rawValue: UInt

static let shouldInvalidateOnBoundsChange = InvalidationActions(rawValue: 1 << 0)

}

private lazy var controller = StateController(layoutRepresentation: self)
Expand Down Expand Up @@ -220,9 +215,15 @@ open class CollectionViewChatLayout: UICollectionViewLayout {
// MARK: IOS 15.1 fix flags

private var needsIOS15_1IssueFix: Bool {
guard enableIOS15_1Fix else { return false }
guard #unavailable(iOS 15.2) else { return false }
guard #available(iOS 15.1, *) else { return false }
guard enableIOS15_1Fix else {
return false
}
guard #unavailable(iOS 15.2) else {
return false
}
guard #available(iOS 15.1, *) else {
return false
}
return isUserInitiatedScrolling && !controller.isAnimatedBoundsChange
}

Expand Down Expand Up @@ -599,7 +600,8 @@ open class CollectionViewChatLayout: UICollectionViewLayout {
switch preferredMessageAttributes.kind {
case .cell:
context.invalidateItems(at: [preferredMessageAttributes.indexPath])
case .header, .footer:
case .footer,
.header:
context.invalidateSupplementaryElements(ofKind: preferredMessageAttributes.kind.supplementaryElementStringType, at: [preferredMessageAttributes.indexPath])
}
}
Expand Down Expand Up @@ -939,11 +941,9 @@ open class CollectionViewChatLayout: UICollectionViewLayout {
}
return attributes
}

}

extension CollectionViewChatLayout {

func configuration(for element: ItemKind, at indexPath: IndexPath) -> ItemModel.Configuration {
let itemSize = estimatedSize(for: element, at: indexPath)
let interItemSpacing: CGFloat
Expand Down Expand Up @@ -1023,11 +1023,9 @@ extension CollectionViewChatLayout {
invalidatedAttributes[kind] = []
}
}

}

extension CollectionViewChatLayout: ChatLayoutRepresentation {

func numberOfItems(in section: Int) -> Int {
guard let collectionView else {
return .zero
Expand Down Expand Up @@ -1056,7 +1054,6 @@ extension CollectionViewChatLayout: ChatLayoutRepresentation {
}

extension CollectionViewChatLayout {

private var maxPossibleContentOffset: CGPoint {
guard let collectionView else {
return .zero
Expand All @@ -1071,5 +1068,4 @@ extension CollectionViewChatLayout {
}
return collectionView.isDragging || collectionView.isDecelerating
}

}
5 changes: 2 additions & 3 deletions ChatLayout/Classes/Core/Extensions/CGRect+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Foundation
import UIKit

extension CGRect {

var higherPoint: CGPoint {
origin
}
Expand All @@ -27,9 +26,9 @@ extension CGRect {
CGPoint(x: origin.x + size.width / 2, y: origin.y + size.height / 2)
}

@inline(__always) mutating func offsettingBy(dx: CGFloat, dy: CGFloat) {
@inline(__always)
mutating func offsettingBy(dx: CGFloat, dy: CGFloat) {
origin.x += dx
origin.y += dy
}

}
2 changes: 0 additions & 2 deletions ChatLayout/Classes/Core/Extensions/IndexPath+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import Foundation

extension IndexPath {

var itemPath: ItemPath {
ItemPath(for: self)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import Foundation

extension RandomAccessCollection where Index == Int {

func binarySearch(predicate: (Element) -> ComparisonResult) -> Index? {
var lowerBound = startIndex
var upperBound = endIndex
Expand Down Expand Up @@ -79,5 +78,4 @@ extension RandomAccessCollection where Index == Int {

return Array(self[lowerBound...upperBound])
}

}
2 changes: 0 additions & 2 deletions ChatLayout/Classes/Core/Model/ChangeItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import UIKit

/// Internal replacement for `UICollectionViewUpdateItem`.
enum ChangeItem: Equatable {

/// Delete section at `sectionIndex`
case sectionDelete(sectionIndex: Int)

Expand Down Expand Up @@ -98,5 +97,4 @@ enum ChangeItem: Equatable {
return nil
}
}

}
13 changes: 6 additions & 7 deletions ChatLayout/Classes/Core/Model/ItemKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import UIKit

/// Type of the item supported by `CollectionViewChatLayout`
public enum ItemKind: CaseIterable, Hashable {

/// Header item
case header

Expand All @@ -40,9 +39,10 @@ public enum ItemKind: CaseIterable, Hashable {
public var isSupplementaryItem: Bool {
switch self {
case .cell:
return false
case .header, .footer:
return true
false
case .footer,
.header:
true
}
}

Expand All @@ -51,10 +51,9 @@ public enum ItemKind: CaseIterable, Hashable {
case .cell:
preconditionFailure("Cell type is not a supplementary view.")
case .header:
return UICollectionView.elementKindSectionHeader
UICollectionView.elementKindSectionHeader
case .footer:
return UICollectionView.elementKindSectionFooter
UICollectionView.elementKindSectionFooter
}
}

}
4 changes: 0 additions & 4 deletions ChatLayout/Classes/Core/Model/ItemModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ import Foundation
import UIKit

struct ItemModel {

struct Configuration {

let alignment: ChatItemAlignment

let preferredSize: CGSize

let calculatedSize: CGSize?

let interItemSpacing: CGFloat

}

let id: UUID
Expand Down Expand Up @@ -72,5 +69,4 @@ struct ItemModel {
self.calculatedSize = nil
preferredSize = calculatedSize
}

}
2 changes: 0 additions & 2 deletions ChatLayout/Classes/Core/Model/ItemPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Foundation
/// On an iPhone X, compiled with -Os optimizations, it's about 35x faster to initialize this struct
/// compared to an `IndexPath`.
struct ItemPath: Hashable {

let section: Int

let item: Int
Expand All @@ -36,5 +35,4 @@ struct ItemPath: Hashable {
section = indexPath.section
item = indexPath.item
}

}
Loading

0 comments on commit 1f8b917

Please sign in to comment.