Skip to content

Commit a7afd37

Browse files
committed
Updated example app to demo SwappingContainerView
1 parent c3abbbb commit a7afd37

File tree

76 files changed

+559
-298
lines changed

Some content is hidden

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

76 files changed

+559
-298
lines changed

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.2.20'
3+
s.version = '1.2.21'
44
s.summary = 'Chat UI Library. It uses custom UICollectionViewLayout to provide you full control over the presentation.'
55
s.swift_version = '5.8'
66

ChatLayout/Classes/Extras/EdgeAligningView.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ public final class EdgeAligningView<CustomView: UIView>: UIView {
123123
fatalError("Use init(with:flexibleEdges:) instead.")
124124
}
125125

126+
/// A Boolean value that indicates whether the receiver depends on the constraint-based layout system.
127+
public override class var requiresConstraintBasedLayout: Bool {
128+
true
129+
}
130+
126131
/// Updates constraints for the view.
127132
public override func updateConstraints() {
128133
guard lastConstraintsUpdateEdges != flexibleEdges else {
@@ -160,7 +165,7 @@ public final class EdgeAligningView<CustomView: UIView>: UIView {
160165
}
161166
customView.translatesAutoresizingMaskIntoConstraints = false
162167
if !addedConstraints.isEmpty {
163-
removeConstraints(addedConstraints)
168+
NSLayoutConstraint.deactivate(addedConstraints)
164169
addedConstraints.removeAll()
165170
}
166171

ChatLayout/Classes/Extras/Extensions/NSLayoutAnchor+Extension.swift

+4
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ extension NSLayoutAnchor {
3838
return constraint
3939
}
4040
}
41+
42+
extension UILayoutPriority {
43+
static let almostRequired = UILayoutPriority(rawValue: UILayoutPriority.required.rawValue - 1)
44+
}

ChatLayout/Classes/Extras/SwappingContainerView.swift

+241-201
Large diffs are not rendered by default.

Example/ChatLayout/Chat/View/Data Source/DefaultChatCollectionDataSource.swift

+31-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ typealias TextMessageCollectionCell = ContainerCollectionViewCell<MessageContain
1919
typealias URLCollectionCell = ContainerCollectionViewCell<MessageContainerView<EditingAccessoryView, MainContainerView<AvatarView, URLView, StatusView>>>
2020
typealias ImageCollectionCell = ContainerCollectionViewCell<MessageContainerView<EditingAccessoryView, MainContainerView<AvatarView, ImageView, StatusView>>>
2121
typealias TitleCollectionCell = ContainerCollectionViewCell<UILabel>
22+
typealias UserTitleCollectionCell = ContainerCollectionViewCell<SwappingContainerView<EdgeAligningView<UILabel>, UIImageView>>
2223
typealias TypingIndicatorCollectionCell = ContainerCollectionViewCell<MessageContainerView<EditingAccessoryView, MainContainerView<AvatarPlaceholderView, TextMessageView, VoidViewFactory>>>
2324

2425
typealias TextTitleView = ContainerCollectionReusableView<UILabel>
@@ -55,6 +56,7 @@ final class DefaultChatCollectionDataSource: NSObject, ChatCollectionDataSource
5556
collectionView.register(TextMessageCollectionCell.self, forCellWithReuseIdentifier: TextMessageCollectionCell.reuseIdentifier)
5657
collectionView.register(ImageCollectionCell.self, forCellWithReuseIdentifier: ImageCollectionCell.reuseIdentifier)
5758
collectionView.register(TitleCollectionCell.self, forCellWithReuseIdentifier: TitleCollectionCell.reuseIdentifier)
59+
collectionView.register(UserTitleCollectionCell.self, forCellWithReuseIdentifier: UserTitleCollectionCell.reuseIdentifier)
5860
collectionView.register(TypingIndicatorCollectionCell.self, forCellWithReuseIdentifier: TypingIndicatorCollectionCell.reuseIdentifier)
5961
collectionView.register(TextTitleView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: TextTitleView.reuseIdentifier)
6062
collectionView.register(TextTitleView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: TextTitleView.reuseIdentifier)
@@ -139,13 +141,35 @@ final class DefaultChatCollectionDataSource: NSObject, ChatCollectionDataSource
139141
return cell
140142
}
141143

142-
private func createGroupTitle(collectionView: UICollectionView, indexPath: IndexPath, alignment: ChatItemAlignment, title: String) -> TitleCollectionCell {
143-
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: TitleCollectionCell.reuseIdentifier, for: indexPath) as! TitleCollectionCell
144-
cell.customView.text = title
145-
cell.customView.preferredMaxLayoutWidth = (collectionView.collectionViewLayout as? CollectionViewChatLayout)?.layoutFrame.width ?? collectionView.frame.width
146-
cell.customView.textColor = .gray
147-
cell.customView.numberOfLines = 0
148-
cell.customView.font = .preferredFont(forTextStyle: .caption2)
144+
private func createGroupTitle(collectionView: UICollectionView, indexPath: IndexPath, alignment: ChatItemAlignment, title: String) -> UserTitleCollectionCell {
145+
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: UserTitleCollectionCell.reuseIdentifier, for: indexPath) as! UserTitleCollectionCell
146+
cell.customView.spacing = 2
147+
148+
cell.customView.customView.customView.text = title
149+
cell.customView.customView.customView.preferredMaxLayoutWidth = (collectionView.collectionViewLayout as? CollectionViewChatLayout)?.layoutFrame.width ?? collectionView.frame.width
150+
cell.customView.customView.customView.textColor = .gray
151+
cell.customView.customView.customView.numberOfLines = 0
152+
cell.customView.customView.customView.font = .preferredFont(forTextStyle: .caption2)
153+
cell.customView.customView.flexibleEdges = [.top]
154+
155+
cell.customView.accessoryView.contentMode = .scaleAspectFit
156+
cell.customView.accessoryView.tintColor = .gray
157+
cell.customView.accessoryView.translatesAutoresizingMaskIntoConstraints = false
158+
if #available(iOS 13.0, *) {
159+
if cell.customView.accessoryView.image == nil {
160+
cell.customView.accessoryView.image = UIImage(systemName: "person")
161+
let constraints = [
162+
cell.customView.accessoryView.widthAnchor.constraint(equalTo: cell.customView.accessoryView.heightAnchor),
163+
cell.customView.accessoryView.heightAnchor.constraint(equalTo: cell.customView.customView.customView.heightAnchor, constant: 2)
164+
]
165+
constraints.forEach { $0.priority = UILayoutPriority(rawValue: 999) }
166+
cell.customView.customView.customView.setContentHuggingPriority(.required, for: .vertical)
167+
cell.customView.accessoryView.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
168+
NSLayoutConstraint.activate(constraints)
169+
}
170+
} else {
171+
cell.customView.accessoryView.isHidden = true
172+
}
149173
cell.contentView.layoutMargins = UIEdgeInsets(top: 2, left: 40, bottom: 2, right: 40)
150174
return cell
151175
}

Example/Podfile.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
PODS:
2-
- ChatLayout (1.2.20):
3-
- ChatLayout/Ultimate (= 1.2.20)
4-
- ChatLayout/Core (1.2.20)
5-
- ChatLayout/Extras (1.2.20):
2+
- ChatLayout (1.2.21):
3+
- ChatLayout/Ultimate (= 1.2.21)
4+
- ChatLayout/Core (1.2.21)
5+
- ChatLayout/Extras (1.2.21):
66
- ChatLayout/Core
7-
- ChatLayout/Ultimate (1.2.20):
7+
- ChatLayout/Ultimate (1.2.21):
88
- ChatLayout/Core
99
- ChatLayout/Extras
1010
- DifferenceKit (1.3.0):
@@ -35,7 +35,7 @@ EXTERNAL SOURCES:
3535
:path: "../"
3636

3737
SPEC CHECKSUMS:
38-
ChatLayout: 6c92dd2c744e32f89310cad07bd1f4a61005be9d
38+
ChatLayout: 41e1c411b8e32210df9f335ccf93a3ac30a861c5
3939
DifferenceKit: ab185c4d7f9cef8af3fcf593e5b387fb81e999ca
4040
FPSCounter: 884afec377de66637808c4f52ecc3b85a404732b
4141
InputBarAccessoryView: 1d7b0a672b36e370f01f264b3907ef39d03328e3

docs/Classes/CellLayoutContainerView.html

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

docs/Classes/ChatLayoutAttributes.html

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

docs/Classes/ChatLayoutInvalidationContext.html

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

docs/Classes/CollectionViewChatLayout.html

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

docs/Classes/ContainerCollectionReusableView.html

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

docs/Classes/ContainerCollectionViewCell.html

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

docs/Classes/EdgeAligningView.html

+28-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<header class="header">
2222
<p class="header-col header-col--primary">
2323
<a class="header-link" href="../index.html">
24-
ChatLayout 1.2.20 Docs
24+
ChatLayout 1.2.21 Docs
2525
</a>
2626
(100% documented)
2727
</p>
@@ -474,6 +474,33 @@ <h4>Parameters</h4>
474474
</section>
475475
</div>
476476
</li>
477+
<li class="item">
478+
<div>
479+
<code>
480+
<a name="/s:10ChatLayout16EdgeAligningViewC023requiresConstraintBasedB0SbvpZ"></a>
481+
<a name="//apple_ref/swift/Variable/requiresConstraintBasedLayout" class="dashAnchor"></a>
482+
<a class="token" href="#/s:10ChatLayout16EdgeAligningViewC023requiresConstraintBasedB0SbvpZ">requiresConstraintBasedLayout</a>
483+
</code>
484+
</div>
485+
<div class="height-container">
486+
<div class="pointer-container"></div>
487+
<section class="section">
488+
<div class="pointer"></div>
489+
<div class="abstract">
490+
<p>A Boolean value that indicates whether the receiver depends on the constraint-based layout system.</p>
491+
492+
</div>
493+
<div class="declaration">
494+
<h4>Declaration</h4>
495+
<div class="language">
496+
<p class="aside-title">Swift</p>
497+
<pre class="highlight swift"><code><span class="kd">public</span> <span class="k">override</span> <span class="kd">class</span> <span class="k">var</span> <span class="nv">requiresConstraintBasedLayout</span><span class="p">:</span> <span class="kt">Bool</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre>
498+
499+
</div>
500+
</div>
501+
</section>
502+
</div>
503+
</li>
477504
<li class="item">
478505
<div>
479506
<code>

docs/Classes/EdgeAligningView/Edge.html

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

docs/Classes/ImageMaskedView.html

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

docs/Classes/MessageContainerView.html

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

docs/Classes/RoundedCornersContainerView.html

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

0 commit comments

Comments
 (0)