//
// RCChatMessageCell.swift
// Runner
//
// Created by chenrui on 2024/6/13.
//
import Foundation
import SwiftUI
class RCBaseMessageCell: UITableViewCell {
fileprivate func createSwiftUIContent(_ parentViewModel: RCConversationViewModel,_ viewModel: RCMessageViewModel) {
self.selectionStyle = .none
let customCotentView = MessageFactory.createMessage(type: viewModel.message.type, viewModel: viewModel)
let hostingController = UIHostingController(rootView: customCotentView)
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
self.hostingController = hostingController
self.contentView.addSubview(hostingController.view)
NSLayoutConstraint.activate([
hostingController.view.leadingAnchor.constraint(equalTo: self.contentView.leadingAnchor),
hostingController.view.trailingAnchor.constraint(equalTo: self.contentView.trailingAnchor),
hostingController.view.topAnchor.constraint(equalTo: self.contentView.topAnchor),
hostingController.view.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor),
])
}
func update(parentViewModel: RCConversationViewModel, message: ChatMessage_ChatMessage, index: Int) {
self.parentViewModel = parentViewModel
let viewModel = RCMessageViewModel(message: message,parentViewModel: parentViewModel)
viewModel.index = index
createSwiftUIContent(parentViewModel, viewModel)
self.hostingController?.view.backgroundColor = UIColor.clear
self.contentView.backgroundColor = UIColor.clear
self.backgroundColor = UIColor.clear
}
}
When I touch the text, sometimes it doesn’t print 123
. It seems like it doesn’t receive the touch gesture. Does anybody know how I can solve this issue? Or another way to avoid this bug.
This bug only happens in iOS 18.1
and iOS 17
. But iOS 16
works fine.
5