修改了登录im的逻辑

This commit is contained in:
fengshuo
2024-02-29 23:49:12 +08:00
parent 70e6ca8204
commit 26d586290c
26 changed files with 1536 additions and 55 deletions

View File

@@ -9,25 +9,39 @@ import UIKit
import NIMSDK
class ChatVC: BaseViewController {
// /
private var isBecome: Bool = false
///
private var isSended: Bool = true
///
private let ToolBarLastH: CGFloat = 52
public init(session: NIMSession) {
vm = ChatViewModel(session: session)
super.init(nibName: nil, bundle: nil)
// vm.delegate = self
// NIMSDK.shared().mediaManager.add(self)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
var vm:ChatViewModel
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .orange
}
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = ThemeColor(hexStr: "#F6F6F6")
let height = ScreenHeight - (ToolBarLastH + SafeAraeBottomHeight + NavHeight)
chatTableView.frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: height)
view.addSubview(chatTableView)
view.addSubview(keyboardView)
}
///cell
private func registerChatCell() {
chatTableView.register(cellType: ChatTextCell.self)
}
private lazy var chatTableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
@@ -42,20 +56,57 @@ class ChatVC: BaseViewController {
return tableView
}()
private lazy var keyboardView: ChatKeyboardView = {
let toolBarY = ScreenHeight - NavHeight - ToolBarLastH - SafeAraeBottomHeight
let view = ChatKeyboardView(frame: CGRect(x: 0, y: toolBarY, width: ScreenWidth, height: ToolBarLastH))
view.delegate = self
return view
}()
}
extension ChatVC: UITableViewDelegate, UITableViewDataSource {
// MARK: - ChatKeyboardViewDelegate
extension ChatVC: ChatKeyboardViewDelegate {
func keyboard(_ keyboard: ChatKeyboardView, DidFinish content: String) {
///
vm.sendTextMessage(text: content) { error in
}
}
func keyboard(_ keyboard: ChatKeyboardView, DidBecome isBecome: Bool) {
self.isSended = true
self.isBecome = isBecome
}
func keyboard(_ keyboard: ChatKeyboardView, DidMoreMenu type: ChatMoreMenuType) {
//TODO:
}
func keyboard(_ keyboard: ChatKeyboardView, DidObserver offsetY: CGFloat) {
}
}
extension ChatVC: UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate {
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return vm.messageObjects.count
}
public func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let model = vm.messageObjects[safe: indexPath.row]
if model?.type == .text {
let cell = tableView.dequeueReusableCell(for: indexPath, cellType: ChatTextCell.self)
cell.model = model
}
return UITableViewCell()
}
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
public func tableView(_ tableView: UITableView,
@@ -63,4 +114,22 @@ extension ChatVC: UITableViewDelegate, UITableViewDataSource {
let m = vm.messageObjects[safe:indexPath.row]
return CGFloat(m?.height ?? 0)
}
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
if isSended {
isSended = false
}
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if isSended {
return
}
if chatTableView.y <= 0 && isBecome {
DispatchQueue.main.async {
NotificationCenter.default.post(name: .kChatTextKeyboardNeedHide, object: nil)
}
}
}
}