Merge branch 'development' into Support_iPad_SplitView

This commit is contained in:
Ashley Ng
2020-03-25 17:29:33 -05:00
91 changed files with 183 additions and 87 deletions
+23 -9
View File
@@ -146,6 +146,16 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
13FCBEED2424D36900CB489F /* Resources */ = {
isa = PBXGroup;
children = (
882B5E7F1CF7D53600B6E160 /* Info.plist */,
882B5E791CF7D53600B6E160 /* Assets.xcassets */,
882B5E7A1CF7D53600B6E160 /* LaunchScreen.storyboard */,
);
path = Resources;
sourceTree = "<group>";
};
385C2924211FF3310010B4BA /* Views */ = {
isa = PBXGroup;
children = (
@@ -176,6 +186,7 @@
385C2933211FF3670010B4BA /* Extensions */ = {
isa = PBXGroup;
children = (
385C292A211FF3450010B4BA /* Settings+UserDefaults.swift */,
385C292F211FF3630010B4BA /* UIColor+Extensions.swift */,
385C2930211FF3630010B4BA /* UIViewController+Extensions.swift */,
);
@@ -265,17 +276,14 @@
children = (
882B5E781CF7D53600B6E160 /* AppDelegate.swift */,
50739F9421C5075D008CA369 /* AudioController */,
385C2949211FF3930010B4BA /* View Controllers */,
385C293A211FF3800010B4BA /* Data Generation */,
385C2933211FF3670010B4BA /* Extensions */,
385C292E211FF3540010B4BA /* Layout */,
385C2929211FF33D0010B4BA /* Models */,
385C2924211FF3310010B4BA /* Views */,
13FCBEED2424D36900CB489F /* Resources */,
5074EF4B2163554900D82952 /* Sounds */,
882B5E791CF7D53600B6E160 /* Assets.xcassets */,
882B5E7F1CF7D53600B6E160 /* Info.plist */,
882B5E7A1CF7D53600B6E160 /* LaunchScreen.storyboard */,
385C292A211FF3450010B4BA /* Settings+UserDefaults.swift */,
385C2933211FF3670010B4BA /* Extensions */,
385C2949211FF3930010B4BA /* View Controllers */,
385C2924211FF3310010B4BA /* Views */,
);
path = Sources;
sourceTree = "<group>";
@@ -489,11 +497,17 @@
"${PODS_ROOT}/Target Support Files/Pods-ChatExample/Pods-ChatExample-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/InputBarAccessoryView/InputBarAccessoryView.framework",
"${BUILT_PRODUCTS_DIR}/MessageKit/MessageKit.framework",
"${BUILT_PRODUCTS_DIR}/PINCache/PINCache.framework",
"${BUILT_PRODUCTS_DIR}/PINOperation/PINOperation.framework",
"${BUILT_PRODUCTS_DIR}/PINRemoteImage/PINRemoteImage.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/InputBarAccessoryView.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MessageKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PINCache.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PINOperation.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PINRemoteImage.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
@@ -722,7 +736,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist";
INFOPLIST_FILE = "$(SRCROOT)/Sources/Resources/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.ChatExample;
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -736,7 +750,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist";
INFOPLIST_FILE = "$(SRCROOT)/Sources/Resources/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.ChatExample;
PRODUCT_NAME = "$(TARGET_NAME)";
+1 -1
View File
@@ -22,4 +22,4 @@
# SOFTWARE.
source 'https://rubygems.org'
gem 'cocoapods', '~> 1.9'
gem 'cocoapods', '~> 1.9.1'
+4 -4
View File
@@ -12,10 +12,10 @@ GEM
json (>= 1.5.1)
atomos (0.1.3)
claide (1.0.3)
cocoapods (1.9.0)
cocoapods (1.9.1)
activesupport (>= 4.0.2, < 5)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.9.0)
cocoapods-core (= 1.9.1)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 1.2.2, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
@@ -31,7 +31,7 @@ GEM
nap (~> 1.0)
ruby-macho (~> 1.4)
xcodeproj (>= 1.14.0, < 2.0)
cocoapods-core (1.9.0)
cocoapods-core (1.9.1)
activesupport (>= 4.0.2, < 6)
algoliasearch (~> 1.0)
concurrent-ruby (~> 1.1)
@@ -84,7 +84,7 @@ PLATFORMS
ruby
DEPENDENCIES
cocoapods (~> 1.9)
cocoapods (~> 1.9.1)
BUNDLED WITH
2.1.4
+1
View File
@@ -6,6 +6,7 @@ target 'ChatExample' do
use_frameworks!
pod 'MessageKit', :path => '../'
pod 'SwiftLint', '~> 0.39.1'
pod 'PINRemoteImage', '~> 3.0.0', :subspecs => ['iOS', 'PINCache']
target 'ChatExampleTests' do
inherit! :search_paths
+24 -1
View File
@@ -4,15 +4,35 @@ PODS:
- InputBarAccessoryView/Core (4.3.2)
- MessageKit (3.1.0):
- InputBarAccessoryView (~> 4.3.0)
- PINCache (3.0.1-beta.8):
- PINCache/Arc-exception-safe (= 3.0.1-beta.8)
- PINCache/Core (= 3.0.1-beta.8)
- PINCache/Arc-exception-safe (3.0.1-beta.8):
- PINCache/Core
- PINCache/Core (3.0.1-beta.8):
- PINOperation (~> 1.1.1)
- PINOperation (1.1.2)
- PINRemoteImage/Core (3.0.0):
- PINOperation
- PINRemoteImage/iOS (3.0.0):
- PINRemoteImage/Core
- PINRemoteImage/PINCache (3.0.0):
- PINCache (= 3.0.1-beta.8)
- PINRemoteImage/Core
- SwiftLint (0.39.1)
DEPENDENCIES:
- MessageKit (from `../`)
- PINRemoteImage/iOS (~> 3.0.0)
- PINRemoteImage/PINCache (~> 3.0.0)
- SwiftLint (~> 0.39.1)
SPEC REPOS:
trunk:
- InputBarAccessoryView
- PINCache
- PINOperation
- PINRemoteImage
- SwiftLint
EXTERNAL SOURCES:
@@ -22,8 +42,11 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
InputBarAccessoryView: 7985d418040a05fe894bd4b8328dd43ab35517c3
MessageKit: 3c593dc22f7465f74822e4a873ef3157a3e05080
PINCache: 534fd41d358d828dfdf227a0d327f3673a65e20b
PINOperation: 24b774353ca248fcf87d67b2d61eef42087c125a
PINRemoteImage: e2b89e19fb6e77ffc099f9d9f3b3fe1745e3f9f9
SwiftLint: 55e96a4a4d537d4a3156859fc1c54bd24851a046
PODFILE CHECKSUM: 3d2d8513a2319438f3480a9f1397e1f78b0a5021
PODFILE CHECKSUM: cf0af8a506e2b58d4d51b99e165b58c56c26d619
COCOAPODS: 1.9.1
@@ -36,6 +36,7 @@ final internal class SampleData {
case Text
case AttributedText
case Photo
case PhotoFromURL = "Photo from URL"
case Video
case Audio
case Emoji
@@ -69,6 +70,11 @@ final internal class SampleData {
var now = Date()
let messageImages: [UIImage] = [#imageLiteral(resourceName: "img1"), #imageLiteral(resourceName: "img2")]
let messageImageURLs: [URL] = [URL(string: "https://placekitten.com/g/200/300")!,
URL(string: "https://placekitten.com/g/300/300")!,
URL(string: "https://placekitten.com/g/300/400")!,
URL(string: "https://placekitten.com/g/400/400")!]
let emojis = [
"👍",
"😂😂😂",
@@ -143,21 +149,16 @@ final internal class SampleData {
}
func randomMessageType() -> MessageTypes {
var messageTypes = [MessageTypes]()
for type in MessageTypes.allCases {
if UserDefaults.standard.bool(forKey: "\(type.rawValue)" + " Messages") {
messageTypes.append(type)
}
}
return messageTypes.random()!
return MessageTypes.allCases.compactMap {
guard UserDefaults.standard.bool(forKey: "\($0.rawValue)" + " Messages") else { return nil }
return $0
}.random()!
}
// swiftlint:disable cyclomatic_complexity
func randomMessage(allowedSenders: [MockUser]) -> MockMessage {
let randomNumberSender = Int(arc4random_uniform(UInt32(allowedSenders.count)))
let uniqueID = UUID().uuidString
let user = allowedSenders[randomNumberSender]
let user = allowedSenders.random()!
let date = dateAddingRandomTime()
switch randomMessageType() {
@@ -169,23 +170,21 @@ final internal class SampleData {
let attributedText = attributedString(with: randomSentence)
return MockMessage(attributedText: attributedText, user: user, messageId: uniqueID, date: date)
case .Photo:
let randomNumberImage = Int(arc4random_uniform(UInt32(messageImages.count)))
let image = messageImages[randomNumberImage]
let image = messageImages.random()!
return MockMessage(image: image, user: user, messageId: uniqueID, date: date)
case .PhotoFromURL:
let imageURL: URL = messageImageURLs.random()!
return MockMessage(imageURL: imageURL, user: user, messageId: uniqueID, date: date)
case .Video:
let randomNumberImage = Int(arc4random_uniform(UInt32(messageImages.count)))
let image = messageImages[randomNumberImage]
let image = messageImages.random()!
return MockMessage(thumbnail: image, user: user, messageId: uniqueID, date: date)
case .Audio:
let randomNumberSound = Int(arc4random_uniform(UInt32(sounds.count)))
let soundURL = sounds[randomNumberSound]
let soundURL = sounds.random()!
return MockMessage(audioURL: soundURL, user: user, messageId: uniqueID, date: date)
case .Emoji:
let randomNumberEmoji = Int(arc4random_uniform(UInt32(emojis.count)))
return MockMessage(emoji: emojis[randomNumberEmoji], user: user, messageId: uniqueID, date: date)
return MockMessage(emoji: emojis.random()!, user: user, messageId: uniqueID, date: date)
case .Location:
let randomNumberLocation = Int(arc4random_uniform(UInt32(locations.count)))
return MockMessage(location: locations[randomNumberLocation], user: user, messageId: uniqueID, date: date)
return MockMessage(location: locations.random()!, user: user, messageId: uniqueID, date: date)
case .Url:
return MockMessage(text: "https://github.com/MessageKit", user: user, messageId: uniqueID, date: date)
case .Phone:
@@ -193,8 +192,7 @@ final internal class SampleData {
case .Custom:
return MockMessage(custom: "Someone left the conversation", user: system, messageId: uniqueID, date: date)
case .ShareContact:
let randomContact = Int(arc4random_uniform(UInt32(contactsToShare.count)))
return MockMessage(contact: contactsToShare[randomContact], user: user, messageId: uniqueID, date: date)
return MockMessage(contact: contactsToShare.random()!, user: user, messageId: uniqueID, date: date)
}
}
// swiftlint:enable cyclomatic_complexity
+10
View File
@@ -52,6 +52,11 @@ private struct ImageMediaItem: MediaItem {
self.placeholderImage = UIImage()
}
init(imageURL: URL) {
self.url = imageURL
self.size = CGSize(width: 240, height: 240)
self.placeholderImage = UIImage(imageLiteralResourceName: "image_message_placeholder")
}
}
private struct MockAudiotem: AudioItem {
@@ -121,6 +126,11 @@ internal struct MockMessage: MessageType {
self.init(kind: .photo(mediaItem), user: user, messageId: messageId, date: date)
}
init(imageURL: URL, user: MockUser, messageId: String, date: Date) {
let mediaItem = ImageMediaItem(imageURL: imageURL)
self.init(kind: .photo(mediaItem), user: user, messageId: messageId, date: date)
}
init(thumbnail: UIImage, user: MockUser, messageId: String, date: Date) {
let mediaItem = ImageMediaItem(image: thumbnail)
self.init(kind: .video(mediaItem), user: user, messageId: messageId, date: date)
+3 -5
View File
@@ -76,12 +76,10 @@ final class MockSocket {
onNewMessageCode?(message)
queuedMessage = nil
} else {
let sender = arc4random_uniform(1) % 2 == 0 ? connectedUsers.first! : connectedUsers.last!
SampleData.shared.getMessages(count: 1, allowedSenders: [sender]) { (message) in
queuedMessage = message.first
}
let sender = connectedUsers.random()!
let message = SampleData.shared.randomMessage(allowedSenders: [sender])
queuedMessage = message
onTypingStatusCode?()
}
}
}

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Before

Width:  |  Height:  |  Size: 177 KiB

After

Width:  |  Height:  |  Size: 177 KiB

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before

Width:  |  Height:  |  Size: 523 B

After

Width:  |  Height:  |  Size: 523 B

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before

Width:  |  Height:  |  Size: 402 B

After

Width:  |  Height:  |  Size: 402 B

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before

Width:  |  Height:  |  Size: 729 B

After

Width:  |  Height:  |  Size: 729 B

Before

Width:  |  Height:  |  Size: 969 B

After

Width:  |  Height:  |  Size: 969 B

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before

Width:  |  Height:  |  Size: 661 B

After

Width:  |  Height:  |  Size: 661 B

@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "image_message_placeholder.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Before

Width:  |  Height:  |  Size: 136 KiB

After

Width:  |  Height:  |  Size: 136 KiB

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

@@ -26,6 +26,7 @@ import UIKit
import MapKit
import MessageKit
import InputBarAccessoryView
import PINRemoteImage
final class AdvancedExampleViewController: ChatViewController {
@@ -353,6 +354,14 @@ extension AdvancedExampleViewController: MessagesDisplayDelegate {
accessoryView.layer.cornerRadius = accessoryView.frame.height / 2
accessoryView.backgroundColor = UIColor.primaryColor.withAlphaComponent(0.3)
}
func configureMediaMessageImageView(_ imageView: UIImageView, for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) {
if case MessageKind.photo(let media) = message.kind, let imageURL = media.url {
imageView.pin_setImage(from: imageURL)
} else {
imageView.pin_cancelImageDownload()
}
}
// MARK: - Location Messages
@@ -9,6 +9,7 @@
import UIKit
import MessageKit
import InputBarAccessoryView
import PINRemoteImage
final class AutocompleteExampleViewController: ChatViewController {
@@ -336,6 +337,14 @@ extension AutocompleteExampleViewController: MessagesDisplayDelegate {
accessoryView.layer.cornerRadius = accessoryView.frame.height / 2
accessoryView.backgroundColor = UIColor.primaryColor.withAlphaComponent(0.3)
}
func configureMediaMessageImageView(_ imageView: UIImageView, for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) {
if case MessageKind.photo(let media) = message.kind, let imageURL = media.url {
imageView.pin_setImage(from: imageURL)
} else {
imageView.pin_cancelImageDownload()
}
}
}
// MARK: - MessagesLayoutDelegate
@@ -25,6 +25,7 @@
import UIKit
import MapKit
import MessageKit
import PINRemoteImage
class BasicExampleViewController: ChatViewController {
override func configureMessageCollectionView() {
@@ -71,6 +72,14 @@ extension BasicExampleViewController: MessagesDisplayDelegate {
let avatar = SampleData.shared.getAvatarFor(sender: message.sender)
avatarView.set(avatar: avatar)
}
func configureMediaMessageImageView(_ imageView: UIImageView, for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) {
if case MessageKind.photo(let media) = message.kind, let imageURL = media.url {
imageView.pin_setImage(from: imageURL)
} else {
imageView.pin_cancelImageDownload()
}
}
// MARK: - Location Messages
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2017-2019 MessageKit
Copyright (c) 2017-2020 MessageKit
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -28,24 +28,30 @@ import InputBarAccessoryView
/// A base class for the example controllers
class ChatViewController: MessagesViewController, MessagesDataSource {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
/// The `BasicAudioController` controll the AVAudioPlayer state (play, pause, stop) and udpate audio cell UI accordingly.
open lazy var audioController = BasicAudioController(messageCollectionView: messagesCollectionView)
var messageList: [MockMessage] = []
// MARK: - Public properties
/// The `BasicAudioController` controll the AVAudioPlayer state (play, pause, stop) and udpate audio cell UI accordingly.
lazy var audioController = BasicAudioController(messageCollectionView: messagesCollectionView)
lazy var messageList: [MockMessage] = []
let refreshControl = UIRefreshControl()
let formatter: DateFormatter = {
private(set) lazy var refreshControl: UIRefreshControl = {
let control = UIRefreshControl()
control.addTarget(self, action: #selector(loadMoreMessages), for: .valueChanged)
return control
}()
// MARK: - Private properties
private let formatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .medium
return formatter
}()
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
@@ -69,6 +75,10 @@ class ChatViewController: MessagesViewController, MessagesDataSource {
MockSocket.shared.disconnect()
audioController.stopAnyOngoingPlaying()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
func loadFirstMessages() {
DispatchQueue.global(qos: .userInitiated).async {
@@ -83,8 +93,7 @@ class ChatViewController: MessagesViewController, MessagesDataSource {
}
}
@objc
func loadMoreMessages() {
@objc func loadMoreMessages() {
DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + 1) {
SampleData.shared.getMessages(count: 20) { messages in
DispatchQueue.main.async {
@@ -104,8 +113,7 @@ class ChatViewController: MessagesViewController, MessagesDataSource {
scrollsToBottomOnKeyboardBeginsEditing = true // default false
maintainPositionOnKeyboardFrameChanged = true // default false
messagesCollectionView.addSubview(refreshControl)
refreshControl.addTarget(self, action: #selector(loadMoreMessages), for: .valueChanged)
messagesCollectionView.refreshControl = refreshControl
}
func configureMessageInputBar() {
@@ -143,50 +151,46 @@ class ChatViewController: MessagesViewController, MessagesDataSource {
return messagesCollectionView.indexPathsForVisibleItems.contains(lastIndexPath)
}
// MARK: - MessagesDataSource
func currentSender() -> SenderType {
return SampleData.shared.currentSender
}
func numberOfSections(in messagesCollectionView: MessagesCollectionView) -> Int {
return messageList.count
}
func messageForItem(at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> MessageType {
return messageList[indexPath.section]
}
func cellTopLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? {
if indexPath.section % 3 == 0 {
return NSAttributedString(string: MessageKitDateFormatter.shared.string(from: message.sentDate), attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 10), NSAttributedString.Key.foregroundColor: UIColor.darkGray])
}
return nil
}
func cellBottomLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? {
return NSAttributedString(string: "Read", attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 10), NSAttributedString.Key.foregroundColor: UIColor.darkGray])
}
func messageTopLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? {
let name = message.sender.displayName
return NSAttributedString(string: name, attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .caption1)])
}
func messageBottomLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? {
let dateString = formatter.string(from: message.sentDate)
return NSAttributedString(string: dateString, attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .caption2)])
}
}
// MARK: - MessageCellDelegate
extension ChatViewController: MessageCellDelegate {
func didTapAvatar(in cell: MessageCollectionViewCell) {
print("Avatar tapped")
}
@@ -261,7 +265,6 @@ extension ChatViewController: MessageCellDelegate {
// MARK: - MessageLabelDelegate
extension ChatViewController: MessageLabelDelegate {
func didSelectAddress(_ addressComponents: [String: String]) {
print("Address Selected: \(addressComponents)")
}
@@ -293,7 +296,6 @@ extension ChatViewController: MessageLabelDelegate {
func didSelectCustom(_ pattern: String, match: String?) {
print("Custom data detector patter selected: \(pattern)")
}
}
// MARK: - MessageInputBarDelegate
@@ -33,7 +33,7 @@ final internal class SettingsViewController: UITableViewController {
return .lightContent
}
let cells = ["Mock messages count", "Text Messages", "AttributedText Messages", "Photo Messages", "Video Messages", "Audio Messages", "Emoji Messages", "Location Messages", "Url Messages", "Phone Messages", "ShareContact Messages"]
let cells = ["Mock messages count", "Text Messages", "AttributedText Messages", "Photo Messages", "Photo from URL Messages", "Video Messages", "Audio Messages", "Emoji Messages", "Location Messages", "Url Messages", "Phone Messages", "ShareContact Messages"]
// MARK: - Picker