Skip to content

Commit ac4a9f4

Browse files
authored
Fix for IOS15 behaviour. Merge pull request #25 from ekazaev/feature/fix_ios15
Fix for IOS15 behaviour
2 parents 6655b5e + dfe19b1 commit ac4a9f4

File tree

99 files changed

+2938
-2729
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2938
-2729
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,4 @@ fastlane/test_output
8989

9090
iOSInjectionProject/
9191
Example/Pods
92+
Gemfile.lock

ChatLayout.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'ChatLayout'
3-
s.version = '1.1.9'
3+
s.version = '1.1.10'
44
s.summary = 'Chat UI Library. It uses custom UICollectionViewLayout to provide you full control over the presentation.'
55
s.swift_version = '5.2'
66

ChatLayout/Classes/Core/ChatLayout.swift

+8-14
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,14 @@ public final class ChatLayout: UICollectionViewLayout {
101101

102102
/// The width and height of the collection view’s contents.
103103
public override var collectionViewContentSize: CGSize {
104-
let contentSize = controller.contentSize(for: .beforeUpdate)
104+
let contentSize: CGSize
105+
if state == .beforeUpdate {
106+
contentSize = controller.contentSize(for: .beforeUpdate)
107+
} else {
108+
var size = controller.contentSize(for: .beforeUpdate)
109+
size.height += controller.totalProposedCompensatingOffset
110+
contentSize = size
111+
}
105112
return contentSize
106113
}
107114

@@ -637,10 +644,6 @@ public final class ChatLayout: UICollectionViewLayout {
637644
controller.batchUpdateCompensatingOffset = 0
638645
let context = ChatLayoutInvalidationContext()
639646
context.contentOffsetAdjustment.y = compensatingOffset
640-
if !isIOS15orHigher {
641-
let contentHeightAdjustment: CGFloat = controller.contentSize(for: .afterUpdate).height - controller.contentSize(for: .beforeUpdate).height
642-
context.contentSizeAdjustment.height = contentHeightAdjustment
643-
}
644647
invalidateLayout(with: context)
645648
} else {
646649
controller.batchUpdateCompensatingOffset = 0
@@ -946,12 +949,3 @@ var isIOS13orHigher: Bool {
946949
return false
947950
}
948951
}
949-
950-
@inline(__always)
951-
var isIOS15orHigher: Bool {
952-
if #available(iOS 15.0, *) {
953-
return true
954-
} else {
955-
return false
956-
}
957-
}

Example/ChatLayout/Chat/View/ChatViewController.swift

+4-6
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ final class ChatViewController: UIViewController {
2929
case scrollingToBottom
3030
case showingPreview
3131
case showingAccessory
32-
case updatingCollection
3332
}
3433

3534
private enum ControllerActions {
3635
case loadingInitialMessages
3736
case loadingPreviousMessages
37+
case updatingCollection
3838
}
3939

4040
override var inputAccessoryView: UIView? {
@@ -377,7 +377,7 @@ extension ChatViewController: UICollectionViewDelegate {
377377
@available(iOS 13.0, *)
378378
func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
379379
guard !currentInterfaceActions.options.contains(.showingPreview),
380-
!currentInterfaceActions.options.contains(.updatingCollection) else {
380+
!currentControllerActions.options.contains(.updatingCollection) else {
381381
return nil
382382
}
383383
let item = dataSource.sections[indexPath.section].cells[indexPath.item]
@@ -442,9 +442,7 @@ extension ChatViewController: ChatControllerDelegate {
442442
// Here is on the main thread for the simplicity.
443443
let changeSet = StagedChangeset(source: dataSource.sections, target: sections).flattenIfPossible()
444444

445-
// In IOS 15 Apple as usual broke something in the UICollectionViewLayout and if simultaneous updates happen when the previous animation is not finished,
446-
// it doesnt caclulate content offset correctly. So we are blocking processing changes whilest the previoues batch update is in progress.
447-
currentInterfaceActions.options.insert(.updatingCollection)
445+
currentControllerActions.options.insert(.updatingCollection)
448446

449447
collectionView.reload(using: changeSet,
450448
interrupt: { changeSet in
@@ -462,7 +460,7 @@ extension ChatViewController: ChatControllerDelegate {
462460
completion: { _ in
463461
DispatchQueue.main.async {
464462
completion?()
465-
self.currentInterfaceActions.options.remove(.updatingCollection)
463+
self.currentControllerActions.options.remove(.updatingCollection)
466464
}
467465
},
468466
setData: { data in

Example/Podfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ SPEC CHECKSUMS:
4242

4343
PODFILE CHECKSUM: 8c714139f0a07a1f2169fe35aa2829ae446d122a
4444

45-
COCOAPODS: 1.10.1
45+
COCOAPODS: 1.11.2

Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
source "https://rubygems.org"
22

33
gem "slather", "2.6.1"
4-
gem "cocoapods"
4+
gem "cocoapods"
5+
gem "jazzy"

Gemfile.lock

-106
This file was deleted.

README.md

-7
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
- [About Supplementary Views](#about-supplementary-views)
3434
- [About Texture](#about-texture)
3535
- [About animation](#about-animation)
36-
- [About IOS 15 Beta](#about-ios-15-beta)
3736
- [License](#license)
3837
- [Articles](#articles)
3938
- [Author](#author)
@@ -148,12 +147,6 @@ It is very possible that you are sending delete/insert commands when you expect
148147
`print("\(updateItems)")` into `ChatLayout.prepare(forCollectionViewUpdates:)` method. `ChatLayout` doesn't know what you expected to see.
149148
It just processes your changes according to the commands it has received.
150149

151-
### About IOS 15 Beta
152-
153-
It seems that in the latest release of IOS 15 it is impossible to call `UICollectionView`'s `performBatchUpdates` while
154-
another is still processing animation and keep the content offset in the correct place. Please check to the Example
155-
app `ChatViewController` how to avoid that issue.
156-
157150
## License
158151

159152
`ChatLayout` is distributed under [the MIT license](https://github.com/ekazaev/ChatLayout/blob/master/LICENSE).

docs/Classes/CellLayoutContainerView.html

+6-7
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@
2121
<header class="header">
2222
<p class="header-col header-col--primary">
2323
<a class="header-link" href="../index.html">
24-
ChatLayout 1.1.8 Docs
24+
ChatLayout 1.1.10 Docs
2525
</a>
2626
(100% documented)
2727
</p>
2828

29-
<p class="header-col--secondary">
29+
<div class="header-col--secondary">
3030
<form role="search" action="../search.json">
3131
<input type="text" placeholder="Search documentation" data-typeahead>
3232
</form>
33-
</p>
33+
</div>
3434

3535

3636
</header>
3737

3838
<p class="breadcrumbs">
3939
<a class="breadcrumb" href="../index.html">ChatLayout Reference</a>
40-
<img class="carat" src="../img/carat.png" />
40+
<img class="carat" src="../img/carat.png" alt=""/>
4141
CellLayoutContainerView Class Reference
4242
</p>
4343

@@ -457,9 +457,8 @@ <h4>Parameters</h4>
457457
</article>
458458
</div>
459459
<section class="footer">
460-
<p>&copy; 2021 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2021-05-15)</p>
461-
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
460+
<p>&copy; 2021 <a class="link" href="https://github.com/ekazaev" target="_blank" rel="external noopener">Evgeny Kazaev</a>. All rights reserved. (Last updated: 2021-10-07)</p>
461+
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
462462
</section>
463463
</body>
464-
</div>
465464
</html>

0 commit comments

Comments
 (0)