Skip to content

Commit

Permalink
Fix for IOS15 behaviour. Merge pull request #25 from ekazaev/feature/…
Browse files Browse the repository at this point in the history
…fix_ios15

Fix for IOS15 behaviour
  • Loading branch information
ekazaev authored Oct 7, 2021
2 parents 6655b5e + dfe19b1 commit ac4a9f4
Show file tree
Hide file tree
Showing 99 changed files with 2,938 additions and 2,729 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ fastlane/test_output

iOSInjectionProject/
Example/Pods
Gemfile.lock
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.1.9'
s.version = '1.1.10'
s.summary = 'Chat UI Library. It uses custom UICollectionViewLayout to provide you full control over the presentation.'
s.swift_version = '5.2'

Expand Down
22 changes: 8 additions & 14 deletions ChatLayout/Classes/Core/ChatLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ public final class ChatLayout: UICollectionViewLayout {

/// The width and height of the collection view’s contents.
public override var collectionViewContentSize: CGSize {
let contentSize = controller.contentSize(for: .beforeUpdate)
let contentSize: CGSize
if state == .beforeUpdate {
contentSize = controller.contentSize(for: .beforeUpdate)
} else {
var size = controller.contentSize(for: .beforeUpdate)
size.height += controller.totalProposedCompensatingOffset
contentSize = size
}
return contentSize
}

Expand Down Expand Up @@ -637,10 +644,6 @@ public final class ChatLayout: UICollectionViewLayout {
controller.batchUpdateCompensatingOffset = 0
let context = ChatLayoutInvalidationContext()
context.contentOffsetAdjustment.y = compensatingOffset
if !isIOS15orHigher {
let contentHeightAdjustment: CGFloat = controller.contentSize(for: .afterUpdate).height - controller.contentSize(for: .beforeUpdate).height
context.contentSizeAdjustment.height = contentHeightAdjustment
}
invalidateLayout(with: context)
} else {
controller.batchUpdateCompensatingOffset = 0
Expand Down Expand Up @@ -946,12 +949,3 @@ var isIOS13orHigher: Bool {
return false
}
}

@inline(__always)
var isIOS15orHigher: Bool {
if #available(iOS 15.0, *) {
return true
} else {
return false
}
}
10 changes: 4 additions & 6 deletions Example/ChatLayout/Chat/View/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ final class ChatViewController: UIViewController {
case scrollingToBottom
case showingPreview
case showingAccessory
case updatingCollection
}

private enum ControllerActions {
case loadingInitialMessages
case loadingPreviousMessages
case updatingCollection
}

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

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

collectionView.reload(using: changeSet,
interrupt: { changeSet in
Expand All @@ -462,7 +460,7 @@ extension ChatViewController: ChatControllerDelegate {
completion: { _ in
DispatchQueue.main.async {
completion?()
self.currentInterfaceActions.options.remove(.updatingCollection)
self.currentControllerActions.options.remove(.updatingCollection)
}
},
setData: { data in
Expand Down
2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 8c714139f0a07a1f2169fe35aa2829ae446d122a

COCOAPODS: 1.10.1
COCOAPODS: 1.11.2
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source "https://rubygems.org"

gem "slather", "2.6.1"
gem "cocoapods"
gem "cocoapods"
gem "jazzy"
106 changes: 0 additions & 106 deletions Gemfile.lock

This file was deleted.

7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
- [About Supplementary Views](#about-supplementary-views)
- [About Texture](#about-texture)
- [About animation](#about-animation)
- [About IOS 15 Beta](#about-ios-15-beta)
- [License](#license)
- [Articles](#articles)
- [Author](#author)
Expand Down Expand Up @@ -148,12 +147,6 @@ It is very possible that you are sending delete/insert commands when you expect
`print("\(updateItems)")` into `ChatLayout.prepare(forCollectionViewUpdates:)` method. `ChatLayout` doesn't know what you expected to see.
It just processes your changes according to the commands it has received.

### About IOS 15 Beta

It seems that in the latest release of IOS 15 it is impossible to call `UICollectionView`'s `performBatchUpdates` while
another is still processing animation and keep the content offset in the correct place. Please check to the Example
app `ChatViewController` how to avoid that issue.

## License

`ChatLayout` is distributed under [the MIT license](https://github.com/ekazaev/ChatLayout/blob/master/LICENSE).
Expand Down
13 changes: 6 additions & 7 deletions docs/Classes/CellLayoutContainerView.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
ChatLayout 1.1.8 Docs
ChatLayout 1.1.10 Docs
</a>
(100% documented)
</p>

<p class="header-col--secondary">
<div class="header-col--secondary">
<form role="search" action="../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
</form>
</p>
</div>


</header>

<p class="breadcrumbs">
<a class="breadcrumb" href="../index.html">ChatLayout Reference</a>
<img class="carat" src="../img/carat.png" />
<img class="carat" src="../img/carat.png" alt=""/>
CellLayoutContainerView Class Reference
</p>

Expand Down Expand Up @@ -457,9 +457,8 @@ <h4>Parameters</h4>
</article>
</div>
<section class="footer">
<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>
<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>
<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>
<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>
</section>
</body>
</div>
</html>
Loading

0 comments on commit ac4a9f4

Please sign in to comment.