聊天页(消息流/输入/历史/已读/撤回)(ChatViewController)

聊天页(消息流/输入/历史/已读/撤回):ChatViewController 属于 ViewController(视图 / 生命周期 / 输入)。本页的 props / events / behaviors 来自 sdk-imkit.json → globalUIKit,声明与示例来自 bindings.ios.uikit,不手写漂移。

契约属性(props)​

属性类型可选说明
viewModelChatViewModel否页面状态机(ChatListViewModel / ChatViewModel)
themeChatUITheme否主题令牌(ChatUITheme),浅色 / 深色预设或自定义
delegateChatDelegate?是交互回调协议实现;只回调,不做导航
options{showHistory:bool,showReadReceipt:bool,showTyping:bool}是页面选项(由契约声明的可选字段,例如搜索栏 / 网络横幅 / 历史 / 已读 / typing)

事件(events)​

事件参数说明
sendtext发送文本
tapMessagemessage点击消息(图片 / 文件 / 位置等)
tapAvataruserId点击头像
requestMore—上拉加载更多历史
readDetailmessage查看已读明细

行为(behaviors)​

  • 消息按 seq 渲染、去重、发送中/失败/已读状态
  • 上拉加载历史(beforeSeq 分页)
  • 进入会话自动已读(可关闭)
  • typing 指示与节流
  • 键盘避让与滚动定位
  • 撤回/已读明细回调由宿主展示

公开符号与声明​

语言声明
SwiftIMPChatViewController(viewModel: IMPChatViewModel, theme: IMPChatUITheme, delegate: IMPChatDelegate?, options: IMPChatViewOptions?)
Objective-C- (instancetype)initWithViewModel:(IMPOSGlobalChatViewModel *)viewModel theme:(IMPOSGlobalChatUITheme *)theme delegate:(id<IMPOSGlobalChatDelegate>)delegate options:(IMPOSGlobalChatViewOptions *)options;

使用示例(Swift / Objective-C)​

IMPChatViewController(viewModel: chatViewModel, theme: .light, delegate: nil, options: nil)
IMPOSGlobalChatViewController *chatViewController =
    [[IMPOSGlobalChatViewController alloc] initWithViewModel:self.viewModel theme:[IMPOSGlobalChatUITheme globalLight] delegate:nil options:nil];
示例口径

示例由绑定签名与契约类型生成:构造函数参数、协议方法、属性名均来自契约;实际业务中把示例变量替换为宿主实例即可。

在架构中的位置​

项值
层ViewController(视图 / 生命周期 / 输入)
依赖GlobalUIKit -> IMKit -> IMLib(公开接口)
相关组件ChatViewModel、ChatDelegate、ChatInputController、ChatUITheme、ChatRouter

错误处理​

ViewModel 层通过事件上报错误(如 error(err));错误码与处理建议见 Global IM UIKit 错误处理、状态码(运行时 43 条)与 状态码全量对照(440 条)。

相关文档​