Skip to content

ChatInputBar

Diego Sánchez edited this page Jul 27, 2016 · 1 revision

ChatInputBar

ChatInputBar is a view that lives in ChattoAdditions. It is a generic container for different input items.

Each input item is represented by a ChatInputItemProtocol

public protocol ChatInputItemProtocol: AnyObject {
    var tabView: UIView { get }
    var inputView: UIView? { get }
    var presentationMode: ChatInputItemPresentationMode { get }
    var showsSendButton: Bool { get }
    var selected: Bool { get set }

    func handleInput(input: AnyObject)
}

To use ChatInputBar in your BaseChatViewController subclass, you must override createChatInputView and return a configured instance:

override func createChatInputView() -> UIView {
    let chatInputView = ChatInputBar.loadNib()
    var appearance = ChatInputBarAppearance()
    appearance.sendButtonAppearance.title = NSLocalizedString("Send", comment: "")
    appearance.textInputAppearance.placeholderText = NSLocalizedString("Type a message", comment: "")
    self.chatInputPresenter = BasicChatInputBarPresenter(chatInputBar: chatInputView, chatInputItems: self.createChatInputItems(), chatInputBarAppearance: appearance)
    chatInputView.maxCharactersCount = 1000
    return chatInputView
}

func createChatInputItems() -> [ChatInputItemProtocol] {
    var items = [ChatInputItemProtocol]()
    items.append(self.createTextInputItem())
    items.append(self.createPhotoInputItem())
    return items
}

private func createTextInputItem() -> TextChatInputItem {
    let item = TextChatInputItem()
    item.textInputHandler = { [weak self] text in
        // Your handling code
    }
    return item
}

private func createPhotoInputItem() -> PhotosChatInputItem {
    let item = PhotosChatInputItem(presentingController: self)
    item.photoInputHandler = { [weak self] image in
        // Your handling code
    }
    return item
}
Clone this wiki locally