Skip to content

Commit d4fd57c

Browse files
authored
Merge pull request MessageKit#728 from MessageKit/development
Release MessageKit 1.0.0-beta.2
2 parents 10c98b0 + 8aff9c2 commit d4fd57c

9 files changed

Lines changed: 119 additions & 35 deletions

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,29 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa
66

77
## Upcoming release
88

9+
## [[Prerelease] 1.0.0-beta.2](https://github.com/MessageKit/MessageKit/releases/tag/1.0.0-beta.2)
10+
11+
### Changed
12+
13+
- Relaxed the settable requirement for the `LocationItem` and `MediaItem` protocols.
14+
[#727](https://github.com/MessageKit/MessageKit/pull/716) by [@SD10](https://github.com/sd10).
15+
916
### Fixed
1017

18+
- Fixed `MessageContentCell`'s subviews `frame` when size equal to `.zero`.
19+
[#716](https://github.com/MessageKit/MessageKit/pull/716) by [@zhongwuzw](https://github.com/zhongwuzw).
20+
21+
- Fixed `MessagesCollectionView`'s bottom inset when hardware keyboard is connected. Do not adjust `MessagesCollection`'s inset when being popped.
22+
[#707](https://github.com/MessageKit/MessageKit/pull/707) by [@zhongwuzw](https://github.com/zhongwuzw).
23+
1124
- Fixed `LabelAlignment` initializer which has default internal access control.
1225
[#705](https://github.com/MessageKit/MessageKit/pull/705) by [@zhongwuzw](https://github.com/zhongwuzw).
1326

27+
### Added
28+
29+
- Added convenience method to set properties for all `MessageSizeCalculator`s.
30+
[#697](https://github.com/MessageKit/MessageKit/pull/697) by [@zhongwuzw](https://github.com/zhongwuzw).
31+
1432
## [[Prerelease] 1.0.0-beta.1](https://github.com/MessageKit/MessageKit/releases/tag/1.0.0-beta.1)
1533

1634
### Added

MessageKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'MessageKit'
3-
s.version = '1.0.0-beta.1'
3+
s.version = '1.0.0-beta.2'
44
s.license = { :type => "MIT", :file => "LICENSE.md" }
55

66
s.summary = 'An elegant messages UI library for iOS.'

Sources/Controllers/MessagesViewController+Keyboard.swift

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,19 @@ extension MessagesViewController {
5353
@objc
5454
private func handleKeyboardDidChangeState(_ notification: Notification) {
5555
guard let keyboardEndFrame = notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? CGRect else { return }
56-
57-
if (keyboardEndFrame.origin.y + keyboardEndFrame.size.height) > UIScreen.main.bounds.height {
58-
// Hardware keyboard is found
59-
messageCollectionViewBottomInset = view.frame.size.height - keyboardEndFrame.origin.y - iPhoneXBottomInset
60-
} else {
61-
//Software keyboard is found
62-
let afterBottomInset = keyboardEndFrame.height > keyboardOffsetFrame.height ? (keyboardEndFrame.height - iPhoneXBottomInset) : keyboardOffsetFrame.height
63-
let differenceOfBottomInset = afterBottomInset - messageCollectionViewBottomInset
64-
65-
if maintainPositionOnKeyboardFrameChanged && differenceOfBottomInset != 0 {
66-
let contentOffset = CGPoint(x: messagesCollectionView.contentOffset.x, y: messagesCollectionView.contentOffset.y + differenceOfBottomInset)
67-
messagesCollectionView.setContentOffset(contentOffset, animated: false)
68-
}
69-
70-
messageCollectionViewBottomInset = afterBottomInset
56+
57+
guard !isMessagesControllerBeingDismissed else { return }
58+
59+
let newBottomInset = view.frame.height - keyboardEndFrame.minY - iPhoneXBottomInset
60+
61+
let differenceOfBottomInset = newBottomInset - messageCollectionViewBottomInset
62+
63+
if maintainPositionOnKeyboardFrameChanged && differenceOfBottomInset != 0 {
64+
let contentOffset = CGPoint(x: messagesCollectionView.contentOffset.x, y: messagesCollectionView.contentOffset.y + differenceOfBottomInset)
65+
messagesCollectionView.setContentOffset(contentOffset, animated: false)
7166
}
67+
68+
messageCollectionViewBottomInset = newBottomInset
7269
}
7370

7471
@objc

Sources/Controllers/MessagesViewController.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
6060
}
6161

6262
private var isFirstLayout: Bool = true
63+
64+
internal var isMessagesControllerBeingDismissed: Bool = false
6365

6466
internal var selectedIndexPathForMenu: IndexPath?
6567

@@ -82,6 +84,16 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
8284
addObservers()
8385
}
8486

87+
open override func viewDidAppear(_ animated: Bool) {
88+
super.viewDidAppear(animated)
89+
isMessagesControllerBeingDismissed = false
90+
}
91+
92+
open override func viewWillDisappear(_ animated: Bool) {
93+
super.viewWillDisappear(animated)
94+
isMessagesControllerBeingDismissed = true
95+
}
96+
8597
open override func viewDidLayoutSubviews() {
8698
// Hack to prevent animation of the contentInset after viewDidAppear
8799
if isFirstLayout {

Sources/Layout/MessagesCollectionViewFlowLayout.swift

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ open class MessagesCollectionViewFlowLayout: UICollectionViewFlowLayout {
3333
return MessagesCollectionViewLayoutAttributes.self
3434
}
3535

36-
/** The `MessagesCollectionView` that owns this layout object. */
36+
/// The `MessagesCollectionView` that owns this layout object.
3737
public var messagesCollectionView: MessagesCollectionView {
3838
guard let messagesCollectionView = collectionView as? MessagesCollectionView else {
3939
fatalError(MessageKitError.layoutUsedOnForeignType)
4040
}
4141
return messagesCollectionView
4242
}
4343

44-
/** The `MessagesDataSource` for the layout's collection view. */
44+
/// The `MessagesDataSource` for the layout's collection view.
4545
public var messagesDataSource: MessagesDataSource {
4646
guard let messagesDataSource = messagesCollectionView.messagesDataSource else {
4747
fatalError(MessageKitError.nilMessagesDataSource)
4848
}
4949
return messagesDataSource
5050
}
5151

52-
/** The `MessagesLayoutDelegate` for the layout's collection view. */
52+
/// The `MessagesLayoutDelegate` for the layout's collection view.
5353
public var messagesLayoutDelegate: MessagesLayoutDelegate {
5454
guard let messagesLayoutDelegate = messagesCollectionView.messagesLayoutDelegate else {
5555
fatalError(MessageKitError.nilMessagesLayoutDelegate)
@@ -155,4 +155,70 @@ open class MessagesCollectionViewFlowLayout: UICollectionViewFlowLayout {
155155
let calculator = cellSizeCalculatorForItem(at: indexPath)
156156
return calculator.sizeForItem(at: indexPath)
157157
}
158+
159+
/// Set `incomingAvatarSize` of all `MessageSizeCalculator`s
160+
public func setMessageIncomingAvatarSize(_ newSize: CGSize) {
161+
messageSizeCalculators().forEach { $0.incomingAvatarSize = newSize }
162+
}
163+
164+
/// Set `outgoingAvatarSize` of all `MessageSizeCalculator`s
165+
public func setMessageOutgoingAvatarSize(_ newSize: CGSize) {
166+
messageSizeCalculators().forEach { $0.outgoingAvatarSize = newSize }
167+
}
168+
169+
/// Set `incomingAvatarPosition` of all `MessageSizeCalculator`s
170+
public func setMessageIncomingAvatarPosition(_ newPosition: AvatarPosition) {
171+
messageSizeCalculators().forEach { $0.incomingAvatarPosition = newPosition }
172+
}
173+
174+
/// Set `outgoingAvatarPosition` of all `MessageSizeCalculator`s
175+
public func setMessageOutgoingAvatarPosition(_ newPosition: AvatarPosition) {
176+
messageSizeCalculators().forEach { $0.outgoingAvatarPosition = newPosition }
177+
}
178+
179+
/// Set `incomingMessagePadding` of all `MessageSizeCalculator`s
180+
public func setMessageIncomingMessagePadding(_ newPadding: UIEdgeInsets) {
181+
messageSizeCalculators().forEach { $0.incomingMessagePadding = newPadding }
182+
}
183+
184+
/// Set `outgoingMessagePadding` of all `MessageSizeCalculator`s
185+
public func setMessageOutgoingMessagePadding(_ newPadding: UIEdgeInsets) {
186+
messageSizeCalculators().forEach { $0.outgoingMessagePadding = newPadding }
187+
}
188+
189+
/// Set `incomingCellTopLabelAlignment` of all `MessageSizeCalculator`s
190+
public func setMessageIncomingCellTopLabelAlignment(_ newAlignment: LabelAlignment) {
191+
messageSizeCalculators().forEach { $0.incomingCellTopLabelAlignment = newAlignment }
192+
}
193+
194+
/// Set `outgoingCellTopLabelAlignment` of all `MessageSizeCalculator`s
195+
public func setMessageOutgoingCellTopLabelAlignment(_ newAlignment: LabelAlignment) {
196+
messageSizeCalculators().forEach { $0.outgoingCellTopLabelAlignment = newAlignment }
197+
}
198+
199+
/// Set `incomingMessageTopLabelAlignment` of all `MessageSizeCalculator`s
200+
public func setMessageIncomingMessageTopLabelAlignment(_ newAlignment: LabelAlignment) {
201+
messageSizeCalculators().forEach { $0.incomingMessageTopLabelAlignment = newAlignment }
202+
}
203+
204+
/// Set `outgoingMessageTopLabelAlignment` of all `MessageSizeCalculator`s
205+
public func setMessageOutgoingMessageTopLabelAlignment(_ newAlignment: LabelAlignment) {
206+
messageSizeCalculators().forEach { $0.outgoingMessageTopLabelAlignment = newAlignment }
207+
}
208+
209+
/// Set `incomingMessageBottomLabelAlignment` of all `MessageSizeCalculator`s
210+
public func setMessageIncomingMessageBottomLabelAlignment(_ newAlignment: LabelAlignment) {
211+
messageSizeCalculators().forEach { $0.incomingMessageBottomLabelAlignment = newAlignment }
212+
}
213+
214+
/// Set `outgoingMessageBottomLabelAlignment` of all `MessageSizeCalculator`s
215+
public func setMessageOutgoingMessageBottomLabelAlignment(_ newAlignment: LabelAlignment) {
216+
messageSizeCalculators().forEach { $0.outgoingMessageBottomLabelAlignment = newAlignment }
217+
}
218+
219+
/// Get all `MessageSizeCalculator`s
220+
open func messageSizeCalculators() -> [MessageSizeCalculator] {
221+
return [textMessageSizeCalculator, attributedTextMessageSizeCalculator, emojiMessageSizeCalculator, photoMessageSizeCalculator, videoMessageSizeCalculator, locationMessageSizeCalculator]
222+
}
223+
158224
}

Sources/Protocols/LocationItem.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import class CoreLocation.CLLocation
2828
public protocol LocationItem {
2929

3030
/// The location.
31-
var location: CLLocation { get set }
31+
var location: CLLocation { get }
3232

3333
/// The size of the location item.
34-
var size: CGSize { get set }
34+
var size: CGSize { get }
3535

3636
}

Sources/Protocols/MediaItem.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ import Foundation
2828
public protocol MediaItem {
2929

3030
/// The url where the media is located.
31-
var url: URL? { get set }
31+
var url: URL? { get }
3232

3333
/// The image.
34-
var image: UIImage? { get set }
34+
var image: UIImage? { get }
3535

3636
/// A placeholder image for when the image is obtained asychronously.
37-
var placeholderImage: UIImage { get set }
37+
var placeholderImage: UIImage { get }
3838

3939
/// The size of the media item.
40-
var size: CGSize { get set }
40+
var size: CGSize { get }
4141

4242
}

Sources/Views/Cells/MessageContentCell.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ open class MessageContentCell: MessageCollectionViewCell {
171171
/// Positions the cell's `AvatarView`.
172172
/// - attributes: The `MessagesCollectionViewLayoutAttributes` for the cell.
173173
open func layoutAvatarView(with attributes: MessagesCollectionViewLayoutAttributes) {
174-
guard attributes.avatarSize != .zero else { return }
175-
176174
var origin: CGPoint = .zero
177175

178176
switch attributes.avatarPosition.horizontal {
@@ -205,8 +203,6 @@ open class MessageContentCell: MessageCollectionViewCell {
205203
/// Positions the cell's `MessageContainerView`.
206204
/// - attributes: The `MessagesCollectionViewLayoutAttributes` for the cell.
207205
open func layoutMessageContainerView(with attributes: MessagesCollectionViewLayoutAttributes) {
208-
guard attributes.messageContainerSize != .zero else { return }
209-
210206
var origin: CGPoint = .zero
211207

212208
switch attributes.avatarPosition.vertical {
@@ -238,16 +234,12 @@ open class MessageContentCell: MessageCollectionViewCell {
238234
/// Positions the cell's top label.
239235
/// - attributes: The `MessagesCollectionViewLayoutAttributes` for the cell.
240236
open func layoutCellTopLabel(with attributes: MessagesCollectionViewLayoutAttributes) {
241-
guard attributes.cellTopLabelSize != .zero else { return }
242-
243237
cellTopLabel.frame = CGRect(origin: .zero, size: attributes.cellTopLabelSize)
244238
}
245239

246240
/// Positions the message bubble's top label.
247241
/// - attributes: The `MessagesCollectionViewLayoutAttributes` for the cell.
248242
open func layoutMessageTopLabel(with attributes: MessagesCollectionViewLayoutAttributes) {
249-
guard attributes.messageTopLabelSize != .zero else { return }
250-
251243
messageTopLabel.textAlignment = attributes.messageTopLabelAlignment.textAlignment
252244
messageTopLabel.textInsets = attributes.messageTopLabelAlignment.textInsets
253245

@@ -260,8 +252,6 @@ open class MessageContentCell: MessageCollectionViewCell {
260252
/// Positions the cell's bottom label.
261253
/// - attributes: The `MessagesCollectionViewLayoutAttributes` for the cell.
262254
open func layoutBottomLabel(with attributes: MessagesCollectionViewLayoutAttributes) {
263-
guard attributes.messageBottomLabelSize != .zero else { return }
264-
265255
messageBottomLabel.textAlignment = attributes.messageBottomLabelAlignment.textAlignment
266256
messageBottomLabel.textInsets = attributes.messageBottomLabelAlignment.textInsets
267257

Tests/ViewsTests/MessageCollectionViewCellTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ final class MessageContentCellTests: XCTestCase {
6464

6565
func testApplyLayoutAttributes() {
6666
let layoutAttributes = MessagesCollectionViewLayoutAttributes()
67+
layoutAttributes.avatarPosition = AvatarPosition(horizontal: .cellLeading, vertical: .cellBottom)
6768
cell.apply(layoutAttributes)
6869

6970
XCTAssertEqual(cell.avatarView.frame, layoutAttributes.frame)

0 commit comments

Comments
 (0)