From e535c7301e1a5fb87c54308407f95539f1ff883e Mon Sep 17 00:00:00 2001 From: Jakub Kaspar Date: Thu, 27 Aug 2020 17:34:31 +0200 Subject: [PATCH 01/22] Update IBAV dependency to 5.1.0 with dark mode support --- Cartfile | 2 +- Example/Podfile.lock | 14 +++++++------- MessageKit.podspec | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cartfile b/Cartfile index 5e9a95f2..eca0311a 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "nathantannar4/InputBarAccessoryView" ~> 4.3.0 +github "nathantannar4/InputBarAccessoryView" ~> 5.1.0 diff --git a/Example/Podfile.lock b/Example/Podfile.lock index eec5de83..35f7bf7c 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,9 +1,9 @@ PODS: - - InputBarAccessoryView (5.0.0): - - InputBarAccessoryView/Core (= 5.0.0) - - InputBarAccessoryView/Core (5.0.0) - - MessageKit (3.1.0): - - InputBarAccessoryView (~> 5.0.0) + - InputBarAccessoryView (5.1.0): + - InputBarAccessoryView/Core (= 5.1.0) + - InputBarAccessoryView/Core (5.1.0) + - MessageKit (3.2.0): + - InputBarAccessoryView (~> 5.1.0) - PINCache (3.0.1-beta.8): - PINCache/Arc-exception-safe (= 3.0.1-beta.8) - PINCache/Core (= 3.0.1-beta.8) @@ -40,8 +40,8 @@ EXTERNAL SOURCES: :path: "../" SPEC CHECKSUMS: - InputBarAccessoryView: cbc0b2d9456058e1166898897865f9f4960fac81 - MessageKit: 83cb90a9087b46d1e7da2451ca3e2bde462ad7e7 + InputBarAccessoryView: 19953f486a23e846e9487099f92bbe3456e46ce5 + MessageKit: ce553a92153b597540ea4688b654680542c4af6a PINCache: 534fd41d358d828dfdf227a0d327f3673a65e20b PINOperation: 24b774353ca248fcf87d67b2d61eef42087c125a PINRemoteImage: e2b89e19fb6e77ffc099f9d9f3b3fe1745e3f9f9 diff --git a/MessageKit.podspec b/MessageKit.podspec index 654c1c3f..fff37452 100644 --- a/MessageKit.podspec +++ b/MessageKit.podspec @@ -16,6 +16,6 @@ Pod::Spec.new do |s| s.ios.deployment_target = '11.0' s.ios.resources = ['Sources/Assets.xcassets'] - s.dependency 'InputBarAccessoryView', '~> 5.0.0' + s.dependency 'InputBarAccessoryView', '~> 5.1.0' end From ddfce2e7247345a8cc67aad841f3d1d35f190f01 Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Fri, 28 Aug 2020 15:16:01 +0430 Subject: [PATCH 02/22] Add pan gesture --- .../Controllers/MessagesViewController.swift | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Sources/Controllers/MessagesViewController.swift b/Sources/Controllers/MessagesViewController.swift index 61c1f87d..b2e440f7 100644 --- a/Sources/Controllers/MessagesViewController.swift +++ b/Sources/Controllers/MessagesViewController.swift @@ -102,6 +102,7 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource { super.viewDidLoad() setupDefaults() setupSubviews() + addPanGesture() setupConstraints() setupDelegates() addMenuControllerObservers() @@ -148,6 +149,39 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource { // MARK: - Methods [Private] + /// Display time of message by swiping the cell + private func addPanGesture() { + let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:))) + messagesCollectionView.addGestureRecognizer(panGesture) + messagesCollectionView.clipsToBounds = false + } + + @objc + private func handlePanGesture(_ gesture: UIPanGestureRecognizer) { + guard let parentView = gesture.view else { + return + } + + switch gesture.state { + case .began, .changed: + // show time + let translation = gesture.translation(in: view) + let minX = -(view.frame.size.width * 0.3) + let maxX: CGFloat = 0 + var offsetValue = translation.x + offsetValue = max(offsetValue, minX) + offsetValue = min(offsetValue, maxX) + parentView.frame.origin.x = offsetValue + case .ended: + // hide time + UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.8, options: .curveEaseOut, animations: { + parentView.frame.origin.x = 0 + }, completion: nil) + default: + break + } + } + private func setupDefaults() { extendedLayoutIncludesOpaqueBars = true view.backgroundColor = .collectionViewBackground From 57e77b0b3d95d9f81c3cd2c1f93625a0731a5c21 Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Fri, 28 Aug 2020 15:56:33 +0430 Subject: [PATCH 03/22] Check pan gesture direction --- .../Controllers/MessagesViewController.swift | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Sources/Controllers/MessagesViewController.swift b/Sources/Controllers/MessagesViewController.swift index b2e440f7..a8dd700f 100644 --- a/Sources/Controllers/MessagesViewController.swift +++ b/Sources/Controllers/MessagesViewController.swift @@ -28,7 +28,7 @@ import InputBarAccessoryView /// A subclass of `UIViewController` with a `MessagesCollectionView` object /// that is used to display conversation interfaces. open class MessagesViewController: UIViewController, -UICollectionViewDelegateFlowLayout, UICollectionViewDataSource { +UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UIGestureRecognizerDelegate { /// The `MessagesCollectionView` managed by the messages view controller object. open var messagesCollectionView = MessagesCollectionView() @@ -152,6 +152,7 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource { /// Display time of message by swiping the cell private func addPanGesture() { let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:))) + panGesture.delegate = self messagesCollectionView.addGestureRecognizer(panGesture) messagesCollectionView.clipsToBounds = false } @@ -164,7 +165,7 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource { switch gesture.state { case .began, .changed: - // show time + messagesCollectionView.showsVerticalScrollIndicator = false let translation = gesture.translation(in: view) let minX = -(view.frame.size.width * 0.3) let maxX: CGFloat = 0 @@ -173,7 +174,7 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource { offsetValue = min(offsetValue, maxX) parentView.frame.origin.x = offsetValue case .ended: - // hide time + messagesCollectionView.showsVerticalScrollIndicator = true UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.8, options: .curveEaseOut, animations: { parentView.frame.origin.x = 0 }, completion: nil) @@ -454,4 +455,15 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource { @objc private func clearMemoryCache() { MessageStyle.bubbleImageCache.removeAllObjects() } + + // MARK: - UIGestureRecognizerDelegate + + /// check pan gesture direction + public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { + guard let panGesture = gestureRecognizer as? UIPanGestureRecognizer else { + return false + } + let velocity = panGesture.velocity(in: messagesCollectionView) + return abs(velocity.x) > abs(velocity.y) + } } From 216d26baec54e619e0868de370890f4cd8407c9a Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Fri, 28 Aug 2020 16:27:50 +0430 Subject: [PATCH 04/22] Add message time label --- .../Controllers/MessagesViewController.swift | 2 +- Sources/Layout/MessageSizeCalculator.swift | 16 ++++++++++++- ...ssagesCollectionViewLayoutAttributes.swift | 4 ++++ Sources/Views/Cells/MessageContentCell.swift | 23 +++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Sources/Controllers/MessagesViewController.swift b/Sources/Controllers/MessagesViewController.swift index a8dd700f..169b62b4 100644 --- a/Sources/Controllers/MessagesViewController.swift +++ b/Sources/Controllers/MessagesViewController.swift @@ -167,7 +167,7 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UIGestureRecogni case .began, .changed: messagesCollectionView.showsVerticalScrollIndicator = false let translation = gesture.translation(in: view) - let minX = -(view.frame.size.width * 0.3) + let minX = -(view.frame.size.width * 0.4) let maxX: CGFloat = 0 var offsetValue = translation.x offsetValue = max(offsetValue, minX) diff --git a/Sources/Layout/MessageSizeCalculator.swift b/Sources/Layout/MessageSizeCalculator.swift index 6fd768d3..ba5b026a 100644 --- a/Sources/Layout/MessageSizeCalculator.swift +++ b/Sources/Layout/MessageSizeCalculator.swift @@ -81,6 +81,7 @@ open class MessageSizeCalculator: CellSizeCalculator { attributes.cellTopLabelSize = cellTopLabelSize(for: message, at: indexPath) attributes.cellTopLabelAlignment = cellTopLabelAlignment(for: message) attributes.cellBottomLabelSize = cellBottomLabelSize(for: message, at: indexPath) + attributes.messageTimeLabelSize = messageTimeLabelSize(for: message, at: indexPath) attributes.cellBottomLabelAlignment = cellBottomLabelAlignment(for: message) attributes.messageTopLabelSize = messageTopLabelSize(for: message, at: indexPath) attributes.messageTopLabelAlignment = messageTopLabelAlignment(for: message) @@ -197,7 +198,20 @@ open class MessageSizeCalculator: CellSizeCalculator { let isFromCurrentSender = dataSource.isFromCurrentSender(message: message) return isFromCurrentSender ? outgoingMessageTopLabelAlignment : incomingMessageTopLabelAlignment } - + + // MARK: - Message time label + + open func messageTimeLabelSize(for message: MessageType, at indexPath: IndexPath) -> CGSize { + let sentDate = message.sentDate + let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) + let timeLabelFont : UIFont = .boldSystemFont(ofSize: 10) + let timeLabelColor: UIColor = .darkGray + let timeLabelText = + NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) + let size = timeLabelText.size() + return CGSize(width: size.width, height: size.height) + } + // MARK: - Bottom cell Label open func cellBottomLabelSize(for message: MessageType, at indexPath: IndexPath) -> CGSize { diff --git a/Sources/Layout/MessagesCollectionViewLayoutAttributes.swift b/Sources/Layout/MessagesCollectionViewLayoutAttributes.swift index 9bf2270a..e182a63c 100644 --- a/Sources/Layout/MessagesCollectionViewLayoutAttributes.swift +++ b/Sources/Layout/MessagesCollectionViewLayoutAttributes.swift @@ -50,6 +50,8 @@ open class MessagesCollectionViewLayoutAttributes: UICollectionViewLayoutAttribu public var messageBottomLabelAlignment = LabelAlignment(textAlignment: .center, textInsets: .zero) public var messageBottomLabelSize: CGSize = .zero + public var messageTimeLabelSize: CGSize = .zero + public var accessoryViewSize: CGSize = .zero public var accessoryViewPadding: HorizontalEdgeInsets = .zero public var accessoryViewPosition: AccessoryPosition = .messageCenter @@ -74,6 +76,7 @@ open class MessagesCollectionViewLayoutAttributes: UICollectionViewLayoutAttribu copy.cellTopLabelSize = cellTopLabelSize copy.cellBottomLabelAlignment = cellBottomLabelAlignment copy.cellBottomLabelSize = cellBottomLabelSize + copy.messageTimeLabelSize = messageTimeLabelSize copy.messageTopLabelAlignment = messageTopLabelAlignment copy.messageTopLabelSize = messageTopLabelSize copy.messageBottomLabelAlignment = messageBottomLabelAlignment @@ -100,6 +103,7 @@ open class MessagesCollectionViewLayoutAttributes: UICollectionViewLayoutAttribu && attributes.cellTopLabelSize == cellTopLabelSize && attributes.cellBottomLabelAlignment == cellBottomLabelAlignment && attributes.cellBottomLabelSize == cellBottomLabelSize + && attributes.messageTimeLabelSize == messageTimeLabelSize && attributes.messageTopLabelAlignment == messageTopLabelAlignment && attributes.messageTopLabelSize == messageTopLabelSize && attributes.messageBottomLabelAlignment == messageBottomLabelAlignment diff --git a/Sources/Views/Cells/MessageContentCell.swift b/Sources/Views/Cells/MessageContentCell.swift index e857558b..d0948b7d 100644 --- a/Sources/Views/Cells/MessageContentCell.swift +++ b/Sources/Views/Cells/MessageContentCell.swift @@ -69,6 +69,9 @@ open class MessageContentCell: MessageCollectionViewCell { return label }() + /// The time label of the messageBubble. + open var timeLabel: InsetLabel = InsetLabel() + // Should only add customized subviews - don't change accessoryView itself. open var accessoryView: UIView = UIView() @@ -95,6 +98,7 @@ open class MessageContentCell: MessageCollectionViewCell { contentView.addSubview(cellBottomLabel) contentView.addSubview(messageContainerView) contentView.addSubview(avatarView) + contentView.addSubview(timeLabel) } open override func prepareForReuse() { @@ -103,6 +107,7 @@ open class MessageContentCell: MessageCollectionViewCell { cellBottomLabel.text = nil messageTopLabel.text = nil messageBottomLabel.text = nil + timeLabel.attributedText = nil } // MARK: - Configuration @@ -118,6 +123,7 @@ open class MessageContentCell: MessageCollectionViewCell { layoutMessageTopLabel(with: attributes) layoutAvatarView(with: attributes) layoutAccessoryView(with: attributes) + layoutTimeLabelView(with: attributes) } /// Used to configure the cell. @@ -151,10 +157,18 @@ open class MessageContentCell: MessageCollectionViewCell { let topMessageLabelText = dataSource.messageTopLabelAttributedText(for: message, at: indexPath) let bottomMessageLabelText = dataSource.messageBottomLabelAttributedText(for: message, at: indexPath) + let sentDate = message.sentDate + let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) + let timeLabelFont : UIFont = .boldSystemFont(ofSize: 10) + let timeLabelColor: UIColor = .darkGray + let timeLabelText = + NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) + cellTopLabel.attributedText = topCellLabelText cellBottomLabel.attributedText = bottomCellLabelText messageTopLabel.attributedText = topMessageLabelText messageBottomLabel.attributedText = bottomMessageLabelText + timeLabel.attributedText = timeLabelText } /// Handle tap gesture on contentView and its subviews. @@ -344,4 +358,13 @@ open class MessageContentCell: MessageCollectionViewCell { accessoryView.frame = CGRect(origin: origin, size: attributes.accessoryViewSize) } + + /// Positions the message bubble's time label. + /// - attributes: The `MessagesCollectionViewLayoutAttributes` for the cell. + open func layoutTimeLabelView(with attributes: MessagesCollectionViewLayoutAttributes) { + let paddingLeft: CGFloat = 10 + let origin = CGPoint(x: contentView.frame.size.width + paddingLeft, y: 0) + let size = CGSize(width: attributes.messageTimeLabelSize.width, height: attributes.messageTimeLabelSize.height) + timeLabel.frame = CGRect(origin: origin, size: size) + } } From 404f3ad33278992764e9d213626b52f8b6ecacad Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Fri, 28 Aug 2020 17:21:00 +0430 Subject: [PATCH 05/22] Add boolean for enable/disable display time --- .../View Controllers/ChatViewController.swift | 2 ++ Sources/Controllers/MessagesViewController.swift | 14 ++++++++++++-- Sources/Views/Cells/MessageContentCell.swift | 4 ++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Example/Sources/View Controllers/ChatViewController.swift b/Example/Sources/View Controllers/ChatViewController.swift index 27f6d267..03d89c4d 100644 --- a/Example/Sources/View Controllers/ChatViewController.swift +++ b/Example/Sources/View Controllers/ChatViewController.swift @@ -112,6 +112,8 @@ class ChatViewController: MessagesViewController, MessagesDataSource { scrollsToBottomOnKeyboardBeginsEditing = true // default false maintainPositionOnKeyboardFrameChanged = true // default false + + displayTimeBySwipingLeft = true messagesCollectionView.refreshControl = refreshControl } diff --git a/Sources/Controllers/MessagesViewController.swift b/Sources/Controllers/MessagesViewController.swift index 169b62b4..17dcf19d 100644 --- a/Sources/Controllers/MessagesViewController.swift +++ b/Sources/Controllers/MessagesViewController.swift @@ -56,6 +56,14 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UIGestureRecogni /// The default value of this property is `false`. open var maintainPositionOnKeyboardFrameChanged: Bool = false + /// Display the date of message by swiping left. + /// The default value of this property is `false`. + open var displayTimeBySwipingLeft: Bool = false { + didSet { + addPanGesture() + } + } + open override var canBecomeFirstResponder: Bool { return true } @@ -102,7 +110,6 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UIGestureRecogni super.viewDidLoad() setupDefaults() setupSubviews() - addPanGesture() setupConstraints() setupDelegates() addMenuControllerObservers() @@ -151,6 +158,9 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UIGestureRecogni /// Display time of message by swiping the cell private func addPanGesture() { + guard displayTimeBySwipingLeft else { + return + } let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:))) panGesture.delegate = self messagesCollectionView.addGestureRecognizer(panGesture) @@ -167,7 +177,7 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UIGestureRecogni case .began, .changed: messagesCollectionView.showsVerticalScrollIndicator = false let translation = gesture.translation(in: view) - let minX = -(view.frame.size.width * 0.4) + let minX = -(view.frame.size.width * 0.35) let maxX: CGFloat = 0 var offsetValue = translation.x offsetValue = max(offsetValue, minX) diff --git a/Sources/Views/Cells/MessageContentCell.swift b/Sources/Views/Cells/MessageContentCell.swift index d0948b7d..3329830a 100644 --- a/Sources/Views/Cells/MessageContentCell.swift +++ b/Sources/Views/Cells/MessageContentCell.swift @@ -169,6 +169,10 @@ open class MessageContentCell: MessageCollectionViewCell { messageTopLabel.attributedText = topMessageLabelText messageBottomLabel.attributedText = bottomMessageLabelText timeLabel.attributedText = timeLabelText + + let displayTimeBySwipingLeft = messagesCollectionView.clipsToBounds == false + messageBottomLabel.isHidden = displayTimeBySwipingLeft + timeLabel.isHidden = !displayTimeBySwipingLeft } /// Handle tap gesture on contentView and its subviews. From 5949d6e32cfc86d53d976a0726819d8a14d381ac Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Sun, 30 Aug 2020 01:27:55 +0430 Subject: [PATCH 06/22] Add comment --- Example/Sources/View Controllers/ChatViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/Sources/View Controllers/ChatViewController.swift b/Example/Sources/View Controllers/ChatViewController.swift index 03d89c4d..44f0362e 100644 --- a/Example/Sources/View Controllers/ChatViewController.swift +++ b/Example/Sources/View Controllers/ChatViewController.swift @@ -113,7 +113,7 @@ class ChatViewController: MessagesViewController, MessagesDataSource { scrollsToBottomOnKeyboardBeginsEditing = true // default false maintainPositionOnKeyboardFrameChanged = true // default false - displayTimeBySwipingLeft = true + displayTimeBySwipingLeft = true // default false messagesCollectionView.refreshControl = refreshControl } From 72c4c2140ed0c00987ff6de8c7a320ed21a8fb67 Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Sun, 30 Aug 2020 01:48:43 +0430 Subject: [PATCH 07/22] Change text color for dark mode --- Sources/Views/Cells/MessageContentCell.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/Views/Cells/MessageContentCell.swift b/Sources/Views/Cells/MessageContentCell.swift index 3329830a..e1cef9ae 100644 --- a/Sources/Views/Cells/MessageContentCell.swift +++ b/Sources/Views/Cells/MessageContentCell.swift @@ -160,7 +160,10 @@ open class MessageContentCell: MessageCollectionViewCell { let sentDate = message.sentDate let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) let timeLabelFont : UIFont = .boldSystemFont(ofSize: 10) - let timeLabelColor: UIColor = .darkGray + var timeLabelColor: UIColor = .darkGray + if #available(iOS 12.0, *), traitCollection.userInterfaceStyle == .dark { + timeLabelColor = .white + } let timeLabelText = NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) From 8f17474b8425de543c7ec2704a764635596cf5ca Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Sun, 30 Aug 2020 01:48:58 +0430 Subject: [PATCH 08/22] Remove unused code --- Sources/Layout/MessageSizeCalculator.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/Layout/MessageSizeCalculator.swift b/Sources/Layout/MessageSizeCalculator.swift index ba5b026a..b269e23a 100644 --- a/Sources/Layout/MessageSizeCalculator.swift +++ b/Sources/Layout/MessageSizeCalculator.swift @@ -205,9 +205,8 @@ open class MessageSizeCalculator: CellSizeCalculator { let sentDate = message.sentDate let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) let timeLabelFont : UIFont = .boldSystemFont(ofSize: 10) - let timeLabelColor: UIColor = .darkGray let timeLabelText = - NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) + NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont]) let size = timeLabelText.size() return CGSize(width: size.width, height: size.height) } From f04a89c764e9aca942e6fbc6a1057984898ca789 Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Sun, 30 Aug 2020 02:06:06 +0430 Subject: [PATCH 09/22] Add removePanGesture method --- .../Controllers/MessagesViewController.swift | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Sources/Controllers/MessagesViewController.swift b/Sources/Controllers/MessagesViewController.swift index 17dcf19d..e915eba4 100644 --- a/Sources/Controllers/MessagesViewController.swift +++ b/Sources/Controllers/MessagesViewController.swift @@ -60,10 +60,17 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UIGestureRecogni /// The default value of this property is `false`. open var displayTimeBySwipingLeft: Bool = false { didSet { - addPanGesture() + if displayTimeBySwipingLeft { + addPanGesture() + } else { + removePanGesture() + } } } + /// Pan gesture for display the date of message by swiping left. + private var panGesture: UIPanGestureRecognizer? + open override var canBecomeFirstResponder: Bool { return true } @@ -158,15 +165,25 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UIGestureRecogni /// Display time of message by swiping the cell private func addPanGesture() { - guard displayTimeBySwipingLeft else { + panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:))) + guard let panGesture = panGesture else { return } - let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:))) panGesture.delegate = self messagesCollectionView.addGestureRecognizer(panGesture) messagesCollectionView.clipsToBounds = false } + private func removePanGesture() { + guard let panGesture = panGesture else { + return + } + panGesture.delegate = nil + self.panGesture = nil + messagesCollectionView.removeGestureRecognizer(panGesture) + messagesCollectionView.clipsToBounds = true + } + @objc private func handlePanGesture(_ gesture: UIPanGestureRecognizer) { guard let parentView = gesture.view else { From c0a659daa3c7218ca3fbb8874b07848e52b9568e Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Sun, 30 Aug 2020 02:14:47 +0430 Subject: [PATCH 10/22] Change to better check --- Sources/Controllers/MessagesViewController.swift | 1 + Sources/Views/Cells/MessageContentCell.swift | 5 ++--- Sources/Views/MessagesCollectionView.swift | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/Controllers/MessagesViewController.swift b/Sources/Controllers/MessagesViewController.swift index e915eba4..475c0efb 100644 --- a/Sources/Controllers/MessagesViewController.swift +++ b/Sources/Controllers/MessagesViewController.swift @@ -60,6 +60,7 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UIGestureRecogni /// The default value of this property is `false`. open var displayTimeBySwipingLeft: Bool = false { didSet { + messagesCollectionView.displayTimeBySwipingLeft = displayTimeBySwipingLeft if displayTimeBySwipingLeft { addPanGesture() } else { diff --git a/Sources/Views/Cells/MessageContentCell.swift b/Sources/Views/Cells/MessageContentCell.swift index e1cef9ae..dbbea1be 100644 --- a/Sources/Views/Cells/MessageContentCell.swift +++ b/Sources/Views/Cells/MessageContentCell.swift @@ -173,9 +173,8 @@ open class MessageContentCell: MessageCollectionViewCell { messageBottomLabel.attributedText = bottomMessageLabelText timeLabel.attributedText = timeLabelText - let displayTimeBySwipingLeft = messagesCollectionView.clipsToBounds == false - messageBottomLabel.isHidden = displayTimeBySwipingLeft - timeLabel.isHidden = !displayTimeBySwipingLeft + messageBottomLabel.isHidden = messagesCollectionView.displayTimeBySwipingLeft + timeLabel.isHidden = !messageBottomLabel.isHidden } /// Handle tap gesture on contentView and its subviews. diff --git a/Sources/Views/MessagesCollectionView.swift b/Sources/Views/MessagesCollectionView.swift index 740cb960..cc8556ee 100644 --- a/Sources/Views/MessagesCollectionView.swift +++ b/Sources/Views/MessagesCollectionView.swift @@ -41,6 +41,10 @@ open class MessagesCollectionView: UICollectionView { return messagesCollectionViewFlowLayout.isTypingIndicatorViewHidden } + /// Display the date of message by swiping left. + /// The default value of this property is `false`. + open var displayTimeBySwipingLeft: Bool = false + private var indexPathForLastItem: IndexPath? { let lastSection = numberOfSections - 1 guard lastSection >= 0, numberOfItems(inSection: lastSection) > 0 else { return nil } From d4f0defa1cef4c15dd776c9610c77e58a93db876 Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Sun, 30 Aug 2020 18:14:38 +0430 Subject: [PATCH 11/22] Use system color --- Sources/Views/Cells/MessageContentCell.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/Views/Cells/MessageContentCell.swift b/Sources/Views/Cells/MessageContentCell.swift index dbbea1be..b4afec24 100644 --- a/Sources/Views/Cells/MessageContentCell.swift +++ b/Sources/Views/Cells/MessageContentCell.swift @@ -160,9 +160,11 @@ open class MessageContentCell: MessageCollectionViewCell { let sentDate = message.sentDate let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) let timeLabelFont : UIFont = .boldSystemFont(ofSize: 10) - var timeLabelColor: UIColor = .darkGray - if #available(iOS 12.0, *), traitCollection.userInterfaceStyle == .dark { - timeLabelColor = .white + let timeLabelColor: UIColor + if #available(iOS 13, *) { + timeLabelColor = .systemGray + } else { + timeLabelColor = .darkGray } let timeLabelText = NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) From ad28df14866ff08b2ddcb74812d3dd785a5dba07 Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Sun, 30 Aug 2020 18:20:32 +0430 Subject: [PATCH 12/22] Use property --- Sources/Views/Cells/MessageContentCell.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Views/Cells/MessageContentCell.swift b/Sources/Views/Cells/MessageContentCell.swift index b4afec24..480e3e47 100644 --- a/Sources/Views/Cells/MessageContentCell.swift +++ b/Sources/Views/Cells/MessageContentCell.swift @@ -176,7 +176,7 @@ open class MessageContentCell: MessageCollectionViewCell { timeLabel.attributedText = timeLabelText messageBottomLabel.isHidden = messagesCollectionView.displayTimeBySwipingLeft - timeLabel.isHidden = !messageBottomLabel.isHidden + timeLabel.isHidden = !messagesCollectionView.displayTimeBySwipingLeft } /// Handle tap gesture on contentView and its subviews. From be2eea0b2d2a6e804909829c21187ae55d003464 Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Sun, 30 Aug 2020 18:24:38 +0430 Subject: [PATCH 13/22] Fix center label --- Sources/Views/Cells/MessageContentCell.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Views/Cells/MessageContentCell.swift b/Sources/Views/Cells/MessageContentCell.swift index 480e3e47..e3eefa80 100644 --- a/Sources/Views/Cells/MessageContentCell.swift +++ b/Sources/Views/Cells/MessageContentCell.swift @@ -371,7 +371,7 @@ open class MessageContentCell: MessageCollectionViewCell { /// - attributes: The `MessagesCollectionViewLayoutAttributes` for the cell. open func layoutTimeLabelView(with attributes: MessagesCollectionViewLayoutAttributes) { let paddingLeft: CGFloat = 10 - let origin = CGPoint(x: contentView.frame.size.width + paddingLeft, y: 0) + let origin = CGPoint(x: contentView.frame.size.width + paddingLeft, y: contentView.frame.size.height * 0.5) let size = CGSize(width: attributes.messageTimeLabelSize.width, height: attributes.messageTimeLabelSize.height) timeLabel.frame = CGRect(origin: origin, size: size) } From 20c6044f59173be081fad1b6e0c5c7c965490de4 Mon Sep 17 00:00:00 2001 From: Bruno Guidolim Date: Mon, 31 Aug 2020 10:15:25 +0200 Subject: [PATCH 14/22] Fixes #1446 - Added LinkPreview calculator into the list of default calculators. --- Sources/Layout/MessagesCollectionViewFlowLayout.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Layout/MessagesCollectionViewFlowLayout.swift b/Sources/Layout/MessagesCollectionViewFlowLayout.swift index 559ca692..8970e8ce 100644 --- a/Sources/Layout/MessagesCollectionViewFlowLayout.swift +++ b/Sources/Layout/MessagesCollectionViewFlowLayout.swift @@ -325,7 +325,8 @@ open class MessagesCollectionViewFlowLayout: UICollectionViewFlowLayout { videoMessageSizeCalculator, locationMessageSizeCalculator, audioMessageSizeCalculator, - contactMessageSizeCalculator + contactMessageSizeCalculator, + linkPreviewMessageSizeCalculator ] } From ceb557c6b6206a22160712cfe13a44772c319e9c Mon Sep 17 00:00:00 2001 From: Bruno Guidolim Date: Mon, 31 Aug 2020 10:20:56 +0200 Subject: [PATCH 15/22] Added changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d02b4f93..aef80f1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa ## Upcoming release ### Fixed - +- Fixes missing insets for link preview messages [#1447](https://github.com/MessageKit/MessageKit/pull/1447) by [@bguidolim](https://github.com/bguidolim) ### Added From f08cdad1f47e081a73fdf502b28101795b826278 Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Wed, 2 Sep 2020 22:28:24 +0430 Subject: [PATCH 16/22] Fix some issues --- .../View Controllers/ChatViewController.swift | 15 +++++++++- .../Sources/Views/SwiftUI/MessagesView.swift | 9 ++++++ .../Controllers/MessagesViewController.swift | 6 ++-- Sources/Layout/MessageSizeCalculator.swift | 11 ++++---- Sources/Protocols/MessagesDataSource.swift | 11 ++++++++ Sources/Views/Cells/MessageContentCell.swift | 28 +++++-------------- Sources/Views/MessagesCollectionView.swift | 2 +- 7 files changed, 50 insertions(+), 32 deletions(-) diff --git a/Example/Sources/View Controllers/ChatViewController.swift b/Example/Sources/View Controllers/ChatViewController.swift index 44f0362e..f8d5ba65 100644 --- a/Example/Sources/View Controllers/ChatViewController.swift +++ b/Example/Sources/View Controllers/ChatViewController.swift @@ -113,7 +113,7 @@ class ChatViewController: MessagesViewController, MessagesDataSource { scrollsToBottomOnKeyboardBeginsEditing = true // default false maintainPositionOnKeyboardFrameChanged = true // default false - displayTimeBySwipingLeft = true // default false + showMessageTimestampOnSwipeLeft = true // default false messagesCollectionView.refreshControl = refreshControl } @@ -188,6 +188,19 @@ class ChatViewController: MessagesViewController, MessagesDataSource { let dateString = formatter.string(from: message.sentDate) return NSAttributedString(string: dateString, attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .caption2)]) } + + func messageTimestampLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { + let sentDate = message.sentDate + let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) + let timeLabelFont: UIFont = .boldSystemFont(ofSize: 10) + let timeLabelColor: UIColor + if #available(iOS 13, *) { + timeLabelColor = .systemGray + } else { + timeLabelColor = .darkGray + } + return NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) + } } // MARK: - MessageCellDelegate diff --git a/Example/Sources/Views/SwiftUI/MessagesView.swift b/Example/Sources/Views/SwiftUI/MessagesView.swift index 4247ce2f..401cfc00 100644 --- a/Example/Sources/Views/SwiftUI/MessagesView.swift +++ b/Example/Sources/Views/SwiftUI/MessagesView.swift @@ -34,6 +34,7 @@ struct MessagesView: UIViewControllerRepresentable { messagesVC.messageInputBar.delegate = context.coordinator messagesVC.scrollsToBottomOnKeyboardBeginsEditing = true // default false messagesVC.maintainPositionOnKeyboardFrameChanged = true // default false + messagesVC.showMessageTimestampOnSwipeLeft = true // default false return messagesVC } @@ -95,6 +96,14 @@ extension MessagesView.Coordinator: MessagesDataSource { let dateString = formatter.string(from: message.sentDate) return NSAttributedString(string: dateString, attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .caption2)]) } + + func messageTimestampLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { + let sentDate = message.sentDate + let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) + let timeLabelFont: UIFont = .boldSystemFont(ofSize: 10) + let timeLabelColor: UIColor = .systemGray + return NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) + } } @available(iOS 13.0, *) diff --git a/Sources/Controllers/MessagesViewController.swift b/Sources/Controllers/MessagesViewController.swift index 475c0efb..63175407 100644 --- a/Sources/Controllers/MessagesViewController.swift +++ b/Sources/Controllers/MessagesViewController.swift @@ -58,10 +58,10 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UIGestureRecogni /// Display the date of message by swiping left. /// The default value of this property is `false`. - open var displayTimeBySwipingLeft: Bool = false { + open var showMessageTimestampOnSwipeLeft: Bool = false { didSet { - messagesCollectionView.displayTimeBySwipingLeft = displayTimeBySwipingLeft - if displayTimeBySwipingLeft { + messagesCollectionView.showMessageTimestampOnSwipeLeft = showMessageTimestampOnSwipeLeft + if showMessageTimestampOnSwipeLeft { addPanGesture() } else { removePanGesture() diff --git a/Sources/Layout/MessageSizeCalculator.swift b/Sources/Layout/MessageSizeCalculator.swift index b269e23a..dad69411 100644 --- a/Sources/Layout/MessageSizeCalculator.swift +++ b/Sources/Layout/MessageSizeCalculator.swift @@ -202,12 +202,11 @@ open class MessageSizeCalculator: CellSizeCalculator { // MARK: - Message time label open func messageTimeLabelSize(for message: MessageType, at indexPath: IndexPath) -> CGSize { - let sentDate = message.sentDate - let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) - let timeLabelFont : UIFont = .boldSystemFont(ofSize: 10) - let timeLabelText = - NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont]) - let size = timeLabelText.size() + let dataSource = messagesLayout.messagesDataSource + guard let attributedText = dataSource.messageTimestampLabelAttributedText(for: message, at: indexPath) else { + return .zero + } + let size = attributedText.size() return CGSize(width: size.width, height: size.height) } diff --git a/Sources/Protocols/MessagesDataSource.swift b/Sources/Protocols/MessagesDataSource.swift index 9db208f7..4b1e3746 100644 --- a/Sources/Protocols/MessagesDataSource.swift +++ b/Sources/Protocols/MessagesDataSource.swift @@ -102,6 +102,17 @@ public protocol MessagesDataSource: AnyObject { /// /// The default value returned by this method is `nil`. func messageBottomLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? + + /// The attributed text to be used for cell's timestamp label. + /// + /// - Parameters: + /// - message: The `MessageType` that will be displayed by this cell. + /// - indexPath: The `IndexPath` of the cell. + /// - messagesCollectionView: The `MessagesCollectionView` in which this cell will be displayed. + /// + /// The default value returned by this method is `nil`. + func messageTimestampLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? + /// Custom collectionView cell for message with `custom` message type. /// diff --git a/Sources/Views/Cells/MessageContentCell.swift b/Sources/Views/Cells/MessageContentCell.swift index e3eefa80..64861335 100644 --- a/Sources/Views/Cells/MessageContentCell.swift +++ b/Sources/Views/Cells/MessageContentCell.swift @@ -70,7 +70,7 @@ open class MessageContentCell: MessageCollectionViewCell { }() /// The time label of the messageBubble. - open var timeLabel: InsetLabel = InsetLabel() + open var messageTimestampLabel: InsetLabel = InsetLabel() // Should only add customized subviews - don't change accessoryView itself. open var accessoryView: UIView = UIView() @@ -98,7 +98,7 @@ open class MessageContentCell: MessageCollectionViewCell { contentView.addSubview(cellBottomLabel) contentView.addSubview(messageContainerView) contentView.addSubview(avatarView) - contentView.addSubview(timeLabel) + contentView.addSubview(messageTimestampLabel) } open override func prepareForReuse() { @@ -107,7 +107,7 @@ open class MessageContentCell: MessageCollectionViewCell { cellBottomLabel.text = nil messageTopLabel.text = nil messageBottomLabel.text = nil - timeLabel.attributedText = nil + messageTimestampLabel.attributedText = nil } // MARK: - Configuration @@ -156,27 +156,13 @@ open class MessageContentCell: MessageCollectionViewCell { let bottomCellLabelText = dataSource.cellBottomLabelAttributedText(for: message, at: indexPath) let topMessageLabelText = dataSource.messageTopLabelAttributedText(for: message, at: indexPath) let bottomMessageLabelText = dataSource.messageBottomLabelAttributedText(for: message, at: indexPath) - - let sentDate = message.sentDate - let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) - let timeLabelFont : UIFont = .boldSystemFont(ofSize: 10) - let timeLabelColor: UIColor - if #available(iOS 13, *) { - timeLabelColor = .systemGray - } else { - timeLabelColor = .darkGray - } - let timeLabelText = - NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) - + let messageTimestampLabelText = dataSource.messageTimestampLabelAttributedText(for: message, at: indexPath) cellTopLabel.attributedText = topCellLabelText cellBottomLabel.attributedText = bottomCellLabelText messageTopLabel.attributedText = topMessageLabelText messageBottomLabel.attributedText = bottomMessageLabelText - timeLabel.attributedText = timeLabelText - - messageBottomLabel.isHidden = messagesCollectionView.displayTimeBySwipingLeft - timeLabel.isHidden = !messagesCollectionView.displayTimeBySwipingLeft + messageTimestampLabel.attributedText = messageTimestampLabelText + messageTimestampLabel.isHidden = !messagesCollectionView.showMessageTimestampOnSwipeLeft } /// Handle tap gesture on contentView and its subviews. @@ -373,6 +359,6 @@ open class MessageContentCell: MessageCollectionViewCell { let paddingLeft: CGFloat = 10 let origin = CGPoint(x: contentView.frame.size.width + paddingLeft, y: contentView.frame.size.height * 0.5) let size = CGSize(width: attributes.messageTimeLabelSize.width, height: attributes.messageTimeLabelSize.height) - timeLabel.frame = CGRect(origin: origin, size: size) + messageTimestampLabel.frame = CGRect(origin: origin, size: size) } } diff --git a/Sources/Views/MessagesCollectionView.swift b/Sources/Views/MessagesCollectionView.swift index cc8556ee..df9e3590 100644 --- a/Sources/Views/MessagesCollectionView.swift +++ b/Sources/Views/MessagesCollectionView.swift @@ -43,7 +43,7 @@ open class MessagesCollectionView: UICollectionView { /// Display the date of message by swiping left. /// The default value of this property is `false`. - open var displayTimeBySwipingLeft: Bool = false + internal var showMessageTimestampOnSwipeLeft: Bool = false private var indexPathForLastItem: IndexPath? { let lastSection = numberOfSections - 1 From d2b87770c9a83e43cfbafefe27008ed5361b8b53 Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Wed, 2 Sep 2020 22:47:11 +0430 Subject: [PATCH 17/22] Conform protocol --- .../AdvancedExampleViewController.swift | 13 +++++++++++++ .../AutocompleteExampleViewController.swift | 13 +++++++++++++ Sources/Protocols/MessagesDataSource.swift | 15 ++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Example/Sources/View Controllers/AdvancedExampleViewController.swift b/Example/Sources/View Controllers/AdvancedExampleViewController.swift index 98081c1c..33db3654 100644 --- a/Example/Sources/View Controllers/AdvancedExampleViewController.swift +++ b/Example/Sources/View Controllers/AdvancedExampleViewController.swift @@ -279,6 +279,19 @@ final class AdvancedExampleViewController: ChatViewController { return nil } + override func messageTimestampLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { + let sentDate = message.sentDate + let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) + let timeLabelFont: UIFont = .boldSystemFont(ofSize: 10) + let timeLabelColor: UIColor + if #available(iOS 13, *) { + timeLabelColor = .systemGray + } else { + timeLabelColor = .darkGray + } + return NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) + } + } // MARK: - MessagesDisplayDelegate diff --git a/Example/Sources/View Controllers/AutocompleteExampleViewController.swift b/Example/Sources/View Controllers/AutocompleteExampleViewController.swift index f50090aa..47804300 100644 --- a/Example/Sources/View Controllers/AutocompleteExampleViewController.swift +++ b/Example/Sources/View Controllers/AutocompleteExampleViewController.swift @@ -187,6 +187,19 @@ final class AutocompleteExampleViewController: ChatViewController { return nil } + override func messageTimestampLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { + let sentDate = message.sentDate + let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) + let timeLabelFont: UIFont = .boldSystemFont(ofSize: 10) + let timeLabelColor: UIColor + if #available(iOS 13, *) { + timeLabelColor = .systemGray + } else { + timeLabelColor = .darkGray + } + return NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) + } + // Async autocomplete requires the manager to reload func inputBar(_ inputBar: InputBarAccessoryView, textViewTextDidChangeTo text: String) { guard autocompleteManager.currentSession != nil, autocompleteManager.currentSession?.prefix == "#" else { return } diff --git a/Sources/Protocols/MessagesDataSource.swift b/Sources/Protocols/MessagesDataSource.swift index 4b1e3746..0139f278 100644 --- a/Sources/Protocols/MessagesDataSource.swift +++ b/Sources/Protocols/MessagesDataSource.swift @@ -159,7 +159,20 @@ public extension MessagesDataSource { func messageBottomLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { return nil } - + + func messageTimestampLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { + let sentDate = message.sentDate + let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) + let timeLabelFont: UIFont = .boldSystemFont(ofSize: 10) + let timeLabelColor: UIColor + if #available(iOS 13, *) { + timeLabelColor = .systemGray + } else { + timeLabelColor = .darkGray + } + return NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) + } + func customCell(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UICollectionViewCell { fatalError(MessageKitError.customDataUnresolvedCell) } From c6bfdba9000de7db9c72e1378697b425f999a148 Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Thu, 3 Sep 2020 12:42:20 +0430 Subject: [PATCH 18/22] Add document --- .../AdvancedExampleViewController.swift | 14 -------------- .../AutocompleteExampleViewController.swift | 13 ------------- .../View Controllers/ChatViewController.swift | 13 ------------- Sources/Protocols/MessagesDataSource.swift | 1 + 4 files changed, 1 insertion(+), 40 deletions(-) diff --git a/Example/Sources/View Controllers/AdvancedExampleViewController.swift b/Example/Sources/View Controllers/AdvancedExampleViewController.swift index 33db3654..e4fa529e 100644 --- a/Example/Sources/View Controllers/AdvancedExampleViewController.swift +++ b/Example/Sources/View Controllers/AdvancedExampleViewController.swift @@ -278,20 +278,6 @@ final class AdvancedExampleViewController: ChatViewController { } return nil } - - override func messageTimestampLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { - let sentDate = message.sentDate - let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) - let timeLabelFont: UIFont = .boldSystemFont(ofSize: 10) - let timeLabelColor: UIColor - if #available(iOS 13, *) { - timeLabelColor = .systemGray - } else { - timeLabelColor = .darkGray - } - return NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) - } - } // MARK: - MessagesDisplayDelegate diff --git a/Example/Sources/View Controllers/AutocompleteExampleViewController.swift b/Example/Sources/View Controllers/AutocompleteExampleViewController.swift index 47804300..f50090aa 100644 --- a/Example/Sources/View Controllers/AutocompleteExampleViewController.swift +++ b/Example/Sources/View Controllers/AutocompleteExampleViewController.swift @@ -187,19 +187,6 @@ final class AutocompleteExampleViewController: ChatViewController { return nil } - override func messageTimestampLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { - let sentDate = message.sentDate - let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) - let timeLabelFont: UIFont = .boldSystemFont(ofSize: 10) - let timeLabelColor: UIColor - if #available(iOS 13, *) { - timeLabelColor = .systemGray - } else { - timeLabelColor = .darkGray - } - return NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) - } - // Async autocomplete requires the manager to reload func inputBar(_ inputBar: InputBarAccessoryView, textViewTextDidChangeTo text: String) { guard autocompleteManager.currentSession != nil, autocompleteManager.currentSession?.prefix == "#" else { return } diff --git a/Example/Sources/View Controllers/ChatViewController.swift b/Example/Sources/View Controllers/ChatViewController.swift index f8d5ba65..0d98d341 100644 --- a/Example/Sources/View Controllers/ChatViewController.swift +++ b/Example/Sources/View Controllers/ChatViewController.swift @@ -188,19 +188,6 @@ class ChatViewController: MessagesViewController, MessagesDataSource { let dateString = formatter.string(from: message.sentDate) return NSAttributedString(string: dateString, attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .caption2)]) } - - func messageTimestampLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { - let sentDate = message.sentDate - let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) - let timeLabelFont: UIFont = .boldSystemFont(ofSize: 10) - let timeLabelColor: UIColor - if #available(iOS 13, *) { - timeLabelColor = .systemGray - } else { - timeLabelColor = .darkGray - } - return NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) - } } // MARK: - MessageCellDelegate diff --git a/Sources/Protocols/MessagesDataSource.swift b/Sources/Protocols/MessagesDataSource.swift index 0139f278..f81ba4fa 100644 --- a/Sources/Protocols/MessagesDataSource.swift +++ b/Sources/Protocols/MessagesDataSource.swift @@ -104,6 +104,7 @@ public protocol MessagesDataSource: AnyObject { func messageBottomLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? /// The attributed text to be used for cell's timestamp label. + /// The timestamp label is shown when showMessageTimestampOnSwipeLeft is enabled by swiping left over the chat controller. /// /// - Parameters: /// - message: The `MessageType` that will be displayed by this cell. From d4c980a03ef28a2bf14a476093b19706fa6f5a82 Mon Sep 17 00:00:00 2001 From: amir pirzad Date: Thu, 3 Sep 2020 15:32:42 +0430 Subject: [PATCH 19/22] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aef80f1f..4f50292c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa - Fixes missing insets for link preview messages [#1447](https://github.com/MessageKit/MessageKit/pull/1447) by [@bguidolim](https://github.com/bguidolim) ### Added +- show message time by swiping left over the chat controller. [#718] by @amirpirzad ### Changed From 2fc49461adf041dd576a28ca21111525cc0d2181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ka=C5=A1par?= Date: Thu, 3 Sep 2020 13:19:35 +0200 Subject: [PATCH 20/22] Update CHANGELOG.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Martin Púčik --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f50292c..d1ce5887 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa - Fixes missing insets for link preview messages [#1447](https://github.com/MessageKit/MessageKit/pull/1447) by [@bguidolim](https://github.com/bguidolim) ### Added -- show message time by swiping left over the chat controller. [#718] by @amirpirzad +- Show message time by swiping left over the chat controller. [#1444](https://github.com/MessageKit/MessageKit/pull/1444) by [@amirpirzad](https://github.com/amirpirzad) ### Changed From 81b2f6fb2426dd244201680d05ca7bf591b370a9 Mon Sep 17 00:00:00 2001 From: Jakub Kaspar Date: Fri, 4 Sep 2020 11:11:25 +0200 Subject: [PATCH 21/22] Prepare release 3.3.0 --- CHANGELOG.md | 4 +--- MessageKit.podspec | 2 +- MessageKit.xcodeproj/project.pbxproj | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1ce5887..49430705 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/MessageKit/MessageKit/releases) on GitHub. -## Upcoming release +## 3.3.0 ### Fixed - Fixes missing insets for link preview messages [#1447](https://github.com/MessageKit/MessageKit/pull/1447) by [@bguidolim](https://github.com/bguidolim) @@ -10,8 +10,6 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa ### Added - Show message time by swiping left over the chat controller. [#1444](https://github.com/MessageKit/MessageKit/pull/1444) by [@amirpirzad](https://github.com/amirpirzad) -### Changed - ## 3.2.0 ### Fixed diff --git a/MessageKit.podspec b/MessageKit.podspec index fff37452..948b1574 100644 --- a/MessageKit.podspec +++ b/MessageKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MessageKit' - s.version = '3.2.0' + s.version = '3.3.0' s.license = { :type => "MIT", :file => "LICENSE.md" } s.summary = 'An elegant messages UI library for iOS.' diff --git a/MessageKit.xcodeproj/project.pbxproj b/MessageKit.xcodeproj/project.pbxproj index 9dc6aed9..89e16370 100644 --- a/MessageKit.xcodeproj/project.pbxproj +++ b/MessageKit.xcodeproj/project.pbxproj @@ -881,7 +881,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Sources/Supporting/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)"; - MARKETING_VERSION = 3.2.0; + MARKETING_VERSION = 3.3.0; PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.MessageKit; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -907,7 +907,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Sources/Supporting/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)"; - MARKETING_VERSION = 3.2.0; + MARKETING_VERSION = 3.3.0; PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.MessageKit; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; From 0e27b921ca73e93fdff584c62063856996e7d588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ka=C5=A1par?= Date: Fri, 4 Sep 2020 11:15:27 +0200 Subject: [PATCH 22/22] Update MessagesDataSource.swift --- Sources/Protocols/MessagesDataSource.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/Protocols/MessagesDataSource.swift b/Sources/Protocols/MessagesDataSource.swift index f81ba4fa..efb0a135 100644 --- a/Sources/Protocols/MessagesDataSource.swift +++ b/Sources/Protocols/MessagesDataSource.swift @@ -113,7 +113,6 @@ public protocol MessagesDataSource: AnyObject { /// /// The default value returned by this method is `nil`. func messageTimestampLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? - /// Custom collectionView cell for message with `custom` message type. ///