@@ -19,6 +19,7 @@ typealias TextMessageCollectionCell = ContainerCollectionViewCell<MessageContain
19
19
typealias URLCollectionCell = ContainerCollectionViewCell < MessageContainerView < EditingAccessoryView , MainContainerView < AvatarView , URLView , StatusView > > >
20
20
typealias ImageCollectionCell = ContainerCollectionViewCell < MessageContainerView < EditingAccessoryView , MainContainerView < AvatarView , ImageView , StatusView > > >
21
21
typealias TitleCollectionCell = ContainerCollectionViewCell < UILabel >
22
+ typealias UserTitleCollectionCell = ContainerCollectionViewCell < SwappingContainerView < EdgeAligningView < UILabel > , UIImageView > >
22
23
typealias TypingIndicatorCollectionCell = ContainerCollectionViewCell < MessageContainerView < EditingAccessoryView , MainContainerView < AvatarPlaceholderView , TextMessageView , VoidViewFactory > > >
23
24
24
25
typealias TextTitleView = ContainerCollectionReusableView < UILabel >
@@ -55,6 +56,7 @@ final class DefaultChatCollectionDataSource: NSObject, ChatCollectionDataSource
55
56
collectionView. register ( TextMessageCollectionCell . self, forCellWithReuseIdentifier: TextMessageCollectionCell . reuseIdentifier)
56
57
collectionView. register ( ImageCollectionCell . self, forCellWithReuseIdentifier: ImageCollectionCell . reuseIdentifier)
57
58
collectionView. register ( TitleCollectionCell . self, forCellWithReuseIdentifier: TitleCollectionCell . reuseIdentifier)
59
+ collectionView. register ( UserTitleCollectionCell . self, forCellWithReuseIdentifier: UserTitleCollectionCell . reuseIdentifier)
58
60
collectionView. register ( TypingIndicatorCollectionCell . self, forCellWithReuseIdentifier: TypingIndicatorCollectionCell . reuseIdentifier)
59
61
collectionView. register ( TextTitleView . self, forSupplementaryViewOfKind: UICollectionView . elementKindSectionHeader, withReuseIdentifier: TextTitleView . reuseIdentifier)
60
62
collectionView. register ( TextTitleView . self, forSupplementaryViewOfKind: UICollectionView . elementKindSectionFooter, withReuseIdentifier: TextTitleView . reuseIdentifier)
@@ -139,13 +141,35 @@ final class DefaultChatCollectionDataSource: NSObject, ChatCollectionDataSource
139
141
return cell
140
142
}
141
143
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
+ }
149
173
cell. contentView. layoutMargins = UIEdgeInsets ( top: 2 , left: 40 , bottom: 2 , right: 40 )
150
174
return cell
151
175
}
0 commit comments