-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Use table view in message list * Set `needsLayout` when base views change content * Fix gallery view layout issue * Implement keyboard avoidance * Updates and selection * Fix scrolling indicator being on the left * Fix missing scroll overlay * Fix missing scroll to bottom button * Fix message cell background color * Fix threads * Dismiss message actions pop-up after reaction * Put back advanced typing indicators handling * Fix scroll to bottom button visibility issues * Fix animations for message list updates * Remove collection view leftovers * Step out from table view mentioning in type names * Fix handling the spacing between rows * Update UI snapshots * Update CHANGELOG Co-authored-by: Vojta Stavik <stavik@outlook.com>
- Loading branch information
1 parent
49ccd37
commit f4668db
Showing
21 changed files
with
423 additions
and
941 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
Sources/StreamChatUI/ChatMessageList/ChatMessage/ChatMessageCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// Copyright © 2021 Stream.io Inc. All rights reserved. | ||
// | ||
|
||
import StreamChat | ||
import UIKit | ||
|
||
/// The cell that displays the message content of a dynamic type and layout. | ||
/// Once the cell is set up it is expected to be dequeued for messages with | ||
/// the same content and layout the cell has already been configured with. | ||
public typealias ChatMessageCell = _ChatMessageCell<NoExtraData> | ||
|
||
/// The cell that displays the message content of a dynamic type and layout. | ||
/// Once the cell is set up it is expected to be dequeued for messages with | ||
/// the same content and layout the cell has already been configured with. | ||
public final class _ChatMessageCell<ExtraData: ExtraDataTypes>: _TableViewCell { | ||
public static var reuseId: String { "\(self)" } | ||
|
||
/// The message content view the cell is showing. | ||
public private(set) var messageContentView: _ChatMessageContentView<ExtraData>? | ||
|
||
/// The minimum spacing below the cell. | ||
public var minimumSpacingBelow: CGFloat = 2 { | ||
didSet { updateBottomSpacing() } | ||
} | ||
|
||
override public func setUp() { | ||
super.setUp() | ||
|
||
selectionStyle = .none | ||
} | ||
|
||
override public func setUpAppearance() { | ||
super.setUpAppearance() | ||
|
||
backgroundColor = .clear | ||
backgroundView = nil | ||
} | ||
|
||
override public func prepareForReuse() { | ||
super.prepareForReuse() | ||
|
||
messageContentView?.prepareForReuse() | ||
} | ||
|
||
/// Creates a message content view | ||
/// - Parameters: | ||
/// - contentViewClass: The type of message content view. | ||
/// - attachmentViewInjectorType: The type of attachment injector. | ||
/// - options: The layout options describing the message content view layout. | ||
public func setMessageContentIfNeeded( | ||
contentViewClass: _ChatMessageContentView<ExtraData>.Type, | ||
attachmentViewInjectorType: _AttachmentViewInjector<ExtraData>.Type?, | ||
options: ChatMessageLayoutOptions | ||
) { | ||
guard messageContentView == nil else { | ||
log.assert(type(of: messageContentView!) == contentViewClass, """ | ||
Attempt to setup different content class: ("\(contentViewClass)") | ||
""") | ||
return | ||
} | ||
|
||
messageContentView = contentViewClass.init().withoutAutoresizingMaskConstraints | ||
// We add the content view to the view hierarchy before invoking `setUpLayoutIfNeeded` | ||
// (where the subviews are instantiated and configured) to use `components` and `appearance` | ||
// taken from the responder chain. | ||
contentView.addSubview(messageContentView!) | ||
messageContentView!.pin(anchors: [.leading, .top, .trailing, .bottom], to: contentView) | ||
messageContentView!.setUpLayoutIfNeeded(options: options, attachmentViewInjectorType: attachmentViewInjectorType) | ||
updateBottomSpacing() | ||
} | ||
|
||
private func updateBottomSpacing() { | ||
guard let contentView = messageContentView else { return } | ||
|
||
contentView.mainContainer.layoutMargins.bottom = max( | ||
contentView.mainContainer.layoutMargins.bottom, | ||
minimumSpacingBelow | ||
) | ||
} | ||
} |
Oops, something went wrong.