Skip to content

Commit

Permalink
Merge pull request #23 from quipper/merge-upstream-3.3.0
Browse files Browse the repository at this point in the history
Merge upstream 3.3.0
  • Loading branch information
manicmaniac authored Aug 28, 2023
2 parents 9772e58 + d3de8c3 commit ebe5c71
Show file tree
Hide file tree
Showing 17 changed files with 217 additions and 21 deletions.
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

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)

### Added

### Changed
- Show message time by swiping left over the chat controller. [#1444](https://github.com/MessageKit/MessageKit/pull/1444) by [@amirpirzad](https://github.com/amirpirzad)

## 3.2.0

Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "nathantannar4/InputBarAccessoryView" ~> 4.3.0
github "nathantannar4/InputBarAccessoryView" ~> 5.1.0
35 changes: 33 additions & 2 deletions Example/ChatExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
5074EF4F2163555900D82952 /* sound1.m4a in Resources */ = {isa = PBXBuildFile; fileRef = 5074EF4D2163555900D82952 /* sound1.m4a */; };
5943ED9D23154E4D004D8B57 /* AnnouncementExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5943ED9C23154E4D004D8B57 /* AnnouncementExampleViewController.swift */; };
512CD041B78B8B72CBEFB439 /* Pods_ChatExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6596D36DCF8979FCD9D50547 /* Pods_ChatExample.framework */; };
5168957524F7AD560058C643 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5168957124F7AD560058C643 /* Assets.xcassets */; };
5168957624F7AD560058C643 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5168957224F7AD560058C643 /* LaunchScreen.storyboard */; };
63ECDABE24182A470016C349 /* MessageSubviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63ECDABD24182A470016C349 /* MessageSubviewViewController.swift */; };
63ECDAC2241889630016C349 /* MessageSubviewContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63ECDAC1241889630016C349 /* MessageSubviewContainerViewController.swift */; };
882B5E811CF7D53600B6E160 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 882B5E781CF7D53600B6E160 /* AppDelegate.swift */; };
882B5E901CF7D56000B6E160 /* ChatExampleUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 882B5E8E1CF7D56000B6E160 /* ChatExampleUITests.swift */; };
882B5E951CF7D56E00B6E160 /* ChatExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 882B5E931CF7D56E00B6E160 /* ChatExampleTests.swift */; };
9961327FB4F9B96CFD84A126 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; };
9961327FB4F9B96CFD84A126 /* (null) in Frameworks */ = {isa = PBXBuildFile; };
D4036D91BB2480E403CDC2F1 /* Pods_ChatExampleUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2AC6E3F5C11E39F57598DBE6 /* Pods_ChatExampleUITests.framework */; };
F182DD0E2148F655FC0DFF91 /* Pods_ChatExampleTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 25FCE8536D329EC8856E2BA8 /* Pods_ChatExampleTests.framework */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -105,6 +107,9 @@
5074EF4D2163555900D82952 /* sound1.m4a */ = {isa = PBXFileReference; lastKnownFileType = file; path = sound1.m4a; sourceTree = "<group>"; };
56F0AC85B38034EC92CCBC7D /* Pods_ChatExampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ChatExampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5943ED9C23154E4D004D8B57 /* AnnouncementExampleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnnouncementExampleViewController.swift; sourceTree = "<group>"; };
5168957124F7AD560058C643 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
5168957324F7AD560058C643 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
5168957424F7AD560058C643 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
59A26FF036CD2E01EB584DD4 /* Pods-ChatExampleUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ChatExampleUITests.debug.xcconfig"; path = "Target Support Files/Pods-ChatExampleUITests/Pods-ChatExampleUITests.debug.xcconfig"; sourceTree = "<group>"; };
63ECDABD24182A470016C349 /* MessageSubviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageSubviewViewController.swift; sourceTree = "<group>"; };
63ECDAC1241889630016C349 /* MessageSubviewContainerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageSubviewContainerViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -145,7 +150,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9961327FB4F9B96CFD84A126 /* BuildFile in Frameworks */,
9961327FB4F9B96CFD84A126 /* (null) in Frameworks */,
D4036D91BB2480E403CDC2F1 /* Pods_ChatExampleUITests.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -244,6 +249,16 @@
path = Sounds;
sourceTree = "<group>";
};
5168957024F7AD560058C643 /* Resources */ = {
isa = PBXGroup;
children = (
5168957124F7AD560058C643 /* Assets.xcassets */,
5168957224F7AD560058C643 /* LaunchScreen.storyboard */,
5168957424F7AD560058C643 /* Info.plist */,
);
path = Resources;
sourceTree = "<group>";
};
7077DB8E202C35C7500F8863 /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -288,6 +303,7 @@
385C2933211FF3670010B4BA /* Extensions */,
385C292E211FF3540010B4BA /* Layout */,
385C2929211FF33D0010B4BA /* Models */,
5168957024F7AD560058C643 /* Resources */,
5074EF4B2163554900D82952 /* Sounds */,
385C2949211FF3930010B4BA /* View Controllers */,
385C2924211FF3310010B4BA /* Views */,
Expand Down Expand Up @@ -437,6 +453,8 @@
buildActionMask = 2147483647;
files = (
5074EF4F2163555900D82952 /* sound1.m4a in Resources */,
5168957624F7AD560058C643 /* LaunchScreen.storyboard in Resources */,
5168957524F7AD560058C643 /* Assets.xcassets in Resources */,
5074EF4E2163555900D82952 /* sound2.m4a in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -630,6 +648,17 @@
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
5168957224F7AD560058C643 /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
5168957324F7AD560058C643 /* Base */,
);
name = LaunchScreen.storyboard;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
882B5E5B1CF7D4B900B6E160 /* Debug */ = {
isa = XCBuildConfiguration;
Expand Down Expand Up @@ -744,6 +773,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = A17AACB177F81B8A5ACA7D64 /* Pods-ChatExample.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = "$(SRCROOT)/Sources/Resources/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.ChatExample;
Expand All @@ -756,6 +786,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = ABBB75782A3594E6FECDF6CD /* Pods-ChatExample.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = "$(SRCROOT)/Sources/Resources/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.ChatExample;
Expand Down
12 changes: 6 additions & 6 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PODS:
- InputBarAccessoryView (5.0.0):
- InputBarAccessoryView/Core (= 5.0.0)
- InputBarAccessoryView/Core (5.0.0)
- InputBarAccessoryView (5.1.0):
- InputBarAccessoryView/Core (= 5.1.0)
- InputBarAccessoryView/Core (5.1.0)
- MessageKit (3.2.0):
- InputBarAccessoryView (~> 5.0.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)
Expand Down Expand Up @@ -40,8 +40,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
InputBarAccessoryView: cbc0b2d9456058e1166898897865f9f4960fac81
MessageKit: 788199a27809d677ec35f9c6e7797e9f6fa538c5
InputBarAccessoryView: 19953f486a23e846e9487099f92bbe3456e46ce5
MessageKit: ce553a92153b597540ea4688b654680542c4af6a
PINCache: 534fd41d358d828dfdf227a0d327f3673a65e20b
PINOperation: 24b774353ca248fcf87d67b2d61eef42087c125a
PINRemoteImage: e2b89e19fb6e77ffc099f9d9f3b3fe1745e3f9f9
Expand Down
4 changes: 4 additions & 0 deletions Example/Sources/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<string>MessageKit</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIcons</key>
<dict/>
<key>CFBundleIcons~ipad</key>
<dict/>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ final class AdvancedExampleViewController: ChatViewController {
}
return nil
}

}

// MARK: - MessagesDisplayDelegate
Expand Down
2 changes: 2 additions & 0 deletions Example/Sources/View Controllers/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class ChatViewController: MessagesViewController, MessagesDataSource {

scrollsToBottomOnKeyboardBeginsEditing = true // default false
maintainPositionOnKeyboardFrameChanged = true // default false

showMessageTimestampOnSwipeLeft = true // default false

messagesCollectionView.refreshControl = refreshControl
}
Expand Down
9 changes: 9 additions & 0 deletions Example/Sources/Views/SwiftUI/MessagesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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, *)
Expand Down
4 changes: 2 additions & 2 deletions MessageKit.podspec
Original file line number Diff line number Diff line change
@@ -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.'
Expand All @@ -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
4 changes: 2 additions & 2 deletions MessageKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,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;
Expand All @@ -913,7 +913,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;
Expand Down
92 changes: 91 additions & 1 deletion Sources/Controllers/MessagesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -56,6 +56,22 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
/// 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 showMessageTimestampOnSwipeLeft: Bool = false {
didSet {
messagesCollectionView.showMessageTimestampOnSwipeLeft = showMessageTimestampOnSwipeLeft
if showMessageTimestampOnSwipeLeft {
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
}
Expand Down Expand Up @@ -145,6 +161,53 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {

// MARK: - Methods [Private]

/// Display time of message by swiping the cell
private func addPanGesture() {
panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))
guard let panGesture = panGesture else {
return
}
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 {
return
}

switch gesture.state {
case .began, .changed:
messagesCollectionView.showsVerticalScrollIndicator = false
let translation = gesture.translation(in: view)
let minX = -(view.frame.size.width * 0.35)
let maxX: CGFloat = 0
var offsetValue = translation.x
offsetValue = max(offsetValue, minX)
offsetValue = min(offsetValue, maxX)
parentView.frame.origin.x = offsetValue
case .ended:
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)
default:
break
}
}

private func setupDefaults() {
extendedLayoutIncludesOpaqueBars = true
view.backgroundColor = .collectionViewBackground
Expand Down Expand Up @@ -402,4 +465,31 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
break
}
}

// MARK: - Helpers

private func addObservers() {
NotificationCenter.default.addObserver(
self, selector: #selector(clearMemoryCache), name: UIApplication.didReceiveMemoryWarningNotification, object: nil)
}

private func removeObservers() {
NotificationCenter.default.removeObserver(self, name: UIApplication.didReceiveMemoryWarningNotification, object: nil)
}

@objc private func clearMemoryCache() {
// Since quipper/MessageKit does not use image caches, the next line is commented out.
// 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)
}
}
14 changes: 13 additions & 1 deletion Sources/Layout/MessageSizeCalculator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,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)
Expand Down Expand Up @@ -208,7 +209,18 @@ 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 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)
}

// MARK: - Bottom cell Label

open func cellBottomLabelSize(for message: MessageType, at indexPath: IndexPath) -> CGSize {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Layout/MessagesCollectionViewFlowLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ open class MessagesCollectionViewFlowLayout: UICollectionViewFlowLayout {
locationMessageSizeCalculator,
audioMessageSizeCalculator,
contactMessageSizeCalculator,
announcementMessageSizeCalculator
announcementMessageSizeCalculator,
linkPreviewMessageSizeCalculator
]
}

Expand Down
Loading

0 comments on commit ebe5c71

Please sign in to comment.