Skip to content

Commit

Permalink
Reformated the code for swift 5.7 and updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Kazaev committed Aug 24, 2022
1 parent 499f0c7 commit 88cbfc1
Show file tree
Hide file tree
Showing 189 changed files with 4,744 additions and 4,149 deletions.
6 changes: 3 additions & 3 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
--exponentgrouping disabled
--fractiongrouping disabled
--fragment false
--header "\nChatLayout\n{file}\nhttps://github.com/ekazaev/ChatLayout\n\nCreated by Eugene Kazaev in 2020-{year}.\nDistributed under the MIT license.\n"
--header "\nChatLayout\n{file}\nhttps://github.com/ekazaev/ChatLayout\n\nCreated by Eugene Kazaev in 2020-{year}.\nDistributed under the MIT license.\n\nBecome a sponsor:\nhttps://github.com/sponsors/ekazaev\n"
--hexgrouping none
--hexliteralcase uppercase
--ifdef no-indent
Expand All @@ -24,7 +24,7 @@
--octalgrouping none
--operatorfunc spaced
--patternlet hoist
--self init-only
--self remove
--selfrequired
--semicolons inline
--stripunusedargs closure-only
Expand All @@ -35,6 +35,6 @@
--wrapcollections preserve
--xcodeindentation disabled
--modifierorder public,override
--disable blankLinesAtEndOfScope,blankLinesAtStartOfScope,redundantReturn,wrapMultilineStatementBraces
--disable blankLinesAtEndOfScope,blankLinesAtStartOfScope,wrapMultilineStatementBraces
--enable isEmpty
--exclude Pods,docs,Example/Pods
2 changes: 1 addition & 1 deletion ChatLayout.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ChatLayout'
s.version = '1.2.4'
s.version = '1.2.5'
s.summary = 'Chat UI Library. It uses custom UICollectionViewLayout to provide you full control over the presentation.'
s.swift_version = '5.7'

Expand Down
3 changes: 3 additions & 0 deletions ChatLayout/Classes/Core/ChatItemAlignment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// Created by Eugene Kazaev in 2020-2022.
// Distributed under the MIT license.
//
// Become a sponsor:
// https://github.com/sponsors/ekazaev
//

import Foundation
import UIKit
Expand Down
9 changes: 6 additions & 3 deletions ChatLayout/Classes/Core/ChatLayoutAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// Created by Eugene Kazaev in 2020-2022.
// Distributed under the MIT license.
//
// Become a sponsor:
// https://github.com/sponsors/ekazaev
//

import Foundation
import UIKit
Expand Down Expand Up @@ -63,7 +66,7 @@ public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes {

/// Returns a Boolean value indicating whether two `ChatLayoutAttributes` are considered equal.
public override func isEqual(_ object: Any?) -> Bool {
return super.isEqual(object)
super.isEqual(object)
&& alignment == (object as? ChatLayoutAttributes)?.alignment
}

Expand All @@ -77,13 +80,13 @@ public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes {
case (.supplementaryView, .some(UICollectionView.elementKindSectionFooter)):
return .footer
default:
preconditionFailure("Unsupported element kind")
preconditionFailure("Unsupported element kind.")
}
}

func typedCopy() -> ChatLayoutAttributes {
guard let typedCopy = copy() as? ChatLayoutAttributes else {
fatalError("Internal inconsistency")
fatalError("Internal inconsistency.")
}
return typedCopy
}
Expand Down
11 changes: 7 additions & 4 deletions ChatLayout/Classes/Core/ChatLayoutDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// Created by Eugene Kazaev in 2020-2022.
// Distributed under the MIT license.
//
// Become a sponsor:
// https://github.com/sponsors/ekazaev
//

import Foundation
import UIKit
Expand Down Expand Up @@ -108,27 +111,27 @@ public extension ChatLayoutDelegate {
/// Default implementation returns: `false`.
func shouldPresentHeader(_ chatLayout: CollectionViewChatLayout,
at sectionIndex: Int) -> Bool {
return false
false
}

/// Default implementation returns: `false`.
func shouldPresentFooter(_ chatLayout: CollectionViewChatLayout,
at sectionIndex: Int) -> Bool {
return false
false
}

/// Default implementation returns: `ItemSize.auto`.
func sizeForItem(_ chatLayout: CollectionViewChatLayout,
of kind: ItemKind,
at indexPath: IndexPath) -> ItemSize {
return .auto
.auto
}

/// Default implementation returns: `ChatItemAlignment.fullWidth`.
func alignmentForItem(_ chatLayout: CollectionViewChatLayout,
of kind: ItemKind,
at indexPath: IndexPath) -> ChatItemAlignment {
return .fullWidth
.fullWidth
}

/// Default implementation sets a `ChatLayoutAttributes.alpha` to zero.
Expand Down
3 changes: 3 additions & 0 deletions ChatLayout/Classes/Core/ChatLayoutInvalidationContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// Created by Eugene Kazaev in 2020-2022.
// Distributed under the MIT license.
//
// Become a sponsor:
// https://github.com/sponsors/ekazaev
//

import Foundation
import UIKit
Expand Down
7 changes: 5 additions & 2 deletions ChatLayout/Classes/Core/ChatLayoutPositionSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
// Created by Eugene Kazaev in 2020-2022.
// Distributed under the MIT license.
//
// Become a sponsor:
// https://github.com/sponsors/ekazaev
//

import Foundation
import UIKit

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

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

/// Top edge of the `UICollectionView`
case top
Expand Down
3 changes: 3 additions & 0 deletions ChatLayout/Classes/Core/ChatLayoutSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// Created by Eugene Kazaev in 2020-2022.
// Distributed under the MIT license.
//
// Become a sponsor:
// https://github.com/sponsors/ekazaev
//

import Foundation
import UIKit
Expand Down
21 changes: 12 additions & 9 deletions ChatLayout/Classes/Core/CollectionViewChatLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// Created by Eugene Kazaev in 2020-2022.
// Distributed under the MIT license.
//
// Become a sponsor:
// https://github.com/sponsors/ekazaev
//

import Foundation
import UIKit
Expand Down Expand Up @@ -82,22 +85,22 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {

/// The direction of the language you used when designing `CollectionViewChatLayout` layout.
public override var developmentLayoutDirection: UIUserInterfaceLayoutDirection {
return .leftToRight
.leftToRight
}

/// A Boolean value that indicates whether the horizontal coordinate system is automatically flipped at appropriate times.
public override var flipsHorizontallyInOppositeLayoutDirection: Bool {
return _flipsHorizontallyInOppositeLayoutDirection
_flipsHorizontallyInOppositeLayoutDirection
}

/// Custom layoutAttributesClass is `ChatLayoutAttributes`.
public override class var layoutAttributesClass: AnyClass {
return ChatLayoutAttributes.self
ChatLayoutAttributes.self
}

/// Custom invalidationContextClass is `ChatLayoutInvalidationContext`.
public override class var invalidationContextClass: AnyClass {
return ChatLayoutInvalidationContext.self
ChatLayoutInvalidationContext.self
}

/// The width and height of the collection view’s contents.
Expand Down Expand Up @@ -206,15 +209,15 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
/// system is automatically flipped at appropriate times. In practice, this is used to support
/// right-to-left layout.
public init(flipsHorizontallyInOppositeLayoutDirection: Bool = true) {
self._flipsHorizontallyInOppositeLayoutDirection = flipsHorizontallyInOppositeLayoutDirection
_flipsHorizontallyInOppositeLayoutDirection = flipsHorizontallyInOppositeLayoutDirection
super.init()
resetAttributesForPendingAnimations()
resetInvalidatedAttributes()
}

/// Returns an object initialized from data in a given unarchiver.
public required init?(coder aDecoder: NSCoder) {
self._flipsHorizontallyInOppositeLayoutDirection = true
_flipsHorizontallyInOppositeLayoutDirection = true
super.init(coder: aDecoder)
resetAttributesForPendingAnimations()
resetInvalidatedAttributes()
Expand Down Expand Up @@ -579,7 +582,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
}

guard let context = context as? ChatLayoutInvalidationContext else {
assertionFailure("`context` must be an instance of `ChatLayoutInvalidationContext`")
assertionFailure("`context` must be an instance of `ChatLayoutInvalidationContext`.")
return
}

Expand Down Expand Up @@ -945,11 +948,11 @@ extension CollectionViewChatLayout: ChatLayoutRepresentation {
}

func shouldPresentHeader(at sectionIndex: Int) -> Bool {
return delegate?.shouldPresentHeader(self, at: sectionIndex) ?? false
delegate?.shouldPresentHeader(self, at: sectionIndex) ?? false
}

func shouldPresentFooter(at sectionIndex: Int) -> Bool {
return delegate?.shouldPresentFooter(self, at: sectionIndex) ?? false
delegate?.shouldPresentFooter(self, at: sectionIndex) ?? false
}

}
Expand Down
9 changes: 6 additions & 3 deletions ChatLayout/Classes/Core/Extensions/CGRect+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@
// Created by Eugene Kazaev in 2020-2022.
// Distributed under the MIT license.
//
// Become a sponsor:
// https://github.com/sponsors/ekazaev
//

import Foundation
import UIKit

extension CGRect {

func equalRounded(to rect: CGRect) -> Bool {
return abs(origin.x - rect.origin.x) <= 1 &&
abs(origin.x - rect.origin.x) <= 1 &&
abs(origin.y - rect.origin.y) <= 1 &&
abs(size.width - rect.size.width) <= 1 &&
abs(size.height - rect.size.height) <= 1
}

var higherPoint: CGPoint {
return origin
origin
}

var lowerPoint: CGPoint {
return CGPoint(x: origin.x + size.width, y: origin.y + size.height)
CGPoint(x: origin.x + size.width, y: origin.y + size.height)
}

}
5 changes: 4 additions & 1 deletion ChatLayout/Classes/Core/Extensions/IndexPath+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
// Created by Eugene Kazaev in 2020-2022.
// Distributed under the MIT license.
//
// Become a sponsor:
// https://github.com/sponsors/ekazaev
//

import Foundation

extension IndexPath {

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

}
11 changes: 7 additions & 4 deletions ChatLayout/Classes/Core/Model/ChangeItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// Created by Eugene Kazaev in 2020-2022.
// Distributed under the MIT license.
//
// Become a sponsor:
// https://github.com/sponsors/ekazaev
//

import Foundation
import UIKit
Expand Down Expand Up @@ -47,7 +50,7 @@ enum ChangeItem: Equatable {
case .move:
guard let indexPathBeforeUpdate = indexPathBeforeUpdate,
let indexPathAfterUpdate = indexPathAfterUpdate else {
assertionFailure("`indexPathBeforeUpdate` and `indexPathAfterUpdate` cannot be `nil` for a `.move` update action")
assertionFailure("`indexPathBeforeUpdate` and `indexPathAfterUpdate` cannot be `nil` for a `.move` update action.")
return nil
}
if indexPathBeforeUpdate.item == NSNotFound, indexPathAfterUpdate.item == NSNotFound {
Expand All @@ -57,7 +60,7 @@ enum ChangeItem: Equatable {
}
case .insert:
guard let indexPath = indexPathAfterUpdate else {
assertionFailure("`indexPathAfterUpdate` cannot be `nil` for an `.insert` update action")
assertionFailure("`indexPathAfterUpdate` cannot be `nil` for an `.insert` update action.")
return nil
}
if indexPath.item == NSNotFound {
Expand All @@ -67,7 +70,7 @@ enum ChangeItem: Equatable {
}
case .delete:
guard let indexPath = indexPathBeforeUpdate else {
assertionFailure("`indexPathBeforeUpdate` cannot be `nil` for a `.delete` update action")
assertionFailure("`indexPathBeforeUpdate` cannot be `nil` for a `.delete` update action.")
return nil
}
if indexPath.item == NSNotFound {
Expand All @@ -77,7 +80,7 @@ enum ChangeItem: Equatable {
}
case .reload:
guard let indexPath = indexPathAfterUpdate else {
assertionFailure("`indexPathAfterUpdate` cannot be `nil` for a `.reload` update action")
assertionFailure("`indexPathAfterUpdate` cannot be `nil` for a `.reload` update action.")
return nil
}

Expand Down
7 changes: 5 additions & 2 deletions ChatLayout/Classes/Core/Model/ItemKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// Created by Eugene Kazaev in 2020-2022.
// Distributed under the MIT license.
//
// Become a sponsor:
// https://github.com/sponsors/ekazaev
//

import Foundation
import UIKit
Expand All @@ -29,7 +32,7 @@ public enum ItemKind: CaseIterable, Hashable {
case UICollectionView.elementKindSectionFooter:
self = .footer
default:
preconditionFailure("Unsupported supplementary view kind")
preconditionFailure("Unsupported supplementary view kind.")
}
}

Expand All @@ -46,7 +49,7 @@ public enum ItemKind: CaseIterable, Hashable {
var supplementaryElementStringType: String {
switch self {
case .cell:
preconditionFailure("Cell type is not a supplementary view")
preconditionFailure("Cell type is not a supplementary view.")
case .header:
return UICollectionView.elementKindSectionHeader
case .footer:
Expand Down
Loading

0 comments on commit 88cbfc1

Please sign in to comment.