From 528ed1aae6363184502b7bda0fae058370b222da Mon Sep 17 00:00:00 2001 From: Wu Zhong Date: Thu, 7 Jun 2018 11:45:32 +0800 Subject: [PATCH] Fixed MessageContentCell's subviews frame when size equal to .zero (#716) * Fixed MessageContentCell's subviews frame when size equal to .zero * Remove .zero check * Fix test failure --- CHANGELOG.md | 3 +++ Sources/Views/Cells/MessageContentCell.swift | 10 ---------- Tests/ViewsTests/MessageCollectionViewCellTests.swift | 1 + 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cf36809..30eecdb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa ### Fixed +- Fixed `MessageContentCell`'s subviews `frame` when size equal to `.zero`. +[#716](https://github.com/MessageKit/MessageKit/pull/716) by [@zhongwuzw](https://github.com/zhongwuzw). + - Fixed `MessagesCollectionView`'s bottom inset when hardware keyboard is connected. Do not adjust `MessagesCollection`'s inset when being popped. [#707](https://github.com/MessageKit/MessageKit/pull/707) by [@zhongwuzw](https://github.com/zhongwuzw). diff --git a/Sources/Views/Cells/MessageContentCell.swift b/Sources/Views/Cells/MessageContentCell.swift index 81fc338e..c98609e3 100644 --- a/Sources/Views/Cells/MessageContentCell.swift +++ b/Sources/Views/Cells/MessageContentCell.swift @@ -171,8 +171,6 @@ open class MessageContentCell: MessageCollectionViewCell { /// Positions the cell's `AvatarView`. /// - attributes: The `MessagesCollectionViewLayoutAttributes` for the cell. open func layoutAvatarView(with attributes: MessagesCollectionViewLayoutAttributes) { - guard attributes.avatarSize != .zero else { return } - var origin: CGPoint = .zero switch attributes.avatarPosition.horizontal { @@ -205,8 +203,6 @@ open class MessageContentCell: MessageCollectionViewCell { /// Positions the cell's `MessageContainerView`. /// - attributes: The `MessagesCollectionViewLayoutAttributes` for the cell. open func layoutMessageContainerView(with attributes: MessagesCollectionViewLayoutAttributes) { - guard attributes.messageContainerSize != .zero else { return } - var origin: CGPoint = .zero switch attributes.avatarPosition.vertical { @@ -238,16 +234,12 @@ open class MessageContentCell: MessageCollectionViewCell { /// Positions the cell's top label. /// - attributes: The `MessagesCollectionViewLayoutAttributes` for the cell. open func layoutCellTopLabel(with attributes: MessagesCollectionViewLayoutAttributes) { - guard attributes.cellTopLabelSize != .zero else { return } - cellTopLabel.frame = CGRect(origin: .zero, size: attributes.cellTopLabelSize) } /// Positions the message bubble's top label. /// - attributes: The `MessagesCollectionViewLayoutAttributes` for the cell. open func layoutMessageTopLabel(with attributes: MessagesCollectionViewLayoutAttributes) { - guard attributes.messageTopLabelSize != .zero else { return } - messageTopLabel.textAlignment = attributes.messageTopLabelAlignment.textAlignment messageTopLabel.textInsets = attributes.messageTopLabelAlignment.textInsets @@ -260,8 +252,6 @@ open class MessageContentCell: MessageCollectionViewCell { /// Positions the cell's bottom label. /// - attributes: The `MessagesCollectionViewLayoutAttributes` for the cell. open func layoutBottomLabel(with attributes: MessagesCollectionViewLayoutAttributes) { - guard attributes.messageBottomLabelSize != .zero else { return } - messageBottomLabel.textAlignment = attributes.messageBottomLabelAlignment.textAlignment messageBottomLabel.textInsets = attributes.messageBottomLabelAlignment.textInsets diff --git a/Tests/ViewsTests/MessageCollectionViewCellTests.swift b/Tests/ViewsTests/MessageCollectionViewCellTests.swift index 32c71302..cbaa1a26 100644 --- a/Tests/ViewsTests/MessageCollectionViewCellTests.swift +++ b/Tests/ViewsTests/MessageCollectionViewCellTests.swift @@ -64,6 +64,7 @@ final class MessageContentCellTests: XCTestCase { func testApplyLayoutAttributes() { let layoutAttributes = MessagesCollectionViewLayoutAttributes() + layoutAttributes.avatarPosition = AvatarPosition(horizontal: .cellLeading, vertical: .cellBottom) cell.apply(layoutAttributes) XCTAssertEqual(cell.avatarView.frame, layoutAttributes.frame)