Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
172 lines (126 sloc) 4.12 KB



ChatViewController is meant to be subclassed, like you would normally do with UITableViewController. This pattern is a convenient way of extending UIViewController. ChatViewController manages a lot behind the scenes while still providing the ability to add custom behaviours. You may override methods, and decide to call super and perform additional logic, or not to call super and override default logic.

Start by creating a new subclass of ChatViewController.

Override delegate function of UITableView

override func numberOfSections(in tableView: UITableView) -> Int {


override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {


override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

Override function didPressSendButton

override func didPressSendButton(_ sender: Any?) {
    // Create message
    let message = Message(id: UUID().uuidString, text: chatBarView.textView.text)
    // Add message
    // Call super to update UI for Chat Bar

Handle ImagePickerView call back

/// Image Picker Result closure
imagePickerView?.pickImageResult = { image, url, error in
    if error != nil {

    guard let _ = image, let _ = url else {

    print("Pick image successfully")

Image Picker

Currently, we support two style for ImagePicker. First one is Slack style and second one is action sheet style

Slack style

One or two rows depend on device and user turn on/off predictive mode for keyboard. To understand more clearly about how we implement it, see the Image Picker

Action Sheet style

Action Sheet is the simplest way to pick an image.

To use default ImagePickerHelper to show Action Sheet style. Declare imagePickerHelper in YourViewController

open lazy var imagePickerHelper: ImagePickerHelper = {
    let imagePickerHelper = ImagePickerHelper()
    imagePickerHelper.delegate = self
    imagePickerHelper.parentViewController = self
    return imagePickerHelper

Make YourViewController adopts ImagePickerHelperResultDelegate

extension YourViewController: ImagePickerHelperResultDelegate {
    public func didFinishPickingMediaWithInfo(_ image: UIImage?, _ imagePath: URL?, _ error: Error?) {

Override didPressGalleryButton function

override func didPressGalleryButton(_ sender: Any?) {
    /// Dismiss keyboard if keyboard is showing
    if currentKeyboardType == .default {

Typing Indicator

Create subclass User adopts Userable protocol

struct User: Userable, Mappable {

    var id: Int!
    var name: String = ""

    var idNumber: String {
        get {
            return id.description

    var displayName: String {
        get {
            return name

    init(id: Int, name: String) { = id = name

Add an user who is typing

user = User(id: 1, name: "Harry")

Remove an user who is typing

user = User(id: 1, name: "Harry")

Chat Bar Visible

Show Chat Bar

setChatBarHidden(false, animated: true)

Hide Chat Bar

setChatBarHidden(true, animated: true)

Pull To Refresh And Load More

Add load more function

// Add function load more for table view
tableView.addLoadMore { in


Add pull to refresh function

// Add function refresh for table view
tableView.addFooterRefresh { in

You can’t perform that action at this time.