119 lines
3.3 KiB
Swift
119 lines
3.3 KiB
Swift
//
|
|
// ChatTextCell.swift
|
|
// yinmeng-ios
|
|
//
|
|
// Created by MaiMang on 2024/2/27.
|
|
//
|
|
|
|
import UIKit
|
|
import SnapKit
|
|
class ChatTextCell: ChatBaseCell {
|
|
|
|
private lazy var textLb: UILabel = {
|
|
let label = UILabel()
|
|
label.translatesAutoresizingMaskIntoConstraints = false
|
|
label.isEnabled = false
|
|
label.numberOfLines = 0
|
|
return label
|
|
}()
|
|
|
|
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
initSubview()
|
|
}
|
|
|
|
func initSubview() {
|
|
bubbleView.addSubview(textLb)
|
|
|
|
avatarImgView.snp.makeConstraints { (make) in
|
|
make.size.equalTo(ChatUIConfig.layout.avatarSize)
|
|
make.left.equalToSuperview().offset(10)
|
|
make.top.equalTo(contentView).offset(10)
|
|
}
|
|
|
|
bubbleView.snp.makeConstraints { (make) in
|
|
make.top.equalTo(contentView.snp.top).offset(2)
|
|
make.bottom.equalTo(textLb.snp.bottom).offset(2)
|
|
make.left.equalTo(avatarImgView.snp.right)
|
|
make.width.equalTo(ChatUIConfig.layout.contentMaxWidth)
|
|
make.height.equalTo(textLb).offset(26)
|
|
}
|
|
|
|
textLb.snp.makeConstraints { (make) in
|
|
make.top.equalTo(bubbleView).offset(ChatUIConfig.layout.textInsets.top);
|
|
make.left.equalTo(bubbleView).offset(ChatUIConfig.layout.textInsets.left);
|
|
make.right.equalTo(bubbleView).offset(-ChatUIConfig.layout.textInsets.right);
|
|
}
|
|
|
|
activityIndicatorView.snp.makeConstraints { (make) in
|
|
make.centerY.equalTo(bubbleView)
|
|
make.centerX.equalToSuperview()
|
|
make.width.height.equalTo(30)
|
|
}
|
|
bubbleView.setContentHuggingPriority(.required, for: .horizontal)
|
|
}
|
|
|
|
override func layoutMessageCell() {
|
|
super.layoutMessageCell()
|
|
if let textModel = model as? ChatTextObject {
|
|
self.textLb.attributedText = textModel.attribute
|
|
setupCellLayout()
|
|
}
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|
|
|
|
|
|
extension ChatTextCell {
|
|
|
|
func setupCellLayout() {
|
|
guard let model = model else {return}
|
|
if model.msg?.isOutgoingMsg == true { //我发送的
|
|
avatarImgView.snp.remakeConstraints { (make) in
|
|
make.size.equalTo(ChatUIConfig.layout.avatarSize)
|
|
make.right.equalToSuperview().offset(-10)
|
|
make.top.equalToSuperview().offset(ChatUIConfig.layout.cellContentInsets.top)
|
|
}
|
|
|
|
bubbleView.snp.remakeConstraints { make in
|
|
make.size.equalTo(model.contentSize)
|
|
make.top.equalTo(avatarImgView)
|
|
make.right.equalTo(avatarImgView.snp.left).offset(-10)
|
|
}
|
|
activityIndicatorView.snp.remakeConstraints { (make) in
|
|
make.centerY.equalTo(bubbleView)
|
|
make.right.equalTo(bubbleView.snp.left)
|
|
make.width.height.equalTo(30)
|
|
}
|
|
|
|
textLb.snp.remakeConstraints { make in
|
|
make.edges.equalToSuperview().inset(ChatUIConfig.layout.textInsets)
|
|
}
|
|
|
|
// start
|
|
activityStartAnimating()
|
|
|
|
}else {
|
|
avatarImgView.snp.remakeConstraints { (make) in
|
|
make.size.equalTo(ChatUIConfig.layout.avatarSize)
|
|
make.left.equalToSuperview().offset(10)
|
|
make.top.equalToSuperview().offset(ChatUIConfig.layout.cellContentInsets.top)
|
|
}
|
|
|
|
bubbleView.snp.remakeConstraints { make in
|
|
make.size.equalTo(model.contentSize)
|
|
make.top.equalTo(avatarImgView)
|
|
make.left.equalTo(avatarImgView.snp.right).offset(10)
|
|
}
|
|
|
|
textLb.snp.remakeConstraints { make in
|
|
make.edges.equalToSuperview().inset(ChatUIConfig.layout.textInsets)
|
|
}
|
|
}
|
|
}
|
|
}
|