Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ekazaev committed Jun 30, 2023
1 parent 4678e7b commit d21a06c
Show file tree
Hide file tree
Showing 74 changed files with 176 additions and 147 deletions.
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.3.0'
s.version = '1.3.1'
s.summary = 'Chat UI Library. It uses custom UICollectionViewLayout to provide you full control over the presentation.'
s.swift_version = '5.8'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ extension RandomAccessCollection where Index == Int {

while lowerBound < upperBound {
let midIndex = lowerBound &+ (upperBound &- lowerBound) / 2
if predicate(self[midIndex]) == .orderedSame {
let result = predicate(self[midIndex])
if result == .orderedSame {
return midIndex
} else if predicate(self[midIndex]) == .orderedAscending {
} else if result == .orderedAscending {
lowerBound = midIndex &+ 1
} else {
upperBound = midIndex
Expand Down
8 changes: 4 additions & 4 deletions ChatLayout/Classes/Core/Model/StateController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ final class StateController<Layout: ChatLayoutRepresentation> {
let predicate: (ChatLayoutAttributes) -> ComparisonResult = { attributes in
if attributes.frame.intersects(rect) {
return .orderedSame
} else if attributes.frame.minY > rect.maxY {
} else if attributes.frame.minY >= rect.maxY {
return .orderedDescending
} else if attributes.frame.maxY < rect.minY {
} else if attributes.frame.maxY <= rect.minY {
return .orderedAscending
}
return .orderedSame
Expand Down Expand Up @@ -835,9 +835,9 @@ final class StateController<Layout: ChatLayoutRepresentation> {
}
if itemFrame.intersects(visibleRect) {
return .orderedSame
} else if itemFrame.minY > visibleRect.maxY {
} else if itemFrame.minY >= visibleRect.maxY {
return .orderedDescending
} else if itemFrame.maxX < visibleRect.minY {
} else if itemFrame.maxX <= visibleRect.minY {
return .orderedAscending
}
return .orderedSame
Expand Down
12 changes: 6 additions & 6 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
PODS:
- ChatLayout (1.3.0):
- ChatLayout/Ultimate (= 1.3.0)
- ChatLayout/Core (1.3.0)
- ChatLayout/Extras (1.3.0):
- ChatLayout (1.3.1):
- ChatLayout/Ultimate (= 1.3.1)
- ChatLayout/Core (1.3.1)
- ChatLayout/Extras (1.3.1):
- ChatLayout/Core
- ChatLayout/Ultimate (1.3.0):
- ChatLayout/Ultimate (1.3.1):
- ChatLayout/Core
- ChatLayout/Extras
- DifferenceKit (1.3.0):
Expand Down Expand Up @@ -35,7 +35,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
ChatLayout: 620aaa4cf30ce188cef80eb1dad391c9c250c5e2
ChatLayout: 7ce4d2a769cd48ce69481bf951fa3c73cec2063f
DifferenceKit: ab185c4d7f9cef8af3fcf593e5b387fb81e999ca
FPSCounter: 884afec377de66637808c4f52ecc3b85a404732b
InputBarAccessoryView: 1d7b0a672b36e370f01f264b3907ef39d03328e3
Expand Down
28 changes: 28 additions & 0 deletions Example/Tests/HelpersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ final class HelpersTests: XCTestCase {
XCTAssertEqual((150...170).map { $0 }.binarySearch(predicate: predicate), nil)
}

func testBinarySearchWithCGRect() {
let visibleRect = CGRect(origin: .init(x: 0, y: 100), size: .init(width: 100, height: 100))
let predicate: (CGRect) -> ComparisonResult = { frame in
if frame.intersects(visibleRect) {
return .orderedSame
} else if frame.minY >= visibleRect.maxY {
return .orderedDescending
} else if frame.maxX <= visibleRect.minY {
return .orderedAscending
}
XCTFail("Should not get here")
return .orderedSame
}
XCTAssertEqual([CGRect]().binarySearch(predicate: predicate), nil)
XCTAssertEqual((0...5).map { CGRect(origin: .init(x: 0, y: $0 * 50), size: .init(width: 100, height: 50)) }.binarySearch(predicate: predicate), 3)
XCTAssertEqual((-1...1).map { CGRect(origin: .init(x: 0, y: $0 * 50), size: .init(width: 100, height: 50)) }.binarySearch(predicate: predicate), nil)
XCTAssertEqual((1...1).map { CGRect(origin: .init(x: 0, y: $0 * 50), size: .init(width: 100, height: 50)) }.binarySearch(predicate: predicate), nil)
XCTAssertEqual((4...7).map { CGRect(origin: .init(x: 0, y: $0 * 50), size: .init(width: 100, height: 50)) }.binarySearch(predicate: predicate), nil)
XCTAssertEqual((4...4).map { CGRect(origin: .init(x: 0, y: $0 * 50), size: .init(width: 100, height: 50)) }.binarySearch(predicate: predicate), nil)

XCTAssertEqual([CGRect]().binarySearchRange(predicate: predicate), [])
XCTAssertEqual((0...5).map { CGRect(origin: .init(x: 0, y: $0 * 50), size: .init(width: 100, height: 50)) }.binarySearchRange(predicate: predicate).count, 2)
XCTAssertEqual((-1...1).map { CGRect(origin: .init(x: 0, y: $0 * 50), size: .init(width: 100, height: 50)) }.binarySearchRange(predicate: predicate).count, 0)
XCTAssertEqual((1...1).map { CGRect(origin: .init(x: 0, y: $0 * 50), size: .init(width: 100, height: 50)) }.binarySearchRange(predicate: predicate).count, 0)
XCTAssertEqual((4...7).map { CGRect(origin: .init(x: 0, y: $0 * 50), size: .init(width: 100, height: 50)) }.binarySearchRange(predicate: predicate).count, 0)
XCTAssertEqual((4...4).map { CGRect(origin: .init(x: 0, y: $0 * 50), size: .init(width: 100, height: 50)) }.binarySearchRange(predicate: predicate).count, 0)
}

func testSearchInRange() {
let predicate: (Int) -> ComparisonResult = { integer in
if integer < 100 {
Expand Down
2 changes: 1 addition & 1 deletion Example/Tests/PerformanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ final class PerformanceTests: XCTestCase {

let rect = CGRect(origin: CGPoint(x: 0, y: 99999), size: CGSize(width: 300, height: 2))
let attributes = layout.controller.layoutAttributesForElements(in: rect, state: .beforeUpdate, ignoreCache: true)
XCTAssertEqual(attributes.count, 4)
XCTAssertEqual(attributes.count, 2)
measure {
for _ in 0..<10 {
_ = layout.controller.layoutAttributesForElements(in: rect, state: .beforeUpdate, ignoreCache: true)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source "https://rubygems.org"

gem "slather", "2.6.1"
gem "slather", "2.7.4"
gem "cocoapods"
gem "jazzy"
4 changes: 2 additions & 2 deletions docs/Classes/CellLayoutContainerView.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
ChatLayout 1.3.0 Docs
ChatLayout 1.3.1 Docs
</a>
(100% documented)
</p>
Expand Down Expand Up @@ -464,7 +464,7 @@ <h4>Parameters</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-05-19)</p>
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-06-30)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/ChatLayoutAttributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
ChatLayout 1.3.0 Docs
ChatLayout 1.3.1 Docs
</a>
(100% documented)
</p>
Expand Down Expand Up @@ -423,7 +423,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-05-19)</p>
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-06-30)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/ChatLayoutInvalidationContext.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
ChatLayout 1.3.0 Docs
ChatLayout 1.3.1 Docs
</a>
(100% documented)
</p>
Expand Down Expand Up @@ -208,7 +208,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-05-19)</p>
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-06-30)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/CollectionViewChatLayout.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
ChatLayout 1.3.0 Docs
ChatLayout 1.3.1 Docs
</a>
(100% documented)
</p>
Expand Down Expand Up @@ -1354,7 +1354,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-05-19)</p>
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-06-30)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/ContainerCollectionReusableView.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
ChatLayout 1.3.0 Docs
ChatLayout 1.3.1 Docs
</a>
(100% documented)
</p>
Expand Down Expand Up @@ -384,7 +384,7 @@ <h4>Parameters</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-05-19)</p>
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-06-30)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/ContainerCollectionViewCell.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
ChatLayout 1.3.0 Docs
ChatLayout 1.3.1 Docs
</a>
(100% documented)
</p>
Expand Down Expand Up @@ -384,7 +384,7 @@ <h4>Parameters</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-05-19)</p>
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-06-30)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/EdgeAligningView.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
ChatLayout 1.3.0 Docs
ChatLayout 1.3.1 Docs
</a>
(100% documented)
</p>
Expand Down Expand Up @@ -536,7 +536,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-05-19)</p>
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-06-30)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/EdgeAligningView/Edge.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../../index.html">
ChatLayout 1.3.0 Docs
ChatLayout 1.3.1 Docs
</a>
(100% documented)
</p>
Expand Down Expand Up @@ -288,7 +288,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-05-19)</p>
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-06-30)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/ImageMaskedView.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
ChatLayout 1.3.0 Docs
ChatLayout 1.3.1 Docs
</a>
(100% documented)
</p>
Expand Down Expand Up @@ -408,7 +408,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-05-19)</p>
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-06-30)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/MessageContainerView.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
ChatLayout 1.3.0 Docs
ChatLayout 1.3.1 Docs
</a>
(100% documented)
</p>
Expand Down Expand Up @@ -354,7 +354,7 @@ <h4>Parameters</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-05-19)</p>
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-06-30)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/RoundedCornersContainerView.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
ChatLayout 1.3.0 Docs
ChatLayout 1.3.1 Docs
</a>
(100% documented)
</p>
Expand Down Expand Up @@ -354,7 +354,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-05-19)</p>
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-06-30)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/SwappingContainerView.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
ChatLayout 1.3.0 Docs
ChatLayout 1.3.1 Docs
</a>
(100% documented)
</p>
Expand Down Expand Up @@ -599,7 +599,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-05-19)</p>
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-06-30)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/SwappingContainerView/Axis.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../../index.html">
ChatLayout 1.3.0 Docs
ChatLayout 1.3.1 Docs
</a>
(100% documented)
</p>
Expand Down Expand Up @@ -234,7 +234,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-05-19)</p>
<p>&copy; 2023 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2023-06-30)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</body>
Expand Down
Loading

0 comments on commit d21a06c

Please sign in to comment.