Repository navigation
Crash when show typing indicator #1387
Copy link
Copy link
Closed
Labels
Description
Describe the bug
Typing indicator work perfectly till i did not add custom cell. After adding custom cell typing indicator force crashes when setTypingIndicatorViewHidden method called
To Reproduce
Steps/code to reproduce the behavior:
Add custom cell and then it will crash the application
private func showTypingIndicator() {
firebaseManager.observerOnUpdateOnValue(in: TagRootDirectory.Chat, withPath: "\(self.objID.actualID)/\(TagSubDirectoryChat.Detail.rawValue)") { [weak self] (objAny) in
guard let weakSelf = self else {
return
}
if weakSelf.isFirstLoad == false {
if let dictData = objAny as? NSDictionary,let typingStatus = dictData["typing"] as? String {
if typingStatus == "1" {
weakSelf.setTypingIndicatorViewHidden(false, animated: true, whilePerforming: {
}) { (isCompleted) in
if weakSelf.isLastSectionVisible() == false{
weakSelf.messagesCollectionView.scrollToBottom()
}
}
} else {
weakSelf.setTypingIndicatorViewHidden(false, animated: true, whilePerforming: {
}) { (isCompleted) in
if weakSelf.isLastSectionVisible() == false{
weakSelf.messagesCollectionView.scrollToBottom()
}
}
}
}
}
}
}
func numberOfSections(in messagesCollectionView: MessagesCollectionView) -> Int {
return messageList.count
}
func numberOfItems(inSection section: Int, in messagesCollectionView: MessagesCollectionView) -> Int {
return messageList[section].arrChat.count
}
func messageForItem(at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> MessageType {
return messageList[indexPath.section].arrChat[indexPath.row] //Crash here
}
func cellTopLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? {
let objMessageData = messageList[indexPath.section]
return NSAttributedString(string: objMessageData.strDate ?? "", attributes: [NSAttributedString.Key.font: UIFont.avenirThin(WithSize: 15), NSAttributedString.Key.foregroundColor: #colorLiteral(red: 0.5411764706, green: 0.5411764706, blue: 0.5607843137, alpha: 1)])
}
func messageBottomLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? {
if isFromCurrentSender(message: message) {
let objMessageData = messageList[indexPath.section].arrChat[indexPath.row]
if objMessageData.msgStatus == TagMsgStatus.read
{
let strStatus = objMessageData.msgStatus.rawValue + " " + (objMessageData.readTime ?? "")
return NSAttributedString(string: strStatus, attributes: [NSAttributedString.Key.font: UIFont.avenirMedium(WithSize: 11.0,shouldResize: true),NSAttributedString.Key.foregroundColor : #colorLiteral(red: 0.5215686275, green: 0.5568627451, blue: 0.6, alpha: 1)])
}
return NSAttributedString(string: objMessageData.msgStatus.rawValue, attributes: [NSAttributedString.Key.font: UIFont.avenirMedium(WithSize: 11.0,shouldResize: true),NSAttributedString.Key.foregroundColor : #colorLiteral(red: 0.5215686275, green: 0.5568627451, blue: 0.6, alpha: 1)])
}
return nil
}Expected behavior
Application will not crash and it will show the typing indicator
Screenshots
Video
https://drive.google.com/file/d/18HkVKD6P3VSSi8uwlySGokGRMMfHWler/view?usp=sharing
Environment
- Version of MessageKit : 3.1.0
- Version of iOS : iOS 12
- Version of Swift : swift 5
- What device(s) are you testing on? : simulators , iPhone 5se
Reactions are currently unavailable
Activity
kinoroy commentedon Jun 25, 2020
Hi @shahchirag2110
You point to the crash at a point where there could be an out of bounds array access. Could you share a stack trace of the crash or the error message you receive? The example app in the
AdvancedExampleViewControlleruses a custom cell and the typing indicator together without issue, so it shouldn't be that alone.shahchirag2110 commentedon Jun 26, 2020
@kinoroy
Yes i totally agree with you that in AdvancedExampleViewController it totally working fine. and i take the code from their also but my issue is that i have section header so i return number of row in section where in demo you create section for particular section so my question is does this create any issue?
shahchirag2110 commentedon Jun 26, 2020
Finally i solved the crash it is happening because one section and row was reserved for typing indicator which is make the index out of bound so I add one more dummy model in
messageForItem(at indexPath , in messagesCollectionView)method when typing indicator was shown.Document the typing indicator section contract
Rename numberOfSections to numberOfMessageSections