-
Notifications
You must be signed in to change notification settings - Fork 593
Tutorial_Setup_BaseChatViewController
Diego Sánchez edited this page Jul 27, 2016
·
4 revisions
import Chatto
import ChattoAdditions
class ChatViewController: BaseChatViewController {
}
var chatInputPresenter: BasicChatInputBarPresenter!
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 logic
}
return item
}
private func createPhotoInputItem() -> PhotosChatInputItem {
let item = PhotosChatInputItem(presentingController: self)
item.photoInputHandler = { [weak self] image in
// Your handling logic
}
return item
}
Learn more about ChatInputBar
override func createPresenterBuilders() -> [ChatItemType: [ChatItemPresenterBuilderProtocol]] {
let textMessagePresenter = TextMessagePresenterBuilder(
viewModelBuilder: DemoTextMessageViewModelBuilder(),
interactionHandler: DemoTextMessageHandler(baseHandler: self.baseMessageHandler)
)
textMessagePresenter.baseMessageStyle = BaseMessageCollectionViewCellAvatarStyle()
let photoMessagePresenter = PhotoMessagePresenterBuilder(
viewModelBuilder: DemoPhotoMessageViewModelBuilder(),
interactionHandler: DemoPhotoMessageHandler(baseHandler: self.baseMessageHandler)
)
photoMessagePresenter.baseCellStyle = BaseMessageCollectionViewCellAvatarStyle()
return [
"text-message-type": [textMessagePresenter],
"photo-message-type": [photoMessagePresenter],
]
}
Lear more about Presenters
override func viewDidLoad() {
super.viewDidLoad()
self.chatDataSource = YourDataSource()
}
Lear more about Data source