Skip to content

Crash when show typing indicator #1387

@shahchirag2110

Description

@shahchirag2110

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions