Swiftpack.co - Package - MessageKit/MessageKit

A community-driven replacement for JSQMessagesViewController https://messagekit.github.io

Tests Build framework Build example app Danger

codecov Carthage compatible Swift CocoaPods Xcode MIT Contributions Welcome

Goals

  • Provide a :rotating_light:safe:rotating_light: environment for others to learn and grow through Open Source.
  • Make adding Chat:speech_balloon: to a project easy.
  • Enable beautiful and customizable Chat UI's.
  • Provide an awesome Open Source project for the iOS open source community.
  • Help others learn.

Vision

See VISION.md for Goals, Scope, & Technical Considerations.

Installation

CocoaPods Recommended

# Swift 5.3
pod 'MessageKit'

For Swift 5.0 use version 3.3.0

# Swift 5.0
pod 'MessageKit', '~> 3.3.0'

For Swift 4.2 use version 3.0.0

# Swift 4.2
pod 'MessageKit', '~> 3.0.0'

Carthage

To integrate MessageKit using Carthage, add the following to your Cartfile:

github "MessageKit/MessageKit"

Swift Package Manager

Swift 5.3 in Xcode 12 added support for assets in Swift Packages. You can just add MessageKit package to your project by entering it's repository URL

https://github.com/MessageKit/MessageKit

Older versions of Swift and XCode don't support MessageKit via SPM.

Manual

Requirements

  • iOS 12 or later
  • Swift 5.3 or later

For iOS 11 please use version 3.3.0

For iOS 9 and iOS 10 please use version 3.1.0

Getting Started

Cell Structure

Each default cell is a subclass of MessageContentCell which has 7 parts. From top down we have a: cellTopLabel, messageTopLabel, messageContainerView, messageBottomLabel, cellBottomLabel with the avatarView and accessoryView on either side respectively. Above we see the basic TextMessageCell which uses a MessageLabel as its main content.

This structure will allow you to create a layout that suits your needs as you can customize the size, appearance and padding of each. If you need something more advanced you can implement a custom cell, which we show how to do in the Example project.

MessageInputBar Structure

The MessageInputBar, derrived from InputBarAccessoryView is a flexible and robust way of creating any kind of input layout you wish. It is self-sizing which means as the user types it will grow to fill available space. It is centered around the middleContentView which by default holds the InputTextView. This is surrounded by InputStackView's that will also grow in high based on the needs of their subviews intrinsicContentSize. See the Example project for examples on how to taylor the layout for your own needs.

Guides

Please have a look at the Quick Start guide and the FAQs.

We recommend you start by looking at the Example project or write a question with the "messagekit" tag on Stack Overflow. You can also look at previous issues here on GitHub with the "Question" tag.

For more on how to use the MessageInputBar, see the dependency it is based on InputBarAccessoryView. You can also see this short guide

Default Cells

The type of cell rendered for a given message is based on the MessageKind

public enum MessageKind {
    case text(String) // TextMessageCell
    case attributedText(NSAttributedString) // TextMessageCell
    case photo(MediaItem) // MediaMessageCell
    case video(MediaItem) // MediaMessageCell
    case location(LocationItem) // LocationMessageCell
    case emoji(String) // TextMessageCell
    case audio(AudioItem) // AudioMessageCell
    case contact(ContactItem) // ContactMessageCell
    case linkPreview(LinkItem) // LinkPreviewMessageCell

    /// A custom message.
    /// - Note: Using this case requires that you implement the following methods and handle this case:
    ///   - MessagesDataSource: customCell(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UICollectionViewCell
    ///   - MessagesLayoutDelegate: customCellSizeCalculator(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CellSizeCalculator
    case custom(Any?)
}

If you choose to use the .custom kind you are responsible for all of the cells layout. Any UICollectionViewCell can be returned for custom cells which means any of the styling you provide from the MessageDisplayDelegate will not effect your custom cell. Even if you subclass your cell from MessageContentCell. Read more about custom cells

Read more about the cases on the Quick Start guide.

Contributing

Great! Look over these things first.

  • Please read our Code of Conduct
  • Check the Contributing Guide Lines.
  • Come join us on Slack and 🗣 don't be a stranger.
  • Check out the current issues and see if you can tackle any of those.
  • Download the project and check out the current code base. Suggest any improvements by opening a new issue.
  • Check out the What's Next section :point_down: to see where we are headed.
  • Check StackOverflow
  • Install SwiftLint to keep yourself in :neckbeard: style.
  • Be kind and helpful.

What's Next?

Check out the Releases to see what we are working on next.

Contact

Have a question or an issue about MessageKit? Create an issue!

Interested in contributing to MessageKit? Click here to join our Slack.

Apps using this library

Add your app to the list of apps using this library and make a pull request.

Please provide attribution, it is greatly appreciated.

Core Team

Thanks

Many thanks to the contributors of this project.

License

MessageKit is released under the MIT License.

Inspiration

Inspired by JSQMessagesViewController :point_left: :100:

Github

link
Stars: 4372

Dependencies

Used By

Total: 0

Releases

3.4.1 - 2020-09-16 20:10:45

Fix InputBarAccessoryView minimum version for SPM.

3.4.0 - 2020-09-16 19:57:43

  • Breaking Change Dropped support for iOS 11, added support for Swift 5.3 SPM and XCode 12 #1464 by @kaspik

3.3.0 - 2020-09-04 09:27:29

Fixed

Added

  • Show message time by swiping left over the chat controller. #1444 by @amirpirzad

Changed

  • Updated InputBarAccessoryView to 5.1.0

3.2.0 - 2020-08-26 20:38:58

Fixed

  • Fixes an incorrect animation of message cells while dragging to dismiss the keyboard #1433 by @lhr000lhrmega
  • Fixes an issue where the video message playback icon was too dark when in dark mode #1386 by @kinoroy
  • Fixes an issue where the video message playback button triangle was not centered within the circle #1386 by @kinoroy

Added

  • Added option to use Photo messages with remote image URL in Example project #1294 by @martinpucik
  • Breaking Change Added new linkPreview message type, which display a subclass of TextMessageCell with support to present title, teaser and a thumbnail image for a link #1310 by @bguidolim
  • Added a SwiftUI view using MessageKit in the Example Project by #1410 @kinoroy

Changed

  • Breaking Change Dropped support for iOS 9 and iOS 10 #1261 by @kaspik
  • Converted internal, static colors into color assets to better support dark and high contrast modes #1386 by @kinoroy
  • Change the video message playback button to use a UIVisualEffectsView to better match the look and feel of iMessage. #1386 by @kinoroy

3.1.0 - 2020-03-17 21:44:57

3.1.0

Fixed

3.1.0 Beta 1 - 2020-02-25 19:15:15

3.1.0 Beta 1

Fixed

  • Set the proper notification to invalidate layout. MessageKit now relies on UIApplication orientation notification instead of UIDevice, which invalidates the layout only when it is needed. #1126 by @bguidolim

  • Fixed requiredInitialScrollViewBottomInset when inputAccessoryView is nil #1218 by @aabosh

Added

  • Add missing textAlignment and textInsets assignments to layoutCellTopLabel method in MessageContentCell. #1117 by @mdescalzo

  • Add support for styling NSLinkAttribute with existing urlAttributes in MessageLabel. #1091 by @marcetcheverry

  • Add loading indicator to AudioMessageCell. #1084 by @marcetcheverry

  • Lazily initialize the MessageInputBar on MessagesViewController. #1092 by @marcetcheverry

  • Add support for Dark Mode #1189 by @Vlada31R

  • Add support for scrollToLastItem and scrollsToLastItemOnKeyboardBeginsEditing #1247 by @youuu

Changed

  • Breaking Change Updated to Swift 5.0 #1039 by @nathantannar4

  • Fixes scrollToBottom method to properly handle calls made early in the view lifecycle. #1110 by @marcetcheverry

  • Add missing cellTopLabelAlignment to MessageSizeCalculator. #1113 by @marcetcheverry

  • Breaking Change MessageInputBar, and MessageInputBarDelegate have been obsoleted. UseInputBarAccessoryView and InputBarAccessoryViewDelegate respectively. This change was previously meant for 3.0.0 but was implemented erroneously. #1201 by @kinoroy

  • Deprecated SenderType.id in favour of SenderType.senderId. This change was previously meant for 3.0.0 but was implemented erroneously. #1201 by @kinoroy

3.0.0 - 2019-05-01 00:16:24

Only Swiftlint warnings were resolved that occurred when using Carthage were resolved since the 3.0.0 BETA release.

3.0.0 Beta 1 - 2019-04-06 19:22:09

3.0.0

Dependency Changes

  • Breaking Change The dependency MessageInputBar was replaced with InputBarAccessoryView. As MessageInputBar was previously a fork this means no functionality has been lost but improvements and bug fixes will be present. InputBarAccessoryView has more of a following outside of MessageKit making its development faster than MessageInputBar. Maintaining two versions only increased the workload. You can find the changelog for InputBarAccessoryView here.

Changed

  • Breaking Change Deprecated the Sender struct in favor of the SenderType protocol. #909 by @nathantannar4

  • Breaking Change Add support for audio messages. Added new protocols AudioControllerDelegate, AudioItem a new cell AudioMessageCell and a new controller BasicAudioController. #892 by @moldovaniosif.

  • Breaking Change Moved handleTapGesture method to MessageCollectionViewCell #950 by @nathantannar4

  • Breaking Change Renamed function layoutBottomLabel(with:) to layoutMessageBottomLabel(with:) in MessageContentCell class. #920 by @maxxx777

Added

  • Breaking Change Add support for share contact. #1013 by @moldovaniosif

  • Added typing indicator support, func setTypingIndicatorViewHidden(_ isHidden: Bool, animated: Bool, whilePerforming updates: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil). Return a custom typing view by conforming to MessagesDisplayDelegate or use the default appearance. Customize the size with MessagesLayoutDelegate . #989 by @nathantannar4

  • Added AccessoryPosition class. #989 by @subdiox

  • Added incomingAccessoryViewPosition and outgoingAccessoryViewPosition variables to MessageSizeCalculator class. #989 by @subdiox

  • Added setMessageIncomingAccessoryViewPosition(_:) and setMessageOutgoingAccessoryViewPosition(_:) functions to MessagesCollectionViewFlowLayout class. #989 by @subdiox

  • Breaking Change Added avatarLeadingTrailingPadding as a property of CellSizeCalculator and MessagesCollectionViewLayoutAttributes to inset the AvatarView layout #944 by @nathantannar4

  • Breaking Change Added didTapBackground(in:) function to MessageCellDelegate protocol. #922 by @kpennacchia

  • Breaking Change Added didTapCellBottomLabel(in:) function to MessageCellDelegate protocol. #920 by @maxxx777

  • Breaking Change Added cellBottomLabelAttributedText(for:, at:) function to MessagesDataSource protocol. #920 by @maxxx777

  • Breaking Change Added cellBottomLabelHeight(for:, at:, in messagesCollectionView:) function to MessagesLayoutDelegate protocol. #920 by @maxxx777

  • Added cellBottomLabel to MessageContentCell. #920 by @maxxx777

  • Added layoutCellBottomLabel(with:) function to MessageContentCell class. #920 by @maxxx777

  • Added setMessageIncomingCellBottomLabelAlignment(_:) and setMessageOutgoingCellBottomLabelAlignment(_:) functions to MessagesCollectionViewFlowLayout class. #920 by @maxxx777

  • Added cellBottomLabelAlignment and cellBottomLabelSize variables to MessagesCollectionViewLayoutAttributes class. #920 by @maxxx777

  • Added incomingCellBottomLabelAlignment and outgoingCellBottomLabelAlignment variables to MessageSizeCalculator class. #920 by @maxxx777

  • Added cellBottomLabelSize(for:, at:) and cellBottomLabelAlignment(for:) functions to MessageSizeCalculator class. #920 by @maxxx777

2.0.0 - 2019-04-06 19:20:56

2.0.0-beta.1 - 2018-10-14 21:29:32

Changed

  • Fixed the way that the Strings and UIImages are parsed in the InputTextView to prevent crashes in parseForComponents(). #791 by @nathantannar4

  • Breaking Change Updated codebase to Swift 4.2 #883 by @nathantannar4

Added

  • Added support for detection and handling of NSLinks inside of messages. #815 by @jnic

  • Added customizable accessoryView, with a new MessagesDisplayDelegate function configureAccessoryView, and corresponding size & padding properties in MessageSizeCalculator. The accessoryView is aligned to the center of the messageContainerView. #710 by @hyouuu

  • Added a tap gesture recognition to the accessoryView which calls the MessageCellDelagate function didTapAccessoryView(in:). #834 by @nathantannar4

  • Added additionalBottomInset property that allows to adjust the bottom content inset automatically set on the messages collection view by the view controller. #787 by @andreyvit

Fixed

  • Fixed a bug that prevented MessageLabel from laying out properly when contained by superviews using autolayout. #889 by @marius-serban.

  • Breaking Change Fixed typo of scrollsToBottomOnKeybordBeginsEditing to scrollsToBottomOnKeyboardBeginsEditing. #856 by @p-petrenko

  • Fixed bottom content inset adjustment when using an undocked keyboard on iPad, or when edgesForExtendedLayout does not include .top, or when a parent container view controller adds extra views at the top of the screen. #787 by @andreyvit

  • Fixed the MessageData.emoji case to use 2x the messageLabelFont size by default. #795 by @Vortec4800.

  • Fixed MessagesCollectionView to allow to use nibs with MessageReusableView. #832 by @maxxx777.

  • Fixed multiple crashes at views, when views are being called from another XIB. #905 by @talanov.

1.0.0 - 2018-06-27 01:27:59

This is the first non-prerelease version of MessageKit. This means, while there will still be API breaking changes as the project evolves, we have a generally agreed upon core API. Thanks again to all the contributors that make this project possible 💯 🥇

Special thanks to the core team members @zhongwuzw @nathantannar4 and @cwalo. For those interested in the roadmap/feature candidates for the next major version, please check out the 2.0.0 milestone.

1.0.0-beta.2 - 2018-06-15 13:04:36

This version brings a few bug fixes thanks to all our beta testers 😎. This should be the last beta release for MessageKit. Once again thank you to all the people contributing to this project 💯 🎉

Changed

  • Relaxed the settable requirement for the LocationItem and MediaItem protocols. #727 by @SD10.

Fixed

  • Fixed MessageContentCell's subviews frame when size equal to .zero. #716 by @zhongwuzw.

  • Fixed MessagesCollectionView's bottom inset when hardware keyboard is connected. Do not adjust MessagesCollection's inset when being popped. #707 by @zhongwuzw.

  • Fixed LabelAlignment initializer which has default internal access control. #705 by @zhongwuzw.

Added

  • Added convenience method to set properties for all MessageSizeCalculators. #697 by @zhongwuzw.

1.0.0-beta.1 - 2018-05-03 20:26:22

🎉 This version brings a huge number of API breaking changes necessary for performance and the longevity of this project. This also sets a baseline for stable MessageKit API.

Below we've included a changelog and we've tried our best to fully document all API changes. If you're having trouble migrating from an earlier version of MessageKit, please open a GitHub issue and we'll do our best to point you in the right direction.

This release would not have been possible without the help of @zhongwuzw 🙇 🙇 🙇. He contributed a large number of bug fixes and performance improvements to get MessageKit to where it is today. I'd like to also thank the other core team members @nathantannar4 and @cwalo for their continued support. And of course thanks to the rest of the MessageKit contributors making this project possible 💯

Added

  • Breaking Change Added new MessagesDataSource delegate methods, numberOfSections(in) and numberOfItems(inSection:in). #601 by @SD10, @zhongwuzw.

  • Breaking Change Added new protocol MediaItem as the associated value for the MessageData.video and MessageData.photo cases. #587 by @SD10.

  • Breaking Change Added new protocol LocationItem as the associated value for the MessageData.location case. #587 by @SD10.

  • Breaking Change Added new DetectorType called .transitInformation to message label. #520 by @nosarj.

  • Breaking Change Added .custom(Any?) case to MessageData. #498 by @SD10.

  • Breaking Change Added .messageLabelTop case to AvatarPosition.Vertical enum. #596 by @zhongwuzw

  • Added CellSizeCalculator protocol that is responsible for sizing and configuring attributes of a MessageCollectionViewCell. #579 by @SD10.

  • Added MessageSizeCalculator, MediaMessageSizeCalculator, TextMessageSizeCalculator, and LocationMessageSizeCalculator classes that are responsible for sizing the MessagesCollectionViewCell types provided by MessageKit. #579 by @SD10.

  • Added three new methods cellTopLabelHeight(for:at:in), messageTopLabelHeight(for:at:in), and messageBottomLabelHeight(for:at:in) to MessagesLayoutDelegate. #580 by @SD10.

  • Added new class InsetLabel. #580 by @SD10.

  • Added new method configureMediaMessageImageView(_:for:at:in) to configure the UIImageView of a MediaMessageCell asynchronously. #592 by @zhongwuzw, @SD10

  • Added new MessageContentCell class and MessageReusableView class. #596 by @SD10.

Changed

  • Breaking Change Renamed MessageData enum to MessageKind and changed MessageType's data property name to kind. #658 by @zhongwuzw.

  • Breaking Change Changed the messageFooterView(for:in) and messageHeaderView(for:in) methods of MessagesDisplayDelegate by removing the message parameter. #615 by @SD10.

  • Breaking Change Changed the footerViewSize(for:in) and headerViewSize(for:in) methods of MessagesLayoutDelegate by removing the MessageType and IndexPath parameters and replacing them with a new section: Int parameter. #615 by @SD10.

  • Breaking Change The reuse identifiers of all MessageReusableViews and MessageCollectionViewCells have been changed to match their class name exactly. #615 by @SD10.

  • Breaking Change MessageHeaderView and MessageFooterView now subclass MessageReusableView class. #596 by @SD10.

  • Breaking Change Renamed MessageCollectionViewCell to MessageContentCell. The MessageCollectionViewCell class is now a bare bones subclass. #596 by @SD10.

  • Breaking Change Changed LabelAlignment to be a struct with properties of textAlignment: NSTextAlignment and textInsets: UIEdgeInsets to position the text in the cellTopLabel and cellBottomLabel. #580 by @SD10.

  • Breaking Change The type of cellTopLabel and cellBottomLabel has been changed to InsetLabel. #580 by @SD10.

  • Breaking Change Renamed cellTopLabel to messageTopLabel and renamed cellBottomLabel to messageBottomLabel. #659 by @SD10.

  • Breaking Change Renamed the didTapTopLabel and didTapBottomLabel methods of MessageCellDelegate to didTapMessageTopLabel and didTapMessageBottomLabel. #659 by @SD10.

  • Breaking Change Renamed cellBottomLabelAttributedText method of MessagesDataSource to messageBottomLabelAttributedText. #659 by @zhongwuzw.

  • The MessageData.emoji case no longer uses a default font of 2x the messageLabelFont size. You must now set this font explicitly through the emojiMessageSizeCalculator on MessagesCollectionViewFlowLayout. #530 by @SD10.

  • Changed the contentMode of the UIImageView for MediaMessageCell to be .scaleAspectFill. #587 by @SD10.

  • The result of the MessagesDisplayDelegate method textColor(for message:...) no longer applies to .attributedText case of MessageData. #625 by @cwalo.

  • Removed the explicit height constraint from the separatorLine in MessageInputBar. #667 by @zhongwuzw

Removed

  • Breaking Change Removed NSLayoutConstraintSet by changing access control from public to internal. #607 by @zhongwuzw.

  • Breaking Change Removed the showsDateHeaderAfterTimeInterval property of MessagesCollectionView. #615 by @SD10.

  • Breaking Change Removed the reuseIdentifer method from MessageCollectionViewCell, TextMessageCell, LocationMessageCell, MediaMessageCell, and MessageContentCell. #615 by @SD10.

  • Breaking Change Removed the CollectionViewReusable protocol. #615 by @SD10.

  • Breaking Change Removed MessageHeaderView and MessageFooterView in favor of MessageReusableView. #615 by @SD10.

  • Breaking Change Removed numberOfMessages(in) method of MessagesDataSource, instead please use numberOfSections(in) and numberOfItems(inSection:in). #601 by @SD10, @zhongwuzw.

  • Breaking Change Removed the messageLabelFont property from MessagesCollectionViewFlowLayout. You can now set this property through textMessageSizeCalculator property. #579 by @SD10.

  • Breaking Change Removed MessageDateHeaderView class in favor of using cellTopLabel. #659 by @zhongwuzw.

Fixed

0.13.5 - 2018-04-26 08:48:54

0.13.4 - 2018-04-11 19:32:07

0.13.3 - 2018-04-06 03:16:08

0.13.2 - 2018-03-27 07:27:58

0.13.1 - 2018-01-26 16:12:08

View build details and download artifacts on buddybuild: MessageKit (iOS, MessageKit - Release) ChatExample (iOS, ChatExample)

0.13.0 - 2018-01-17 06:26:04

View build details and download artifacts on buddybuild: MessageKit (iOS, MessageKit - Release) ChatExample (iOS, ChatExample)

View build details and download artifacts on buddybuild:

0.12.1 - 2018-01-07 05:05:09

View build details and download artifacts on buddybuild: MessageKit (iOS, MessageKit - Release) ChatExample (iOS, ChatExample)

0.12.0 - 2017-12-18 04:13:34

View build details and download artifacts on buddybuild: MessageKit (iOS, MessageKit - Release) ChatExample (iOS, ChatExample)

0.11.0 - 2017-12-04 23:51:14

View build details and download artifacts on buddybuild: ChatExample (iOS, ChatExample) MessageKit (iOS, MessageKit - Release)

0.10.2 - 2017-11-12 20:56:22

View build details and download artifacts on buddybuild: ChatExample (iOS, ChatExample) MessageKit (iOS, MessageKit - Release)

0.10.1 - 2017-11-02 02:10:13

View build details and download artifacts on buddybuild: MessageKit (iOS, MessageKit - Release) ChatExample (iOS, ChatExample)

0.10.0 - 2017-10-26 07:50:42

View build details and download artifacts on buddybuild: ChatExample (iOS, ChatExample) MessageKit (iOS, MessageKit - Release)

0.9.0 - 2017-10-06 03:33:01

View build details and download artifacts on buddybuild: ChatExample (iOS, ChatExample) MessageKit (iOS, MessageKit - Debug)

0.8.2 - 2017-09-24 07:11:41

View build details and download artifacts on buddybuild: MessageKit (iOS, MessageKit - Debug) ChatExample (iOS, ChatExample)

0.8.1 - 2017-09-22 08:33:52

View build details and download artifacts on buddybuild: ChatExample (iOS, ChatExample) MessageKit (iOS, MessageKit - Debug)

0.8.0 - 2017-09-22 06:36:16

View build details and download artifacts on buddybuild: ChatExample (iOS, ChatExample) MessageKit (iOS, MessageKit - Debug)

0.7.4 - 2017-09-22 04:37:06

View build details and download artifacts on buddybuild: ChatExample (iOS, ChatExample) MessageKit (iOS, MessageKit - Debug)